You are here

public function FieldTypeTest::testRequiredOptions in Double Field 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/FieldTypeTest.php \Drupal\Tests\double_field\Functional\FieldTypeTest::testRequiredOptions()

Test required options.

File

tests/src/Functional/FieldTypeTest.php, line 533

Class

FieldTypeTest
A test for Double Field type.

Namespace

Drupal\Tests\double_field\Functional

Code

public function testRequiredOptions() : void {
  $storage_settings['storage']['first']['type'] = 'integer';
  $storage_settings['storage']['second']['type'] = 'boolean';
  $this
    ->saveFieldStorageSettings($storage_settings);
  $this
    ->assertViolations([
    NULL,
    1,
  ], [
    'This value should not be blank.',
  ]);

  // Zero should be treated as not empty value.
  $this
    ->assertNoViolations([
    0,
    1,
  ]);
  $settings['first']['required'] = FALSE;
  $this
    ->saveFieldSettings($settings);
  $this
    ->assertNoViolations([
    NULL,
    1,
  ]);

  // For boolean field zero is an empty value.
  $this
    ->assertViolations([
    123,
    0,
  ], [
    'This value should not be blank.',
  ]);
  $settings['second']['required'] = FALSE;
  $this
    ->saveFieldSettings($settings);
  $this
    ->assertNoViolations([
    123,
    0,
  ]);
}