function MigrateFieldTest::assertEntity

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d7\MigrateFieldTest::assertEntity()
  2. 8.9.x core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d7\MigrateFieldTest::assertEntity()
  3. 11.x core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php \Drupal\Tests\field\Kernel\Migrate\d7\MigrateFieldTest::assertEntity()

Asserts various aspects of a field_storage_config entity.

@internal

Parameters

string $id: The entity ID in the form ENTITY_TYPE.FIELD_NAME.

string $expected_type: The expected field type.

bool $expected_translatable: Whether or not the field is expected to be translatable.

int $expected_cardinality: The expected cardinality of the field.

1 call to MigrateFieldTest::assertEntity()
MigrateFieldTest::testFields in core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php
Tests migrating D7 fields to field_storage_config entities.

File

core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php, line 50

Class

MigrateFieldTest
Migrates Drupal 7 fields.

Namespace

Drupal\Tests\field\Kernel\Migrate\d7

Code

protected function assertEntity(string $id, string $expected_type, bool $expected_translatable, int $expected_cardinality) : void {
    [
        $expected_entity_type,
        $expected_name,
    ] = explode('.', $id);
    
    /** @var \Drupal\field\FieldStorageConfigInterface $field */
    $field = FieldStorageConfig::load($id);
    $this->assertInstanceOf(FieldStorageConfigInterface::class, $field);
    $this->assertEquals($expected_name, $field->getName());
    $this->assertEquals($expected_type, $field->getType());
    $this->assertEquals($expected_translatable, $field->isTranslatable());
    $this->assertEquals($expected_entity_type, $field->getTargetEntityTypeId());
    if ($expected_cardinality === 1) {
        $this->assertFalse($field->isMultiple());
    }
    else {
        $this->assertTrue($field->isMultiple());
    }
    $this->assertEquals($expected_cardinality, $field->getCardinality());
}

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