function NodeTypeValidationTest::testPreviewModeValidation

Same name and namespace in other branches
  1. 10 core/modules/node/tests/src/Kernel/NodeTypeValidationTest.php \Drupal\Tests\node\Kernel\NodeTypeValidationTest::testPreviewModeValidation()
  2. main 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.

Attributes

#[IgnoreDeprecations]

File

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

Class

NodeTypeValidationTest
Tests validation of node_type entities.

Namespace

Drupal\Tests\node\Kernel

Code

public function testPreviewModeValidation() : void {
  $this->expectUserDeprecationMessage('Calling Drupal\\node\\Entity\\NodeType::setPreviewMode with an integer $preview_mode parameter is deprecated in drupal:11.3.0 and is removed in drupal:13.0.0. Use the \\Drupal\\node\\NodePreviewMode enum instead. See https://www.drupal.org/node/3538666');
  $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 = NodePreviewMode::cases();
  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.