You are here

public function ContentHubEntityDependencyTest::testGetRemoteDependencies in Acquia Content Hub 8

Test getRemoteDependencies method.

@covers ::getRemoteDependencies

File

tests/src/Unit/ContentHubEntityDependencyTest.php, line 225

Class

ContentHubEntityDependencyTest
PHPUnit for the ContentHubEntityDependency class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testGetRemoteDependencies() {
  $this->moduleHandler
    ->expects($this
    ->at(0))
    ->method('moduleExists')
    ->with('entity_embed')
    ->willReturn(TRUE);
  $values['attributes']['field_reference1'] = [
    'type' => Attribute::TYPE_REFERENCE,
    'value' => [
      'en' => '00000000-2222-0000-0000-000000000000',
    ],
  ];
  $values['attributes']['field_reference2'] = [
    'type' => Attribute::TYPE_ARRAY_REFERENCE,
    'value' => [
      'en' => [
        '00000000-3333-0000-0000-000000000000',
        '00000000-4444-0000-0000-000000000000',
        '00000000-5555-0000-0000-000000000000',
      ],
    ],
  ];

  // Author should be excluded from dependency calculation.
  $values['attributes']['author'] = [
    'type' => Attribute::TYPE_REFERENCE,
    'value' => [
      'en' => '00000000-6666-0000-0000-000000000000',
    ],
  ];

  // Embedded entities should be included in the dependencies.
  $body_value = [
    'value' => '<drupal-entity data-caption="some_image" data-embed-button="media_browser" data-entity-embed-display="view_mode:media.embedded" data-entity-type="media" data-entity-uuid="00000000-7777-0000-0000-000000000000"></drupal-entity>',
    'summary' => '',
    'format' => 'rich_text',
  ];
  $values['attributes']['body'] = [
    'type' => Attribute::TYPE_ARRAY_STRING,
    'value' => [
      'en' => [
        json_encode($body_value, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT),
      ],
    ],
  ];
  $this->entity = $this
    ->createContentHubEntity($values);
  $ch_entity_dependency = new ContentHubEntityDependency($this->entity);
  $dependencies = $ch_entity_dependency
    ->getRemoteDependencies();
  $expected = [
    '00000000-2222-0000-0000-000000000000',
    '00000000-3333-0000-0000-000000000000',
    '00000000-4444-0000-0000-000000000000',
    '00000000-5555-0000-0000-000000000000',
    '00000000-7777-0000-0000-000000000000',
  ];
  $this
    ->assertEquals($expected, $dependencies);
}