Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / StyleUITest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\views\Views;
6
7 /**
8  * Tests the UI of style plugins.
9  *
10  * @group views_ui
11  * @see \Drupal\views_test_data\Plugin\views\style\StyleTest.
12  */
13 class StyleUITest extends UITestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_view'];
21
22   /**
23    * Tests changing the style plugin and changing some options of a style.
24    */
25   public function testStyleUI() {
26     $view_name = 'test_view';
27     $view_edit_url = "admin/structure/views/view/$view_name/edit";
28
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";
31
32     $this->drupalGet($style_plugin_url);
33     $this->assertFieldByName('style[type]', 'default', 'The default style plugin selected in the UI should be unformatted list.');
34
35     $edit = [
36       'style[type]' => 'test_style'
37     ];
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();
41     $edit = [
42       'style_options[test_option]' => $random_name
43     ];
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.');
47
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');
50
51     $view = Views::getView($view_name);
52     $view->initDisplay();
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.');
56
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.'));
63   }
64
65 }