ArgumentValidatorTest.php in Drupal 9
File
core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php
View source
<?php
namespace Drupal\Tests\views_ui\Functional;
use Drupal\views\Views;
class ArgumentValidatorTest extends UITestBase {
public static $testViews = [
'test_argument',
];
protected $defaultTheme = 'stark';
public function testSpecifyValidation() {
$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.');
$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.');
}
protected function saveArgumentHandlerWithValidationOptions($specify_validation) {
$options = [
'options[validate][type]' => 'entity---node',
'options[specify_validation]' => $specify_validation,
];
$this
->drupalGet('admin/structure/views/nojs/handler/test_argument/default/argument/id');
$this
->submitForm($options, 'Apply');
$this
->drupalGet('admin/structure/views/view/test_argument');
$this
->submitForm([], 'Save');
}
}