function MigrateTaxonomyTermTranslationTest::assertHierarchy

Same name in this branch
  1. 8.9.x core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTranslationTest::assertHierarchy()
Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php \Drupal\Tests\content_translation\Kernel\Migrate\d6\MigrateTaxonomyTermTranslationTest::assertHierarchy()
  2. 9 core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTranslationTest::assertHierarchy()
  3. 10 core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php \Drupal\Tests\content_translation\Kernel\Migrate\d6\MigrateTaxonomyTermTranslationTest::assertHierarchy()
  4. 10 core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTranslationTest::assertHierarchy()
  5. 11.x core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php \Drupal\Tests\content_translation\Kernel\Migrate\d6\MigrateTaxonomyTermTranslationTest::assertHierarchy()
  6. 11.x core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php \Drupal\Tests\taxonomy\Kernel\Migrate\d7\MigrateTaxonomyTermTranslationTest::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 MigrateTaxonomyTermTranslationTest::assertHierarchy()
MigrateTaxonomyTermTranslationTest::assertEntity in core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php
Validate a migrated term contains the expected values.

File

core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php, line 98

Class

MigrateTaxonomyTermTranslationTest
Test migration of translated taxonomy terms.

Namespace

Drupal\Tests\content_translation\Kernel\Migrate\d6

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];
    // PostgreSQL, MySQL and SQLite may not return the parent terms in the same
    // order so sort before testing.
    sort($parent_ids);
    $actual_terms = array_filter($term->parents);
    sort($actual_terms);
    $this->assertEquals($parent_ids, $actual_terms, "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.