3 namespace Drupal\Tests\views_ui\Functional;
6 * Tests all ui related settings under admin/structure/views/settings.
10 class SettingsTest extends UITestBase {
13 * Stores an admin user used by the different tests.
15 * @var \Drupal\user\User
22 protected function setUp($import_test_views = TRUE) {
23 parent::setUp($import_test_views);
24 $this->drupalPlaceBlock('local_tasks_block');
28 * Tests the settings for the edit ui.
30 public function testEditUI() {
31 $this->drupalLogin($this->adminUser);
33 // Test the settings tab exists.
34 $this->drupalGet('admin/structure/views');
35 $this->assertLinkByHref('admin/structure/views/settings');
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.'));
41 // Configure to always show the master display.
43 'ui_show_master_display' => TRUE,
45 $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
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'));
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
60 'ui_show_master_display' => FALSE,
62 $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
64 $view['page[create]'] = FALSE;
65 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
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'));
72 $this->assertNoLink(t('Master'));
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.
77 // Configure to show the embeddable display.
79 'ui_show_display_embed' => TRUE,
81 $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
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);
88 'ui_show_display_embed' => FALSE,
90 $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
92 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
93 $this->assertNoFieldById('edit-displays-top-add-display-embed');
95 // Configure to hide/show the sql at the preview.
97 'ui_show_sql_query_enabled' => FALSE,
99 $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
101 $view['id'] = strtolower($this->randomMachineName());
102 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
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.');
109 'ui_show_sql_query_enabled' => TRUE,
111 $this->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
113 $view['id'] = strtolower($this->randomMachineName());
114 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
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.');
122 // Test the advanced settings form.
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.'));
129 'skip_cache' => TRUE,
130 'sql_signature' => TRUE,
132 $this->drupalPostForm('admin/structure/views/settings/advanced', $edit, t('Save configuration'));
134 $this->assertFieldChecked('edit-skip-cache', 'The skip_cache option is checked.');
135 $this->assertFieldChecked('edit-sql-signature', 'The sql_signature option is checked.');
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.'));