You are here

public function EntityFormTest::testValidationHandlers in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityFormTest.php \Drupal\system\Tests\Entity\EntityFormTest::testValidationHandlers()

Checks that validation handlers works as expected.

File

core/modules/system/src/Tests/Entity/EntityFormTest.php, line 156
Contains \Drupal\system\Tests\Entity\EntityFormTest.

Class

EntityFormTest
Tests the entity form.

Namespace

Drupal\system\Tests\Entity

Code

public function testValidationHandlers() {

  /** @var \Drupal\Core\State\StateInterface $state */
  $state = $this->container
    ->get('state');

  // Check that from-level validation handlers can be defined and can alter
  // the form array.
  $state
    ->set('entity_test.form.validate.test', 'form-level');
  $this
    ->drupalPostForm('entity_test/add', [], 'Save');
  $this
    ->assertTrue($state
    ->get('entity_test.form.validate.result'), 'Form-level validation handlers behave correctly.');

  // Check that defining a button-level validation handler causes an exception
  // to be thrown.
  $state
    ->set('entity_test.form.validate.test', 'button-level');
  $this
    ->drupalPostForm('entity_test/add', [], 'Save');
  $this
    ->assertEqual($state
    ->get('entity_test.form.save.exception'), 'Drupal\\Core\\Entity\\EntityStorageException: Entity validation was skipped.', 'Button-level validation handlers behave correctly.');
}