Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / SettingsTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 /**
6  * Tests all ui related settings under admin/structure/views/settings.
7  *
8  * @group views_ui
9  */
10 class SettingsTest extends UITestBase {
11
12   /**
13    * Stores an admin user used by the different tests.
14    *
15    * @var \Drupal\user\User
16    */
17   protected $adminUser;
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function setUp($import_test_views = TRUE) {
23     parent::setUp($import_test_views);
24     $this->drupalPlaceBlock('local_tasks_block');
25   }
26
27   /**
28    * Tests the settings for the edit ui.
29    */
30   public function testEditUI() {
31     $this->drupalLogin($this->adminUser);
32
33     // Test the settings tab exists.
34     $this->drupalGet('admin/structure/views');
35     $this->assertLinkByHref('admin/structure/views/settings');
36
37     // Test the confirmation message.
38     $this->drupalPostForm('admin/structure/views/settings', [], t('Save configuration'));
39     $this->assertText(t('The configuration options have been saved.'));
40
41     // Configure to always show the master display.
42     $edit = [
43       'ui_show_master_display' => TRUE,
44     ];
45     $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
46
47     $view = [];
48     $view['label'] = $this->randomMachineName(16);
49     $view['id'] = strtolower($this->randomMachineName(16));
50     $view['description'] = $this->randomMachineName(16);
51     $view['page[create]'] = TRUE;
52     $view['page[title]'] = $this->randomMachineName(16);
53     $view['page[path]'] = $this->randomMachineName(16);
54     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
55
56     // Configure to not always show the master display.
57     // If you have a view without a page or block the master display should be
58     // still shown.
59     $edit = [
60       'ui_show_master_display' => FALSE,
61     ];
62     $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
63
64     $view['page[create]'] = FALSE;
65     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
66
67     // Create a view with an additional display, so master should be hidden.
68     $view['page[create]'] = TRUE;
69     $view['id'] = strtolower($this->randomMachineName());
70     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
71
72     $this->assertNoLink(t('Master'));
73
74     // Configure to always show the advanced settings.
75     // @todo It doesn't seem to be a way to test this as this works just on js.
76
77     // Configure to show the embeddable display.
78     $edit = [
79       'ui_show_display_embed' => TRUE,
80     ];
81     $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
82
83     $view['id'] = strtolower($this->randomMachineName());
84     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
85     $this->assertFieldById('edit-displays-top-add-display-embed', NULL);
86
87     $edit = [
88       'ui_show_display_embed' => FALSE,
89     ];
90     $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
91
92     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
93     $this->assertNoFieldById('edit-displays-top-add-display-embed');
94
95     // Configure to hide/show the sql at the preview.
96     $edit = [
97       'ui_show_sql_query_enabled' => FALSE,
98     ];
99     $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
100
101     $view['id'] = strtolower($this->randomMachineName());
102     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
103
104     $this->drupalPostForm(NULL, [], t('Update preview'));
105     $xpath = $this->xpath('//div[@class="views-query-info"]/pre');
106     $this->assertEqual(count($xpath), 0, 'The views sql is hidden.');
107
108     $edit = [
109       'ui_show_sql_query_enabled' => TRUE,
110     ];
111     $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
112
113     $view['id'] = strtolower($this->randomMachineName());
114     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
115
116     $this->drupalPostForm(NULL, [], t('Update preview'));
117     $xpath = $this->xpath('//div[@class="views-query-info"]//pre');
118     $this->assertEqual(count($xpath), 1, 'The views sql is shown.');
119     $this->assertFalse(strpos($xpath[0]->getText(), 'db_condition_placeholder') !== FALSE, 'No placeholders are shown in the views sql.');
120     $this->assertTrue(strpos($xpath[0]->getText(), "node_field_data.status = '1'") !== FALSE, 'The placeholders in the views sql is replace by the actual value.');
121
122     // Test the advanced settings form.
123
124     // Test the confirmation message.
125     $this->drupalPostForm('admin/structure/views/settings/advanced', [], t('Save configuration'));
126     $this->assertText(t('The configuration options have been saved.'));
127
128     $edit = [
129       'skip_cache' => TRUE,
130       'sql_signature' => TRUE,
131     ];
132     $this->drupalPostForm('admin/structure/views/settings/advanced', $edit, t('Save configuration'));
133
134     $this->assertFieldChecked('edit-skip-cache', 'The skip_cache option is checked.');
135     $this->assertFieldChecked('edit-sql-signature', 'The sql_signature option is checked.');
136
137     // Test the "Clear Views' cache" button.
138     $this->drupalPostForm('admin/structure/views/settings/advanced', [], t("Clear Views' cache"));
139     $this->assertText(t('The cache has been cleared.'));
140   }
141
142 }