function StyleUITest::testStyleUI
Same name in other branches
- 8.9.x core/modules/views_ui/tests/src/Functional/StyleUITest.php \Drupal\Tests\views_ui\Functional\StyleUITest::testStyleUI()
- 10 core/modules/views_ui/tests/src/Functional/StyleUITest.php \Drupal\Tests\views_ui\Functional\StyleUITest::testStyleUI()
- 11.x core/modules/views_ui/tests/src/Functional/StyleUITest.php \Drupal\Tests\views_ui\Functional\StyleUITest::testStyleUI()
Tests changing the style plugin and changing some options of a style.
File
-
core/
modules/ views_ui/ tests/ src/ Functional/ StyleUITest.php, line 30
Class
- StyleUITest
- Tests the UI of style plugins.
Namespace
Drupal\Tests\views_ui\FunctionalCode
public function testStyleUI() {
$view_name = 'test_view';
$view_edit_url = "admin/structure/views/view/{$view_name}/edit";
$style_plugin_url = "admin/structure/views/nojs/display/{$view_name}/default/style";
$style_options_url = "admin/structure/views/nojs/display/{$view_name}/default/style_options";
$this->drupalGet($style_plugin_url);
$this->assertSession()
->fieldValueEquals('style[type]', 'default');
$edit = [
'style[type]' => 'test_style',
];
$this->submitForm($edit, 'Apply');
$this->assertSession()
->fieldExists('style_options[test_option]');
$random_name = $this->randomMachineName();
$edit = [
'style_options[test_option]' => $random_name,
];
$this->submitForm($edit, 'Apply');
$this->drupalGet($style_options_url);
$this->assertSession()
->fieldValueEquals('style_options[test_option]', $random_name);
$this->drupalGet($view_edit_url);
$this->submitForm([], 'Save');
$this->assertSession()
->linkExists('Test style plugin', 0, 'Make sure the test style plugin is shown in the UI');
$view = Views::getView($view_name);
$view->initDisplay();
$style = $view->display_handler
->getOption('style');
$this->assertEquals('test_style', $style['type'], 'Make sure that the test_style got saved as used style plugin.');
$this->assertEquals($random_name, $style['options']['test_option'], 'Make sure that the custom settings field got saved as expected.');
// Test that fields are working correctly in the UI for style plugins when
// a field row plugin is selected.
$this->drupalGet("admin/structure/views/view/{$view_name}/edit");
$this->submitForm([], 'Add Page');
$this->drupalGet("admin/structure/views/nojs/display/{$view_name}/page_1/row");
$this->submitForm([
'row[type]' => 'fields',
], 'Apply');
// If fields are being used this text will not be shown.
$this->assertSession()
->pageTextNotContains('The selected style or row format does not use fields.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.