Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Handler / ArgumentNullTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel\Handler;
4
5 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
6 use Drupal\views\Views;
7
8 /**
9  * Tests the core Drupal\views\Plugin\views\argument\NullArgument handler.
10  *
11  * @group views
12  */
13 class ArgumentNullTest extends ViewsKernelTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_view'];
21
22   public function viewsData() {
23     $data = parent::viewsData();
24     $data['views_test_data']['id']['argument']['id'] = 'null';
25
26     return $data;
27   }
28
29   public function testAreaText() {
30     // Test validation
31     $view = Views::getView('test_view');
32     $view->setDisplay();
33
34     // Add a null argument.
35     $view->displayHandlers->get('default')->overrideOption('arguments', [
36       'null' => [
37         'id' => 'null',
38         'table' => 'views',
39         'field' => 'null',
40       ],
41     ]);
42
43     $this->executeView($view);
44
45     // Make sure that the argument is not validated yet.
46     unset($view->argument['null']->argument_validated);
47     $this->assertTrue($view->argument['null']->validateArgument(26));
48     // test must_not_be option.
49     unset($view->argument['null']->argument_validated);
50     $view->argument['null']->options['must_not_be'] = TRUE;
51     $this->assertFalse($view->argument['null']->validateArgument(26), 'must_not_be returns FALSE, if there is an argument');
52     unset($view->argument['null']->argument_validated);
53     $this->assertTrue($view->argument['null']->validateArgument(NULL), 'must_not_be returns TRUE, if there is no argument');
54
55     // Test execution.
56     $view->destroy();
57     $view->setDisplay();
58
59     // Add a argument, which has null as handler.
60     $view->displayHandlers->get('default')->overrideOption('arguments', [
61       'id' => [
62         'id' => 'id',
63         'table' => 'views_test_data',
64         'field' => 'id',
65       ],
66     ]);
67
68     $this->executeView($view, [26]);
69
70     // The argument should be ignored, so every result should return.
71     $this->assertEqual(5, count($view->result));
72   }
73
74 }