class EntityReferenceTest in Feeds 8.3
Same name in this branch
- 8.3 tests/src/Unit/Feeds/Target/EntityReferenceTest.php \Drupal\Tests\feeds\Unit\Feeds\Target\EntityReferenceTest
- 8.3 tests/src/Kernel/Feeds/Target/EntityReferenceTest.php \Drupal\Tests\feeds\Kernel\Feeds\Target\EntityReferenceTest
@coversDefaultClass \Drupal\feeds\Feeds\Target\EntityReference @group feeds
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\feeds\Unit\FeedsUnitTestCase uses FeedsMockingTrait, FeedsReflectionTrait
- class \Drupal\Tests\feeds\Unit\Feeds\Target\FieldTargetTestBase
- class \Drupal\Tests\feeds\Unit\Feeds\Target\EntityReferenceTestBase
- class \Drupal\Tests\feeds\Unit\Feeds\Target\EntityReferenceTest
- class \Drupal\Tests\feeds\Unit\Feeds\Target\EntityReferenceTestBase
- class \Drupal\Tests\feeds\Unit\Feeds\Target\FieldTargetTestBase
- class \Drupal\Tests\feeds\Unit\FeedsUnitTestCase uses FeedsMockingTrait, FeedsReflectionTrait
Expanded class hierarchy of EntityReferenceTest
File
- tests/
src/ Unit/ Feeds/ Target/ EntityReferenceTest.php, line 18
Namespace
Drupal\Tests\feeds\Unit\Feeds\TargetView source
class EntityReferenceTest extends EntityReferenceTestBase {
/**
* Field manager used in the test.
*
* @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->entityFieldManager = $this
->prophesize(EntityFieldManagerInterface::class);
$this->entityFieldManager
->getFieldStorageDefinitions('referenceable_entity_type')
->willReturn([]);
$this
->buildContainer();
}
/**
* {@inheritdoc}
*/
protected function createTargetPluginInstance(array $configuration = []) {
$configuration += [
'feed_type' => $this
->createMock(FeedTypeInterface::class),
'target_definition' => $this
->createTargetDefinitionMock(),
];
return new EntityReference($configuration, 'entity_reference', [], $this->entityTypeManager
->reveal(), $this->entityFieldManager
->reveal(), $this->entityFinder
->reveal());
}
/**
* {@inheritdoc}
*/
protected function getTargetClass() {
return EntityReference::class;
}
/**
* {@inheritdoc}
*/
protected function createReferencableEntityType() {
$referenceable_entity_type = $this
->prophesize(EntityTypeInterface::class);
$referenceable_entity_type
->entityClassImplements(ContentEntityInterface::class)
->willReturn(TRUE)
->shouldBeCalled();
$referenceable_entity_type
->getKey('label')
->willReturn('referenceable_entity_type label');
return $referenceable_entity_type;
}
/**
* @covers ::prepareTarget
*/
public function testPrepareTarget() {
$field_definition_mock = $this
->getMockFieldDefinition();
$field_definition_mock
->expects($this
->once())
->method('getSetting')
->will($this
->returnValue('referenceable_entity_type'));
$method = $this
->getMethod($this
->getTargetClass(), 'prepareTarget')
->getClosure();
$this
->assertInstanceof(FieldTargetDefinition::class, $method($field_definition_mock));
}
/**
* @covers ::prepareValue
* @covers ::findEntities
*/
public function testPrepareValue() {
$this->entityFinder
->findEntities('referenceable_entity_type', 'referenceable_entity_type label', 1, [])
->willReturn([
12,
13,
14,
])
->shouldBeCalled();
$method = $this
->getProtectedClosure($this
->createTargetPluginInstance(), 'prepareValue');
$values = [
'target_id' => 1,
];
$method(0, $values);
$this
->assertSame($values, [
'target_id' => 12,
]);
}
/**
* @covers ::prepareValue
*
* Tests prepareValue() without passing values.
*/
public function testPrepareValueEmptyFeed() {
$method = $this
->getProtectedClosure($this
->createTargetPluginInstance(), 'prepareValue');
$values = [
'target_id' => '',
];
$this
->expectException(EmptyFeedException::class);
$method(0, $values);
}
/**
* @covers ::prepareValue
* @covers ::findEntities
*
* Tests prepareValue() method without match.
*/
public function testPrepareValueReferenceNotFound() {
$this->entityFinder
->findEntities('referenceable_entity_type', 'referenceable_entity_type label', 1, [])
->willReturn([])
->shouldBeCalled();
$method = $this
->getProtectedClosure($this
->createTargetPluginInstance(), 'prepareValue');
$values = [
'target_id' => 1,
];
$this
->expectException(ReferenceNotFoundException::class, "Referenced entity not found for field <em class=\"placeholder\">referenceable_entity_type label</em> with value <em class=\"placeholder\">1</em>.");
$method(0, $values);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityReferenceTest:: |
protected | property | Field manager used in the test. | |
EntityReferenceTest:: |
protected | function |
Creates a referencable entity type instance. Overrides EntityReferenceTestBase:: |
|
EntityReferenceTest:: |
protected | function |
Creates a new target plugin instance. Overrides EntityReferenceTestBase:: |
|
EntityReferenceTest:: |
protected | function |
Returns the target class. Overrides FieldTargetTestBase:: |
|
EntityReferenceTest:: |
public | function |
Overrides EntityReferenceTestBase:: |
|
EntityReferenceTest:: |
public | function |
@covers ::prepareTarget Overrides EntityReferenceTestBase:: |
|
EntityReferenceTest:: |
public | function | @covers ::prepareValue @covers ::findEntities | |
EntityReferenceTest:: |
public | function |
@covers ::prepareValue Overrides EntityReferenceTestBase:: |
|
EntityReferenceTest:: |
public | function | @covers ::prepareValue @covers ::findEntities | |
EntityReferenceTestBase:: |
protected | property | The Feeds entity finder service. | |
EntityReferenceTestBase:: |
protected | property | The entity storage prophecy used in the test. | |
EntityReferenceTestBase:: |
protected | property | The entity type manager prophecy used in the test. | |
EntityReferenceTestBase:: |
protected | function | Builds the Drupal service container. | |
EntityReferenceTestBase:: |
protected | function | Creates a Feeds target definition mock. | |
EntityReferenceTestBase:: |
protected | function | Returns the entity storage class name to use in this test. | 1 |
EntityReferenceTestBase:: |
protected | function | Returns the entity type machine name to use in this test. | 1 |
FeedsMockingTrait:: |
protected | function | Mocks an account object. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked AccountSwitcher object. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked feed entity. | |
FeedsMockingTrait:: |
protected | function | Returns a mocked feed type entity. | |
FeedsMockingTrait:: |
protected | function | Mocks a field definition. | 1 |
FeedsMockingTrait:: |
protected | function | Mocks the file system. | |
FeedsReflectionTrait:: |
protected | function | Calls a protected method on the given object. | |
FeedsReflectionTrait:: |
protected | function | Gets a ReflectionMethod for a class method. | |
FeedsReflectionTrait:: |
protected | function | Returns a dynamically created closure for the object's method. | |
FeedsReflectionTrait:: |
protected | function | Sets a protected property. | |
FeedsUnitTestCase:: |
protected | function | Returns the absolute directory path of the Feeds module. | |
FeedsUnitTestCase:: |
protected | function | Defines stub constants. | |
FeedsUnitTestCase:: |
protected | function | Returns a mock stream wrapper manager. | |
FeedsUnitTestCase:: |
protected | function | Returns the absolute directory path of the resources folder. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |