function MigrateTestTrait::assertEntity

Same name in other branches
  1. 10 core/modules/forum/tests/src/Kernel/Migrate/MigrateTestTrait.php \Drupal\Tests\forum\Kernel\Migrate\MigrateTestTrait::assertEntity()

Validate a migrated term contains the expected values.

@internal

Parameters

int $id: Entity ID to load and check.

string $expected_language: The language code for this term.

$expected_label: The label the migrated entity should have.

$expected_vid: The parent vocabulary the migrated entity should have.

string|null $expected_description: The description the migrated entity should have.

string|null $expected_format: The format the migrated entity should have.

int $expected_weight: The weight the migrated entity should have.

array $expected_parents: The parent terms the migrated entity should have.

int|null $expected_container_flag: The term should be a container entity.

2 calls to MigrateTestTrait::assertEntity()
MigrateTaxonomyTermTest::testTaxonomyTerms in core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php
Assert the forum taxonomy terms.
MigrateTaxonomyTermTest::testTaxonomyTerms in core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
Assert the forum taxonomy terms.

File

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

Class

MigrateTestTrait
Common assertions for migration tests.

Namespace

Drupal\Tests\forum\Kernel\Migrate

Code

protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, ?string $expected_description = '', ?string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int|null $expected_container_flag = NULL) : void {
    
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class, $entity);
    $this->assertSame($expected_language, $entity->language()
        ->getId());
    $this->assertEquals($expected_label, $entity->label());
    $this->assertEquals($expected_vid, $entity->bundle());
    $this->assertEquals($expected_description, $entity->getDescription());
    $this->assertEquals($expected_format, $entity->getFormat());
    $this->assertEquals($expected_weight, $entity->getWeight());
    $this->assertEquals($expected_parents, array_column($entity->get('parent')
        ->getValue(), 'target_id'));
    $this->assertHierarchy($expected_vid, $id, $expected_parents);
    if (isset($expected_container_flag)) {
        $this->assertEquals($expected_container_flag, $entity->forum_container->value);
    }
}

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