a113f0c4ffd6c1001f01b8658382a15cd78781ca
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Handler / AreaEmptyTest.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 generic entity area handler.
10  *
11  * @group views
12  * @see \Drupal\views\Plugin\views\area\Entity
13  */
14 class AreaEmptyTest extends ViewsKernelTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['node'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp($import_test_views = TRUE) {
25     parent::setUp();
26     $this->installEntitySchema('node');
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function viewsData() {
33     $data = parent::viewsData();
34     $data['views']['test_example'] = [
35       'title' => 'Test Example area',
36       'help' => 'A area handler which just exists for tests.',
37       'area' => [
38         'id' => 'test_example',
39       ],
40     ];
41
42     return $data;
43   }
44
45   /**
46    * Views used by this test.
47    *
48    * @var array
49    */
50   public static $testViews = ['test_example_area'];
51
52   /**
53    * Tests that the header and footer areas are not rendered if empty.
54    */
55   public function testRenderEmptyHeaderFooter() {
56     $view = Views::getView('test_example_area');
57     $view->initHandlers();
58
59     // Set example empty text.
60     $empty_text = $this->randomMachineName();
61     $empty_header = $this->randomMachineName();
62     $empty_footer = $this->randomMachineName();
63
64     // Set empty text.
65     $view->empty['test_example']->options['string'] = '<p>' . $empty_text . '</p>';
66     // Set example header text.
67     $view->header['test_example']->options['string'] = '<p>' . $empty_header . '</p>';
68     // Set example footer text.
69     $view->footer['test_example']->options['string'] = '<p>' . $empty_footer . '</p>';
70
71     // Verify that the empty header and footer sections have not been rendered.
72     $view->setDisplay('default');
73     $this->executeView($view);
74     $output = $view->render();
75     $output = \Drupal::service('renderer')->renderRoot($output);
76     $this->setRawContent($output);
77     $this->assertText($empty_text);
78     $this->assertNoText($empty_header);
79     $this->assertNoText($empty_footer);
80
81     // Enable displaying the header and footer when the View is empty.
82     $view->header['test_example']->options['empty'] = TRUE;
83     $view->footer['test_example']->options['empty'] = TRUE;
84
85     // Verify that the header and footer sections have been rendered.
86     $this->executeView($view);
87     $output = $view->render();
88     $output = \Drupal::service('renderer')->renderRoot($output);
89     $this->setRawContent($output);
90     $this->assertText($empty_header);
91     $this->assertText($empty_footer);
92   }
93
94 }