00b1c8f0fc0ecc41ee92676f870b77645b336b24
[yaffs-website] / web / modules / contrib / php / src / Tests / Plugin / views / PhpArgumentValidatorTest.php
1 <?php
2
3 namespace Drupal\php\Tests\Plugin\views;
4
5 use Drupal\views\Tests\ViewKernelTestBase;
6 use Drupal\views\Tests\ViewTestData;
7 use Drupal\views\Views;
8
9 /**
10  * Tests Views PHP argument validators.
11  *
12  * @group PHP
13  *
14  * @see \Drupal\php\Plugin\views\argument_validator\Php
15  */
16 class PhpArgumentValidatorTest extends ViewKernelTestBase {
17
18   /**
19    * Views used by this test.
20    *
21    * @var array
22    */
23   public static $testViews = ['test_view_argument_validate_php'];
24
25   /**
26    * Modules to enable.
27    *
28    * @var array
29    */
30   public static $modules = ['filter', 'php', 'php_views_test_config'];
31
32   /**
33    * {@inheritdoc}
34    */
35   protected function setUp($import_test_views = TRUE) {
36     parent::setUp();
37     if ($import_test_views) {
38       ViewTestData::createTestViews(get_class($this), ['php_views_test_config']);
39     }
40   }
41
42   /**
43    * Tests the validateArgument question.
44    */
45   public function testArgumentValidatePhp() {
46     $string = $this->randomMachineName();
47     $view = Views::getView('test_view_argument_validate_php');
48     $view->setDisplay();
49     $view->displayHandlers->get('default')->options['arguments']['null']['validate_options']['code'] = 'return $argument == \'' . $string . '\';';
50
51     $view->initHandlers();
52     $this->assertTrue($view->argument['null']->validateArgument($string));
53     // Reset saved argument validation.
54     $view->argument['null']->argument_validated = NULL;
55     $this->assertFalse($view->argument['null']->validateArgument($this->randomMachineName()));
56   }
57
58 }