3 namespace Drupal\views_ui\Tests;
5 use Drupal\views\Tests\ViewTestBase;
8 * Tests for the filters from the UI.
12 class FilterUITest extends ViewTestBase {
16 * Views used by this test.
20 public static $testViews = ['test_filter_in_operator_ui', 'test_filter_groups'];
27 public static $modules = ['views_ui', 'node'];
32 protected function setUp() {
34 $this->drupalCreateContentType(['type' => 'page']);
35 $this->enableViewsTestModule();
39 * Tests that an option for a filter is saved as expected from the UI.
41 public function testFilterInOperatorUi() {
42 $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
43 $this->drupalLogin($admin_user);
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);
50 // Select "Limit list to selected items" option and apply.
52 'options[expose][reduce]' => TRUE,
54 $this->drupalPostForm($path, $edit, t('Apply'));
56 // Verifies that the option was saved as expected.
57 $this->drupalGet($path);
58 $this->assertFieldByName('options[expose][reduce]', TRUE);
62 * Tests the filters from the UI.
64 public function testFiltersUI() {
65 $admin_user = $this->drupalCreateUser(['administer views', 'administer site configuration']);
66 $this->drupalLogin($admin_user);
68 $this->drupalGet('admin/structure/views/view/test_filter_groups');
70 $this->assertLink('Content: ID (= 1)', 0, 'Content: ID (= 1) link appears correctly.');
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.');
76 // Create 2 new groups.
77 $this->drupalPostForm(NULL, [], t('Create new filter group'));
78 $this->drupalPostForm(NULL, [], t('Create new filter group'));
80 // Remove the new group 3.
81 $this->drupalPostForm(NULL, [], t('Remove group 3'));
83 // Verify that the group 4 is now named as 3.
84 $this->assertRaw('<span>Group 3</span>', 'Group 3 still exists.');
86 // Remove the group 3 again.
87 $this->drupalPostForm(NULL, [], t('Remove group 3'));
89 // Group 3 now does not exist.
90 $this->assertNoRaw('<span>Group 3</span>', 'Group 3 has not been added yet.');
94 * Tests the identifier settings and restrictions.
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';
101 // Set an empty identifier.
103 'options[expose][identifier]' => '',
105 $this->drupalPostForm($path, $edit, t('Apply'));
106 $this->assertText('The identifier is required if the filter is exposed.');
108 // Set the identifier to 'value'.
110 'options[expose][identifier]' => 'value',
112 $this->drupalPostForm($path, $edit, t('Apply'));
113 $this->assertText('This identifier is not allowed.');
115 // Set the identifier to a value with a restricted character.
117 'options[expose][identifier]' => 'value value',
119 $this->drupalPostForm($path, $edit, t('Apply'));
120 $this->assertText('This identifier has illegal characters.');