3 namespace Drupal\Tests\views\Kernel\Plugin;
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\views\Views;
7 use Drupal\views_test_data\Plugin\views\argument_validator\ArgumentValidatorTest as ArgumentValidatorTestPlugin;
10 * Tests Views argument validators.
14 class ArgumentValidatorTest extends ViewsKernelTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_view_argument_validate_numeric', 'test_view'];
23 public function testArgumentValidateNumeric() {
24 $view = Views::getView('test_view_argument_validate_numeric');
25 $view->initHandlers();
26 $this->assertFalse($view->argument['null']->validateArgument($this->randomString()));
27 // Reset safed argument validation.
28 $view->argument['null']->argument_validated = NULL;
29 $this->assertTrue($view->argument['null']->validateArgument(12));
33 * Tests the argument validator test plugin.
35 * @see Drupal\views_test_data\Plugin\views\argument_validator\ArgumentValidatorTest
37 public function testArgumentValidatorPlugin() {
38 $view = Views::getView('test_view');
40 // Add a new argument and set the test plugin for the argument_validator.
42 'specify_validation' => TRUE,
44 'type' => 'argument_validator_test',
47 $id = $view->addHandler('default', 'argument', 'views_test_data', 'name', $options);
48 $view->initHandlers();
50 $test_value = $this->randomMachineName();
52 $argument = $view->argument[$id];
53 $argument->options['validate_options']['test_value'] = $test_value;
54 $this->assertFalse($argument->validateArgument($this->randomMachineName()), 'A random value does not validate.');
55 // Reset internal flag.
56 $argument->argument_validated = NULL;
57 $this->assertTrue($argument->validateArgument($test_value), 'The right argument validates.');
59 $plugin = $argument->getPlugin('argument_validator');
60 $this->assertTrue($plugin instanceof ArgumentValidatorTestPlugin, 'The correct argument validator plugin is used.');
61 $this->assertFalse($plugin->validateArgument($this->randomMachineName()), 'A random value does not validate.');
62 $this->assertTrue($plugin->validateArgument($test_value), 'The right argument validates.');