class EntityReferenceItemNormalizerTest in Tome 8
@coversDefaultClass \Drupal\tome_sync\Normalizer\EntityReferenceItemNormalizer @group tome_sync
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\tome_sync\Unit\Normalizer\EntityReferenceItemNormalizerTest uses InternalTypedDataTestTrait
Expanded class hierarchy of EntityReferenceItemNormalizerTest
File
- modules/
tome_sync/ tests/ src/ Unit/ Normalizer/ EntityReferenceItemNormalizerTest.php, line 20
Namespace
Drupal\Tests\tome_sync\Unit\NormalizerView source
class EntityReferenceItemNormalizerTest extends UnitTestCase {
use InternalTypedDataTestTrait;
/**
* Tests the normalize() method.
*
* @covers ::normalize
*/
public function testNormalize() {
$entity_repository = $this
->prophesize(EntityRepositoryInterface::class);
$normalizer = new EntityReferenceItemNormalizer($entity_repository
->reveal());
$serializer = $this
->prophesize(Serializer::class);
$serializer
->normalize(Argument::cetera())
->willReturn(1);
$normalizer
->setSerializer($serializer
->reveal());
$entity = $this
->prophesize(EntityInterface::class);
$entity
->hasLinkTemplate('canonical')
->willReturn(FALSE)
->shouldBeCalled();
$entity
->uuid()
->willReturn('080e3add-f9d5-41ac-9821-eea55b7b42fb')
->shouldBeCalled();
$entity
->getEntityTypeId()
->willReturn('test_type')
->shouldBeCalled();
$entity_reference = $this
->prophesize(TypedDataInterface::class);
$entity_reference
->getValue()
->willReturn($entity
->reveal())
->shouldBeCalled();
$field_definition = $this
->prophesize(FieldDefinitionInterface::class);
$field_definition
->getSetting('target_type')
->willReturn('test_type');
$field_item = $this
->prophesize(EntityReferenceItem::class);
$field_item
->getIterator()
->willReturn(new \ArrayIterator([
'target_id' => [],
]));
$field_item
->getFieldDefinition()
->willReturn($field_definition
->reveal());
$field_item
->get('entity')
->willReturn($entity_reference)
->shouldBeCalled();
$field_item
->getProperties(TRUE)
->willReturn([
'target_id' => $this
->getTypedDataProperty(FALSE),
])
->shouldBeCalled();
$normalized = $normalizer
->normalize($field_item
->reveal());
$expected = [
'target_type' => 'test_type',
'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
];
$this
->assertSame($expected, $normalized, 'The target_id and url keys were removed as expected.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityReferenceItemNormalizerTest:: |
public | function | Tests the normalize() method. | |
InternalTypedDataTestTrait:: |
protected | function | Gets a typed data property. | |
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. | |
UnitTestCase:: |
protected | function | 340 |