3 namespace Drupal\Tests\views_ui\Functional;
5 use Drupal\views\Views;
8 * Tests the Argument validator through the UI.
12 class ArgumentValidatorTest extends UITestBase {
15 * Views used by this test.
19 public static $testViews = ['test_argument'];
22 * Tests the 'Specify validation criteria' checkbox functionality.
24 public function testSpecifyValidation() {
25 // Specify a validation based on Node for the 'id' argument on the default
26 // display and assert that this works.
27 $this->saveArgumentHandlerWithValidationOptions(TRUE);
28 $view = Views::getView('test_argument');
29 $handler = $view->getHandler('default', 'argument', 'id');
30 $this->assertTrue($handler['specify_validation'], 'Validation for this argument has been turned on.');
31 $this->assertEqual('entity:node', $handler['validate']['type'], 'Validation for the argument is based on the node.');
33 // Uncheck the 'Specify validation criteria' checkbox and expect the
34 // validation type to be reset back to 'none'.
35 $this->saveArgumentHandlerWithValidationOptions(FALSE);
36 $view = Views::getView('test_argument');
37 $handler = $view->getHandler('default', 'argument', 'id');
38 $this->assertFalse($handler['specify_validation'], 'Validation for this argument has been turned off.');
39 $this->assertEqual('none', $handler['validate']['type'], 'Validation for the argument has been reverted to Basic Validation.');
43 * Saves the test_argument view with changes made to the argument handler
44 * both with and without specify_validation turned on.
46 * @param bool $specify_validation
48 protected function saveArgumentHandlerWithValidationOptions($specify_validation) {
50 'options[validate][type]' => 'entity---node',
51 'options[specify_validation]' => $specify_validation,
53 $this->drupalPostForm('admin/structure/views/nojs/handler/test_argument/default/argument/id', $options, t('Apply'));
54 $this->drupalPostForm('admin/structure/views/view/test_argument', [], t('Save'));