function FieldStorageConfigEntityUnitTest::testEnforcedCardinality

Same name in other branches
  1. 9 core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest::testEnforcedCardinality()
  2. 8.9.x core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest::testEnforcedCardinality()
  3. 10 core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest::testEnforcedCardinality()

Tests enforced cardinality.

@covers ::getCardinality

File

core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php, line 146

Class

FieldStorageConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldStorageConfig

Namespace

Drupal\Tests\field\Unit

Code

public function testEnforcedCardinality() : void {
    $this->fieldTypeManager
        ->expects($this->any())
        ->method('getDefinition')
        ->with('test_field_type')
        ->willReturn([
        'class' => TestFieldType::class,
        // This field type defines an enforced cardinality.
'cardinality' => 21,
    ]);
    $field_storage = new FieldStorageConfig([
        'entity_type' => 'entity_test',
        'field_name' => 'test_field',
        'type' => 'test_field_type',
        'module' => 'test_module',
    ]);
    // Custom cardinality tentative.
    $field_storage->setCardinality(8);
    // Check that the enforced cardinality is returned.
    $this->assertEquals(21, $field_storage->getCardinality());
}

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