View source
<?php
namespace Drupal\Tests\views_ui\Functional;
class SettingsTest extends UITestBase {
protected $adminUser;
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->drupalPlaceBlock('local_tasks_block');
}
public function testEditUI() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/structure/views');
$this
->assertLinkByHref('admin/structure/views/settings');
$this
->drupalPostForm('admin/structure/views/settings', [], t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
$edit = [
'ui_show_master_display' => TRUE,
];
$this
->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
$view = [];
$view['label'] = $this
->randomMachineName(16);
$view['id'] = strtolower($this
->randomMachineName(16));
$view['description'] = $this
->randomMachineName(16);
$view['page[create]'] = TRUE;
$view['page[title]'] = $this
->randomMachineName(16);
$view['page[path]'] = $this
->randomMachineName(16);
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$edit = [
'ui_show_master_display' => FALSE,
];
$this
->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
$view['page[create]'] = FALSE;
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$view['page[create]'] = TRUE;
$view['id'] = strtolower($this
->randomMachineName());
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->assertSession()
->linkNotExists(t('Master'));
$edit = [
'ui_show_display_embed' => TRUE,
];
$this
->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
$view['id'] = strtolower($this
->randomMachineName());
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->assertFieldById('edit-displays-top-add-display-embed', NULL);
$edit = [
'ui_show_display_embed' => FALSE,
];
$this
->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->assertNoFieldById('edit-displays-top-add-display-embed');
$edit = [
'ui_show_sql_query_enabled' => FALSE,
];
$this
->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
$view['id'] = strtolower($this
->randomMachineName());
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->drupalPostForm(NULL, [], t('Update preview'));
$xpath = $this
->xpath('//div[@class="views-query-info"]/pre');
$this
->assertCount(0, $xpath, 'The views sql is hidden.');
$edit = [
'ui_show_sql_query_enabled' => TRUE,
];
$this
->drupalPostForm('admin/structure/views/settings', $edit, t('Save configuration'));
$view['id'] = strtolower($this
->randomMachineName());
$this
->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
$this
->drupalPostForm(NULL, [], t('Update preview'));
$xpath = $this
->xpath('//div[@class="views-query-info"]//pre');
$this
->assertCount(1, $xpath, 'The views sql is shown.');
$this
->assertStringNotContainsString('db_condition_placeholder', $xpath[0]
->getText(), 'No placeholders are shown in the views sql.');
$this
->assertStringContainsString("node_field_data.status = '1'", $xpath[0]
->getText(), 'The placeholders in the views sql is replace by the actual value.');
$this
->drupalPostForm('admin/structure/views/settings/advanced', [], t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
$edit = [
'skip_cache' => TRUE,
'sql_signature' => TRUE,
];
$this
->drupalPostForm('admin/structure/views/settings/advanced', $edit, t('Save configuration'));
$this
->assertFieldChecked('edit-skip-cache', 'The skip_cache option is checked.');
$this
->assertFieldChecked('edit-sql-signature', 'The sql_signature option is checked.');
$this
->drupalPostForm('admin/structure/views/settings/advanced', [], t("Clear Views' cache"));
$this
->assertText(t('The cache has been cleared.'));
}
}