Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Handler / AreaResultTest.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 result area handler.
10  *
11  * @group views
12  * @see \Drupal\views\Plugin\views\area\Result
13  */
14 class AreaResultTest extends ViewsKernelTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $testViews = ['test_area_result'];
20
21   /**
22    * Tests the results area handler.
23    */
24   public function testResult() {
25     $view = Views::getView('test_area_result');
26     $view->setDisplay('default');
27     $this->executeView($view);
28     $output = $view->render();
29     $output = \Drupal::service('renderer')->renderRoot($output);
30     $this->setRawContent($output);
31     $this->assertText('start: 1 | end: 5 | total: 5 | label: test_area_result | per page: 0 | current page: 1 | current record count: 5 | page count: 1');
32   }
33
34   /**
35    * Tests the results area handler.
36    */
37   public function testResultEmpty() {
38     $view = Views::getView('test_area_result');
39
40     // Test that the area is displayed if we have checked the empty checkbox.
41     $view->setDisplay('default');
42
43     // Add a filter that will make the result set empty.
44     $view->displayHandlers->get('default')->overrideOption('filters', [
45       'name' => [
46         'id' => 'name',
47         'table' => 'views_test_data',
48         'field' => 'name',
49         'relationship' => 'none',
50         'operator' => '=',
51         'value' => 'non-existing-name',
52       ],
53     ]);
54
55     $this->executeView($view);
56     $output = $view->render();
57     $output = \Drupal::service('renderer')->renderRoot($output);
58     $this->setRawContent($output);
59     $this->assertText('start: 0 | end: 0 | total: 0 | label: test_area_result | per page: 0 | current page: 1 | current record count: 0 | page count: 1');
60     $this->assertRaw('<header>');
61
62     // Test that the area is not displayed if we have not checked the empty
63     // checkbox.
64     $view->setDisplay('page_1');
65
66     $this->executeView($view);
67     $output = $view->render();
68     $output = \Drupal::service('renderer')->renderRoot($output);
69     $this->setRawContent($output);
70     $this->assertNoText('start: 0 | end: 0 | total: 0 | label: test_area_result | per page: 0 | current page: 1 | current record count: 0 | page count: 1');
71     // Make sure the empty header region isn't rendered.
72     $this->assertNoRaw('<header>');
73   }
74
75 }