You are here

public function BaseFieldDefinitionTest::testFieldCardinality in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest::testFieldCardinality()

Tests field cardinality.

@covers ::getCardinality @covers ::setCardinality

File

core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php, line 282

Class

BaseFieldDefinitionTest
Unit test for BaseFieldDefinition.

Namespace

Drupal\Tests\Core\Entity

Code

public function testFieldCardinality() {
  $definition = BaseFieldDefinition::create($this->fieldType);
  $this
    ->assertEquals(1, $definition
    ->getCardinality());
  $definition
    ->setCardinality(2);
  $this
    ->assertEquals(2, $definition
    ->getCardinality());
  $definition
    ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $this
    ->assertEquals(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, $definition
    ->getCardinality());
}