You are here

public function FieldDefinitionTest::testFieldRequired in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php \Drupal\Tests\Core\Entity\FieldDefinitionTest::testFieldRequired()
  2. 10 core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php \Drupal\Tests\Core\Entity\FieldDefinitionTest::testFieldRequired()

Tests required.

@covers ::isRequired @covers ::setRequired @dataProvider factoryTypeProvider

File

core/tests/Drupal/Tests/Core/Entity/FieldDefinitionTest.php, line 256

Class

FieldDefinitionTest
Unit test for the FieldDefinition class.

Namespace

Drupal\Tests\Core\Entity

Code

public function testFieldRequired($factory_name) {
  $definition = $this
    ->initializeFieldUsingFactory($factory_name);
  $this
    ->assertFalse($definition
    ->isRequired());
  $definition
    ->setRequired(TRUE);
  $this
    ->assertTrue($definition
    ->isRequired());
  $definition
    ->setRequired(FALSE);
  $this
    ->assertFalse($definition
    ->isRequired());
}