3 namespace Drupal\Tests\views_ui\Functional;
5 use Drupal\views\Views;
8 * Tests the UI of style plugins.
11 * @see \Drupal\views_test_data\Plugin\views\style\StyleTest.
13 class StyleUITest extends UITestBase {
16 * Views used by this test.
20 public static $testViews = ['test_view'];
23 * Tests changing the style plugin and changing some options of a style.
25 public function testStyleUI() {
26 $view_name = 'test_view';
27 $view_edit_url = "admin/structure/views/view/$view_name/edit";
29 $style_plugin_url = "admin/structure/views/nojs/display/$view_name/default/style";
30 $style_options_url = "admin/structure/views/nojs/display/$view_name/default/style_options";
32 $this->drupalGet($style_plugin_url);
33 $this->assertFieldByName('style[type]', 'default', 'The default style plugin selected in the UI should be unformatted list.');
36 'style[type]' => 'test_style'
38 $this->drupalPostForm(NULL, $edit, t('Apply'));
39 $this->assertFieldByName('style_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
40 $random_name = $this->randomMachineName();
42 'style_options[test_option]' => $random_name
44 $this->drupalPostForm(NULL, $edit, t('Apply'));
45 $this->drupalGet($style_options_url);
46 $this->assertFieldByName('style_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
48 $this->drupalPostForm($view_edit_url, [], t('Save'));
49 $this->assertLink(t('Test style plugin'), 0, 'Make sure the test style plugin is shown in the UI');
51 $view = Views::getView($view_name);
53 $style = $view->display_handler->getOption('style');
54 $this->assertEqual($style['type'], 'test_style', 'Make sure that the test_style got saved as used style plugin.');
55 $this->assertEqual($style['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
57 // Test that fields are working correctly in the UI for style plugins when
58 // a field row plugin is selected.
59 $this->drupalPostForm("admin/structure/views/view/$view_name/edit", [], 'Add Page');
60 $this->drupalPostForm("admin/structure/views/nojs/display/$view_name/page_1/row", ['row[type]' => 'fields'], t('Apply'));
61 // If fields are being used this text will not be shown.
62 $this->assertNoText(t('The selected style or row format does not use fields.'));