Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / OverrideDisplaysTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 /**
6  * Tests that displays can be correctly overridden via the user interface.
7  *
8  * @group views_ui
9  */
10 class OverrideDisplaysTest extends UITestBase {
11
12   protected function setUp($import_test_views = TRUE) {
13     parent::setUp($import_test_views);
14
15     $this->drupalPlaceBlock('page_title_block');
16   }
17
18   /**
19    * Tests that displays can be overridden via the UI.
20    */
21   public function testOverrideDisplays() {
22     // Create a basic view that shows all content, with a page and a block
23     // display.
24     $view['label'] = $this->randomMachineName(16);
25     $view['id'] = strtolower($this->randomMachineName(16));
26     $view['page[create]'] = 1;
27     $view['page[path]'] = $this->randomMachineName(16);
28     $view['block[create]'] = 1;
29     $view_path = $view['page[path]'];
30     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
31
32     // Configure its title. Since the page and block both started off with the
33     // same (empty) title in the views wizard, we expect the wizard to have set
34     // things up so that they both inherit from the default display, and we
35     // therefore only need to change that to have it take effect for both.
36     $edit = [];
37     $edit['title'] = $original_title = $this->randomMachineName(16);
38     $edit['override[dropdown]'] = 'default';
39     $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
40     $this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/page_1", [], t('Save'));
41
42     // Add a node that will appear in the view, so that the block will actually
43     // be displayed.
44     $this->drupalCreateContentType(['type' => 'page']);
45     $this->drupalCreateNode();
46
47     // Make sure the title appears in the page.
48     $this->drupalGet($view_path);
49     $this->assertResponse(200);
50     $this->assertText($original_title);
51
52     // Confirm that the view block is available in the block administration UI.
53     $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default'));
54     $this->clickLink('Place block');
55     $this->assertText($view['label']);
56
57     // Place the block.
58     $this->drupalPlaceBlock("views_block:{$view['id']}-block_1");
59
60     // Make sure the title appears in the block.
61     $this->drupalGet('');
62     $this->assertText($original_title);
63
64     // Change the title for the page display only, and make sure that the
65     // original title still appears on the page.
66     $edit = [];
67     $edit['title'] = $new_title = $this->randomMachineName(16);
68     $edit['override[dropdown]'] = 'page_1';
69     $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
70     $this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/page_1", [], t('Save'));
71     $this->drupalGet($view_path);
72     $this->assertResponse(200);
73     $this->assertText($new_title);
74     $this->assertText($original_title);
75   }
76
77   /**
78    * Tests that the wizard correctly sets up default and overridden displays.
79    */
80   public function testWizardMixedDefaultOverriddenDisplays() {
81     // Create a basic view with a page, block, and feed. Give the page and feed
82     // identical titles, but give the block a different one, so we expect the
83     // page and feed to inherit their titles from the default display, but the
84     // block to override it.
85     $view['label'] = $this->randomMachineName(16);
86     $view['id'] = strtolower($this->randomMachineName(16));
87     $view['page[create]'] = 1;
88     $view['page[title]'] = $this->randomMachineName(16);
89     $view['page[path]'] = $this->randomMachineName(16);
90     $view['page[feed]'] = 1;
91     $view['page[feed_properties][path]'] = $this->randomMachineName(16);
92     $view['block[create]'] = 1;
93     $view['block[title]'] = $this->randomMachineName(16);
94     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
95
96     // Add a node that will appear in the view, so that the block will actually
97     // be displayed.
98     $this->drupalCreateContentType(['type' => 'page']);
99     $this->drupalCreateNode();
100
101     // Make sure that the feed, page and block all start off with the correct
102     // titles.
103     $this->drupalGet($view['page[path]']);
104     $this->assertResponse(200);
105     $this->assertText($view['page[title]']);
106     $this->assertNoText($view['block[title]']);
107     $this->drupalGet($view['page[feed_properties][path]']);
108     $this->assertResponse(200);
109     $this->assertText($view['page[title]']);
110     $this->assertNoText($view['block[title]']);
111
112     // Confirm that the block is available in the block administration UI.
113     $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')->get('default'));
114     $this->clickLink('Place block');
115     $this->assertText($view['label']);
116
117     // Put the block into the first sidebar region, and make sure it will not
118     // display on the view's page display (since we will be searching for the
119     // presence/absence of the view's title in both the page and the block).
120     $this->drupalPlaceBlock("views_block:{$view['id']}-block_1", [
121       'visibility' => [
122         'request_path' => [
123           'pages' => '/' . $view['page[path]'],
124           'negate' => TRUE,
125         ],
126       ],
127     ]);
128
129     $this->drupalGet('');
130     $this->assertText($view['block[title]']);
131     $this->assertNoText($view['page[title]']);
132
133     // Edit the page and change the title. This should automatically change
134     // the feed's title also, but not the block.
135     $edit = [];
136     $edit['title'] = $new_default_title = $this->randomMachineName(16);
137     $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/page_1/title", $edit, t('Apply'));
138     $this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/page_1", [], t('Save'));
139     $this->drupalGet($view['page[path]']);
140     $this->assertResponse(200);
141     $this->assertText($new_default_title);
142     $this->assertNoText($view['page[title]']);
143     $this->assertNoText($view['block[title]']);
144     $this->drupalGet($view['page[feed_properties][path]']);
145     $this->assertResponse(200);
146     $this->assertText($new_default_title);
147     $this->assertNoText($view['page[title]']);
148     $this->assertNoText($view['block[title]']);
149     $this->drupalGet('');
150     $this->assertNoText($new_default_title);
151     $this->assertNoText($view['page[title]']);
152     $this->assertText($view['block[title]']);
153
154     // Edit the block and change the title. This should automatically change
155     // the block title only, and leave the defaults alone.
156     $edit = [];
157     $edit['title'] = $new_block_title = $this->randomMachineName(16);
158     $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/block_1/title", $edit, t('Apply'));
159     $this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/block_1", [], t('Save'));
160     $this->drupalGet($view['page[path]']);
161     $this->assertResponse(200);
162     $this->assertText($new_default_title);
163     $this->drupalGet($view['page[feed_properties][path]']);
164     $this->assertResponse(200);
165     $this->assertText($new_default_title);
166     $this->assertNoText($new_block_title);
167     $this->drupalGet('');
168     $this->assertText($new_block_title);
169     $this->assertNoText($view['block[title]']);
170   }
171
172   /**
173    * Tests that the revert to all displays select-option works as expected.
174    */
175   public function testRevertAllDisplays() {
176     // Create a basic view with a page, block.
177     // Because there is both a title on page and block we expect the title on
178     // the block be overridden.
179     $view['label'] = $this->randomMachineName(16);
180     $view['id'] = strtolower($this->randomMachineName(16));
181     $view['page[create]'] = 1;
182     $view['page[title]'] = $this->randomMachineName(16);
183     $view['page[path]'] = $this->randomMachineName(16);
184     $view['block[create]'] = 1;
185     $view['block[title]'] = $this->randomMachineName(16);
186     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
187
188     // Revert the title of the block to the default ones, but submit some new
189     // values to be sure that the new value is not stored.
190     $edit = [];
191     $edit['title'] = $new_block_title = $this->randomMachineName();
192     $edit['override[dropdown]'] = 'default_revert';
193
194     $this->drupalPostForm("admin/structure/views/nojs/display/{$view['id']}/block_1/title", $edit, t('Apply'));
195     $this->drupalPostForm("admin/structure/views/view/{$view['id']}/edit/block_1", [], t('Save'));
196     $this->assertText($view['page[title]']);
197   }
198
199 }