You are here

public function PreExistingTermMultipleParentImportExportTest::verifyTaxonomyTerm in Acquia Content Hub 8.2

Verifies data for a taxonomy term given its key in the termValues array.

Parameters

string $key: The Taxonomy term key in the $this->termValues array.

array $imported_uuids: Provides a list of imported UUIDs (coming from Content Hub).

bool $imported: TRUE if this is an imported term, FALSE if local term. Defaults to FALSE.

2 calls to PreExistingTermMultipleParentImportExportTest::verifyTaxonomyTerm()
PreExistingTermMultipleParentImportExportTest::testTermImportExport1 in tests/src/Kernel/PreExistingTermMultipleParentImportExportTest.php
Performs tests with taxonomy term with multiple parents.
PreExistingTermMultipleParentImportExportTest::testTermImportExport2 in tests/src/Kernel/PreExistingTermMultipleParentImportExportTest.php
Performs tests with taxonomy term with multiple parents.

File

tests/src/Kernel/PreExistingTermMultipleParentImportExportTest.php, line 153

Class

PreExistingTermMultipleParentImportExportTest
Tests terms with multiple parents during export and import.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

public function verifyTaxonomyTerm($key, array $imported_uuids, $imported = FALSE) {
  $name = $this->termValues[$key]['name'];
  $terms = $this->entityTypeManager
    ->getStorage('taxonomy_term')
    ->loadByProperties([
    'name' => $name,
  ]);

  // Assert there is only a single term with this name.
  $this
    ->assertEquals(1, count($terms));
  $term = reset($terms);

  // Verify the uuid of this term is either imported or local.
  if ($imported) {
    $this
      ->assertTrue(in_array($term
      ->uuid(), $imported_uuids), "Failed to assert that UUID for term '{$term->label()}' ({$term->uuid()}) was found in list of imported UUIDs.");
  }
  else {
    $this
      ->assertFalse(in_array($term
      ->uuid(), $imported_uuids), "Failed to assert that UUID for term '{$term->label()}' ({$term->uuid()}) was not found in list of imported UUIDs.");
  }

  // Verify parents.
  $expected_parents = [];
  $parent_keys = $this->termValues[$key]['parent'];
  foreach ($parent_keys as $parent_key) {
    $expected_parents[] = $this->termValues[$parent_key]['name'];
  }
  $parents = $this->entityTypeManager
    ->getStorage('taxonomy_term')
    ->loadParents($term
    ->id());
  $actual_parents = [];
  foreach ($parents as $parent) {
    $actual_parents[] = $parent
      ->label();
  }
  $this
    ->assertEquals($expected_parents, $actual_parents);
}