3 namespace Drupal\Tests\views_ui\Functional;
6 * Tests for the filters from the UI.
10 class FilterUITest extends UITestBase {
14 * Views used by this test.
18 public static $testViews = ['test_filter_in_operator_ui', 'test_filter_groups'];
25 public static $modules = ['views_ui', 'node'];
30 protected function setUp($import_test_views = TRUE) {
31 parent::setUp($import_test_views);
32 $this->drupalCreateContentType(['type' => 'page']);
36 * Tests that an option for a filter is saved as expected from the UI.
38 public function testFilterInOperatorUi() {
39 $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
40 $this->drupalLogin($admin_user);
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);
47 // Select "Limit list to selected items" option and apply.
49 'options[expose][reduce]' => TRUE,
51 $this->drupalPostForm($path, $edit, t('Apply'));
53 // Verifies that the option was saved as expected.
54 $this->drupalGet($path);
55 $this->assertFieldByName('options[expose][reduce]', TRUE);
59 * Tests the filters from the UI.
61 public function testFiltersUI() {
62 $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
63 $this->drupalLogin($admin_user);
65 $this->drupalGet('admin/structure/views/view/test_filter_groups');
67 $this->assertLink('Content: ID (= 1)', 0, 'Content: ID (= 1) link appears correctly.');
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.');
73 // Create 2 new groups.
74 $this->drupalPostForm(NULL, [], t('Create new filter group'));
75 $this->drupalPostForm(NULL, [], t('Create new filter group'));
77 // Remove the new group 3.
78 $this->drupalPostForm(NULL, [], t('Remove group 3'));
80 // Verify that the group 4 is now named as 3.
81 $this->assertRaw('<span>Group 3</span>', 'Group 3 still exists.');
83 // Remove the group 3 again.
84 $this->drupalPostForm(NULL, [], t('Remove group 3'));
86 // Group 3 now does not exist.
87 $this->assertNoRaw('<span>Group 3</span>', 'Group 3 has not been added yet.');
91 * Tests the identifier settings and restrictions.
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';
98 // Set an empty identifier.
100 'options[expose][identifier]' => '',
102 $this->drupalPostForm($path, $edit, t('Apply'));
103 $this->assertText('The identifier is required if the filter is exposed.');
105 // Set the identifier to 'value'.
107 'options[expose][identifier]' => 'value',
109 $this->drupalPostForm($path, $edit, t('Apply'));
110 $this->assertText('This identifier is not allowed.');
112 // Set the identifier to a value with a restricted character.
114 'options[expose][identifier]' => 'value value',
116 $this->drupalPostForm($path, $edit, t('Apply'));
117 $this->assertText('This identifier has illegal characters.');