5 * Contains \Drupal\php\Tests\Plugin\views\ArgumentValidatorTest.
8 namespace Drupal\php\Tests\Plugin\views;
10 use Drupal\views\Tests\ViewKernelTestBase;
11 use Drupal\views\Tests\ViewTestData;
12 use Drupal\views\Views;
15 * Tests Views PHP argument validators.
19 * @see \Drupal\php\Plugin\views\argument_validator\Php
21 class PhpArgumentValidatorTest extends ViewKernelTestBase {
24 * Views used by this test.
28 public static $testViews = ['test_view_argument_validate_php'];
35 public static $modules = ['php', 'php_views_test_config'];
40 protected function setUp($import_test_views = TRUE) {
42 if ($import_test_views) {
43 ViewTestData::createTestViews(get_class($this), array('php_views_test_config'));
48 * Tests the validateArgument question.
50 public function testArgumentValidatePhp() {
51 $string = $this->randomMachineName();
52 $view = Views::getView('test_view_argument_validate_php');
54 $view->displayHandlers->get('default')->options['arguments']['null']['validate_options']['code'] = 'return $argument == \'' . $string . '\';';
56 $view->initHandlers();
57 $this->assertTrue($view->argument['null']->validateArgument($string));
58 // Reset saved argument validation.
59 $view->argument['null']->argument_validated = NULL;
60 $this->assertFalse($view->argument['null']->validateArgument($this->randomMachineName()));