You are here

public function FieldStorageConfigEntityUnitTest::testEnforcedCardinality in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest::testEnforcedCardinality()
  2. 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 147
Contains \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest.

Class

FieldStorageConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldStorageConfig

Namespace

Drupal\Tests\field\Unit

Code

public function testEnforcedCardinality() {
  $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());
}