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