You are here

protected function TaxonomyTermTest::assertEntity in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/csv_example/tests/src/Kernel/Migrate/TaxonomyTermTest.php \Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate\TaxonomyTermTest::assertEntity()
  2. 3.0.x modules/csv_example/tests/src/Kernel/Migrate/TaxonomyTermTest.php \Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate\TaxonomyTermTest::assertEntity()

Validate a migrated term contains the expected values.

Parameters

string $id: Entity ID to load and check.

string $expected_label: The label the migrated entity should have.

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

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

string $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 $expected_field_integer_value: The value the migrated entity field should have.

int $expected_term_reference_tid: The term reference id the migrated entity field should have.

bool $expected_container_flag: The term should be a container entity.

1 call to TaxonomyTermTest::assertEntity()
TaxonomyTermTest::testTaxonomyTerms in modules/csv_example/tests/src/Kernel/Migrate/TaxonomyTermTest.php
Tests the taxonomy term migration.

File

modules/csv_example/tests/src/Kernel/Migrate/TaxonomyTermTest.php, line 79

Class

TaxonomyTermTest
Upgrade taxonomy terms.

Namespace

Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate

Code

protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, array $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL, $expected_container_flag = FALSE) {

  /** @var \Drupal\taxonomy\TermInterface $entity */
  $entity = Term::load($id);
  $this
    ->assertInstanceOf(TermInterface::class, $entity);
  $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, $this
    ->getParentIDs($id));
  $this
    ->assertHierarchy($expected_vid, $id, $expected_parents);
  if (!is_null($expected_field_integer_value)) {
    $this
      ->assertTrue($entity
      ->hasField('field_integer'));
    $this
      ->assertEquals($expected_field_integer_value, $entity->field_integer->value);
  }
  if (!is_null($expected_term_reference_tid)) {
    $this
      ->assertTrue($entity
      ->hasField('field_integer'));
    $this
      ->assertEquals($expected_term_reference_tid, $entity->field_term_reference->target_id);
  }
  if ($entity
    ->hasField('forum_container')) {
    $this
      ->assertEquals($expected_container_flag, $entity->forum_container->value);
  }
}