function MigrateTestTrait::assertHierarchy

Same name in other branches
  1. 11.x core/modules/forum/tests/src/Kernel/Migrate/MigrateTestTrait.php \Drupal\Tests\forum\Kernel\Migrate\MigrateTestTrait::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 MigrateTestTrait::assertHierarchy()
MigrateTestTrait::assertEntity in core/modules/forum/tests/src/Kernel/Migrate/MigrateTestTrait.php
Validate a migrated term contains the expected values.

File

core/modules/forum/tests/src/Kernel/Migrate/MigrateTestTrait.php, line 89

Class

MigrateTestTrait
Common assertions for migration tests.

Namespace

Drupal\Tests\forum\Kernel\Migrate

Code

protected function assertHierarchy(string $vid, int $tid, array $parent_ids) : void {
    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($parent_ids, $term->parents, "Term {$tid} has correct parents in taxonomy tree");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.