You are here

protected function CommerceMigrateCoreTestTrait::assertHierarchy in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/CommerceMigrateCoreTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateCoreTestTrait::assertHierarchy()
  2. 3.0.x tests/src/Kernel/CommerceMigrateCoreTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateCoreTestTrait::assertHierarchy()

Assert that a term is present in the tree storage, with the right parents.

Parameters

string $vid: Vocabulary ID.

int $tid: ID of the term to check.

array $parent_ids: The expected parent term IDs.

1 call to CommerceMigrateCoreTestTrait::assertHierarchy()
CommerceMigrateCoreTestTrait::assertTermEntity in tests/src/Kernel/CommerceMigrateCoreTestTrait.php
Validate a migrated term contains the expected values.

File

tests/src/Kernel/CommerceMigrateCoreTestTrait.php, line 65

Class

CommerceMigrateCoreTestTrait
Helper function to test migrations.

Namespace

Drupal\Tests\commerce_migrate\Kernel

Code

protected function assertHierarchy($vid, $tid, array $parent_ids) {
  if (!isset($this->treeData[$vid])) {
    $tree = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term')
      ->loadTree($vid);
    $this->treeData[$vid] = [];
    foreach ($tree as $item) {
      $this->treeData[$vid][$item->tid] = $item;
    }
  }
  $this
    ->assertArrayHasKey($tid, $this->treeData[$vid], "Term {$tid} exists in taxonomy tree");
  $term = $this->treeData[$vid][$tid];
  $this
    ->assertEquals(array_filter($parent_ids), array_filter($term->parents), "Term {$tid} has correct parents in taxonomy tree");
}