You are here

public function UnserializationTest::testTaxonomyTermUnserialization in Acquia Content Hub 8.2

Tests content entity unserialization.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

\ReflectionException

See also

_acquia_contenthub_publisher_enqueue_entity()

File

tests/src/Kernel/UnserializationTest.php, line 171

Class

UnserializationTest
Tests that entities are properly unserialized.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

public function testTaxonomyTermUnserialization() {
  $cdf_document = $this
    ->createCDFDocumentFromFixture('taxonomy.json');
  $this->contentHubClient
    ->getEntities([
    self::CLIENT_UUID_2 => self::CLIENT_UUID_2,
  ])
    ->willReturn($cdf_document);
  $this->contentHubClient
    ->getInterestsByWebhook(Argument::type('string'))
    ->willReturn([
    self::CLIENT_UUID_2,
  ]);
  $this
    ->initializeContentHubClientExpectation($cdf_document);
  $this->contentHubClient
    ->addEntitiesToInterestList("foo", [
    self::CLIENT_UUID_3,
    self::CLIENT_UUID_2,
  ])
    ->willReturn(new Response());
  $item = new \stdClass();
  $item->uuids = implode(', ', [
    self::CLIENT_UUID_2,
  ]);
  $this->contentHubImportQueueWorker
    ->processItem($item);

  // Checks that vocabulary has been imported.
  $vocabulary = Vocabulary::load('tags');
  $this
    ->assertNotEmpty($vocabulary
    ->id());
  $this
    ->assertEquals('Tags', $vocabulary
    ->label());

  // Checks that taxonomy has been imported.

  /** @var \Drupal\taxonomy\Entity\Term[] $taxonomy_terms */
  $taxonomy_terms = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadByProperties([
    'name' => 'tag1',
  ]);
  $this
    ->assertNotEmpty($taxonomy_terms);
  $taxonomy_term = current($taxonomy_terms);
  $this
    ->assertNotEmpty($taxonomy_term
    ->id());
}