function ArgumentValidatorTest::testSpecifyValidation

Same name in other branches
  1. 9 core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php \Drupal\Tests\views_ui\Functional\ArgumentValidatorTest::testSpecifyValidation()
  2. 8.9.x core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php \Drupal\Tests\views_ui\Functional\ArgumentValidatorTest::testSpecifyValidation()
  3. 11.x core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php \Drupal\Tests\views_ui\Functional\ArgumentValidatorTest::testSpecifyValidation()

Tests the 'Specify validation criteria' checkbox functionality.

File

core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php, line 31

Class

ArgumentValidatorTest
Tests the Argument validator through the UI.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testSpecifyValidation() : void {
    // Specify a validation based on Node for the 'id' argument on the default
    // display and assert that this works.
    $this->saveArgumentHandlerWithValidationOptions(TRUE);
    $view = Views::getView('test_argument');
    $handler = $view->getHandler('default', 'argument', 'id');
    $this->assertTrue($handler['specify_validation'], 'Validation for this argument has been turned on.');
    $this->assertEquals('entity:node', $handler['validate']['type'], 'Validation for the argument is based on the node.');
    // Uncheck the 'Specify validation criteria' checkbox and expect the
    // validation type to be reset back to 'none'.
    $this->saveArgumentHandlerWithValidationOptions(FALSE);
    $view = Views::getView('test_argument');
    $handler = $view->getHandler('default', 'argument', 'id');
    $this->assertFalse($handler['specify_validation'], 'Validation for this argument has been turned off.');
    $this->assertEquals('none', $handler['validate']['type'], 'Validation for the argument has been reverted to Basic Validation.');
}

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