function NodeTypeValidationTest::testPreviewModeValidation

Same name and namespace in other branches
  1. 11.x core/modules/node/tests/src/Kernel/NodeTypeValidationTest.php \Drupal\Tests\node\Kernel\NodeTypeValidationTest::testPreviewModeValidation()

Tests that a node type's preview mode is constrained to certain values.

File

core/modules/node/tests/src/Kernel/NodeTypeValidationTest.php, line 45

Class

NodeTypeValidationTest
Tests validation of node_type entities.

Namespace

Drupal\Tests\node\Kernel

Code

public function testPreviewModeValidation() : void {
  $this->entity
    ->setPreviewMode(38);
  $this->assertValidationErrors([
    'preview_mode' => 'The value you selected is not a valid choice.',
  ]);
  $this->entity
    ->setPreviewMode(-1);
  $this->assertValidationErrors([
    'preview_mode' => 'The value you selected is not a valid choice.',
  ]);
  $allowed_values = [
    DRUPAL_DISABLED,
    DRUPAL_OPTIONAL,
    DRUPAL_REQUIRED,
  ];
  foreach ($allowed_values as $allowed_value) {
    $this->entity
      ->setPreviewMode($allowed_value);
    $this->assertValidationErrors([]);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.