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