Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / FilterUITest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 /**
6  * Tests for the filters from the UI.
7  *
8  * @group views_ui
9  */
10 class FilterUITest extends UITestBase {
11
12
13   /**
14    * Views used by this test.
15    *
16    * @var array
17    */
18   public static $testViews = ['test_filter_in_operator_ui', 'test_filter_groups'];
19
20   /**
21    * Modules to enable.
22    *
23    * @var array
24    */
25   public static $modules = ['views_ui', 'node'];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp($import_test_views = TRUE) {
31     parent::setUp($import_test_views);
32     $this->drupalCreateContentType(['type' => 'page']);
33   }
34
35   /**
36    * Tests that an option for a filter is saved as expected from the UI.
37    */
38   public function testFilterInOperatorUi() {
39     $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
40     $this->drupalLogin($admin_user);
41
42     $path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type';
43     $this->drupalGet($path);
44     // Verifies that "Limit list to selected items" option is not selected.
45     $this->assertFieldByName('options[expose][reduce]', FALSE);
46
47     // Select "Limit list to selected items" option and apply.
48     $edit = [
49       'options[expose][reduce]' => TRUE,
50     ];
51     $this->drupalPostForm($path, $edit, t('Apply'));
52
53     // Verifies that the option was saved as expected.
54     $this->drupalGet($path);
55     $this->assertFieldByName('options[expose][reduce]', TRUE);
56   }
57
58   /**
59    * Tests the filters from the UI.
60    */
61   public function testFiltersUI() {
62     $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
63     $this->drupalLogin($admin_user);
64
65     $this->drupalGet('admin/structure/views/view/test_filter_groups');
66
67     $this->assertLink('Content: ID (= 1)', 0, 'Content: ID (= 1) link appears correctly.');
68
69     // Tests that we can create a new filter group from UI.
70     $this->drupalGet('admin/structure/views/nojs/rearrange-filter/test_filter_groups/page');
71     $this->assertNoRaw('<span>Group 3</span>', 'Group 3 has not been added yet.');
72
73     // Create 2 new groups.
74     $this->drupalPostForm(NULL, [], t('Create new filter group'));
75     $this->drupalPostForm(NULL, [], t('Create new filter group'));
76
77     // Remove the new group 3.
78     $this->drupalPostForm(NULL, [], t('Remove group 3'));
79
80     // Verify that the group 4 is now named as 3.
81     $this->assertRaw('<span>Group 3</span>', 'Group 3 still exists.');
82
83     // Remove the group 3 again.
84     $this->drupalPostForm(NULL, [], t('Remove group 3'));
85
86     // Group 3 now does not exist.
87     $this->assertNoRaw('<span>Group 3</span>', 'Group 3 has not been added yet.');
88   }
89
90   /**
91    * Tests the identifier settings and restrictions.
92    */
93   public function testFilterIdentifier() {
94     $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
95     $this->drupalLogin($admin_user);
96     $path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type';
97
98     // Set an empty identifier.
99     $edit = [
100       'options[expose][identifier]' => '',
101     ];
102     $this->drupalPostForm($path, $edit, t('Apply'));
103     $this->assertText('The identifier is required if the filter is exposed.');
104
105     // Set the identifier to 'value'.
106     $edit = [
107       'options[expose][identifier]' => 'value',
108     ];
109     $this->drupalPostForm($path, $edit, t('Apply'));
110     $this->assertText('This identifier is not allowed.');
111
112     // Set the identifier to a value with a restricted character.
113     $edit = [
114       'options[expose][identifier]' => 'value value',
115     ];
116     $this->drupalPostForm($path, $edit, t('Apply'));
117     $this->assertText('This identifier has illegal characters.');
118   }
119
120 }