You are here

public function LinkFieldUnserializerTest::testLinkFieldUnSerializer in Acquia Content Hub 8.2

Throws

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Kernel/EventSubscriber/UnserializeContentField/LinkFieldUnserializerTest.php, line 62

Class

LinkFieldUnserializerTest
Test that links are handled correctly during unserialization.

Namespace

Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\UnserializeContentField

Code

public function testLinkFieldUnSerializer() {

  // Create mock taxonomy term.
  $term = Term::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => 'tags',
  ]);
  $term
    ->save();
  $stack = $this
    ->prophesize(DependencyStack::class);
  $wrapper = $this
    ->prophesize(DependentEntityWrapper::class);
  $wrapper
    ->getEntity()
    ->willReturn($term);
  $stack
    ->getDependency(Argument::any())
    ->willReturn($wrapper
    ->reveal());
  $meta_data = [
    'type' => 'link',
  ];
  $mock_field = [
    'value' => [
      'en' => [
        0 => [
          'uri' => 'uuid',
          'title' => 'test',
          'options' => [],
          'uri_type' => 'internal',
          'internal_type' => 'internal_entity',
        ],
      ],
    ],
  ];
  $entity_type = $this
    ->prophesize(EntityTypeInterface::class);
  $event = new UnserializeCdfEntityFieldEvent($entity_type
    ->reveal(), 'test', 'link', $mock_field, $meta_data, $stack
    ->reveal());
  $this->dispatcher
    ->dispatch(AcquiaContentHubEvents::UNSERIALIZE_CONTENT_ENTITY_FIELD, $event);
  $expected = [
    'en' => [
      'link' => [
        0 => [
          'uri' => 'internal:/taxonomy/term/1',
          'title' => 'test',
          'options' => [],
        ],
      ],
    ],
  ];
  $this
    ->assertEqual($event
    ->getValue(), $expected);
}