Version 1
[yaffs-website] / web / core / modules / views / tests / src / Functional / Handler / AreaTitleWebTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Handler;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Entity\View;
7
8 /**
9  * Tests the title area handler with a web test.
10  *
11  * @group views
12  * @see \Drupal\views\Plugin\views\area\Title
13  */
14 class AreaTitleWebTest extends ViewTestBase {
15
16   /**
17    * Views used by this test.
18    *
19    * @var array
20    */
21   public static $testViews = ['test_area_title'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp($import_test_views = TRUE) {
27     parent::setUp($import_test_views);
28
29     $this->enableViewsTestModule();
30   }
31
32   /**
33    * Tests the title area handler.
34    */
35   public function testTitleText() {
36     // Confirm that the view has the normal title before making the view return
37     // no result.
38     $this->drupalGet('test-area-title');
39     $this->assertTitle('test_title_header | Drupal');
40
41     // Change the view to return no result.
42     /** @var \Drupal\views\Entity\View $view */
43     $view = View::load('test_area_title');
44     $display =& $view->getDisplay('default');
45     $display['display_options']['filters']['name'] = [
46       'field' => 'name',
47       'id' => 'name',
48       'table' => 'views_test_data',
49       'relationship' => 'none',
50       'plugin_id' => 'string',
51       // Add a value which does not exist. The dataset is defined in
52       // \Drupal\views\Tests\ViewTestData::dataSet().
53       'value' => 'Euler',
54     ];
55     $view->save();
56
57     $this->drupalGet('test-area-title');
58     $this->assertTitle('test_title_empty | Drupal');
59
60     // Change the view to return a result instead.
61     /** @var \Drupal\views\Entity\View $view */
62     $view = View::load('test_area_title');
63     $display =& $view->getDisplay('default');
64     $display['display_options']['filters']['name'] = [
65       'field' => 'name',
66       'id' => 'name',
67       'table' => 'views_test_data',
68       'relationship' => 'none',
69       'plugin_id' => 'string',
70       // Change to a value which does exist. The dataset is defined in
71       // \Drupal\views\Tests\ViewTestData::dataSet().
72       'value' => 'Ringo',
73     ];
74     $view->save();
75
76     $this->drupalGet('test-area-title');
77     $this->assertTitle('test_title_header | Drupal');
78   }
79
80 }