You are here

class EntityReferenceItemNormalizerTest in Tome 8

@coversDefaultClass \Drupal\tome_sync\Normalizer\EntityReferenceItemNormalizer @group tome_sync

Hierarchy

Expanded class hierarchy of EntityReferenceItemNormalizerTest

File

modules/tome_sync/tests/src/Unit/Normalizer/EntityReferenceItemNormalizerTest.php, line 20

Namespace

Drupal\Tests\tome_sync\Unit\Normalizer
View 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

Namesort descending Modifiers Type Description Overrides
EntityReferenceItemNormalizerTest::testNormalize public function Tests the normalize() method.
InternalTypedDataTestTrait::getTypedDataProperty protected function Gets a typed data property.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340