You are here

public function BaseFieldDefinitionTest::testFieldRequired 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::testFieldRequired()

Tests required.

@covers ::isRequired @covers ::setRequired

File

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

Class

BaseFieldDefinitionTest
Unit test for BaseFieldDefinition.

Namespace

Drupal\Tests\Core\Entity

Code

public function testFieldRequired() {
  $definition = BaseFieldDefinition::create($this->fieldType);
  $this
    ->assertFalse($definition
    ->isRequired());
  $definition
    ->setRequired(TRUE);
  $this
    ->assertTrue($definition
    ->isRequired());
  $definition
    ->setRequired(FALSE);
  $this
    ->assertFalse($definition
    ->isRequired());
}