3 namespace Drupal\views_ui\Tests;
5 use Drupal\Tests\SchemaCheckTestTrait;
8 * Tests the numeric filter UI.
11 * @see \Drupal\views\Plugin\views\filter\NumericFilter
13 class FilterNumericWebTest extends UITestBase {
14 use SchemaCheckTestTrait;
17 * Views used by this test.
21 public static $testViews = ['test_view'];
24 * Tests the filter numeric UI.
26 public function testFilterNumericUI() {
27 $this->drupalPostForm('admin/structure/views/nojs/add-handler/test_view/default/filter', ['name[views_test_data.age]' => TRUE], t('Add and configure @handler', ['@handler' => t('filter criteria')]));
29 $this->drupalPostForm(NULL, [], t('Expose filter'));
30 $this->drupalPostForm(NULL, [], t('Grouped filters'));
33 $edit['options[group_info][group_items][1][title]'] = 'Old';
34 $edit['options[group_info][group_items][1][operator]'] = '>';
35 $edit['options[group_info][group_items][1][value][value]'] = 27;
36 $edit['options[group_info][group_items][2][title]'] = 'Young';
37 $edit['options[group_info][group_items][2][operator]'] = '<=';
38 $edit['options[group_info][group_items][2][value][value]'] = 27;
39 $edit['options[group_info][group_items][3][title]'] = 'From 26 to 28';
40 $edit['options[group_info][group_items][3][operator]'] = 'between';
41 $edit['options[group_info][group_items][3][value][min]'] = 26;
42 $edit['options[group_info][group_items][3][value][max]'] = 28;
44 $this->drupalPostForm(NULL, $edit, t('Apply'));
46 $this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
47 foreach ($edit as $name => $value) {
48 $this->assertFieldByName($name, $value);
51 $this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
52 $this->assertConfigSchemaByName('views.view.test_view');
54 // Test that the exposed filter works as expected.
55 $this->drupalPostForm(NULL, [], t('Update preview'));
56 $this->assertText('John');
57 $this->assertText('Paul');
58 $this->assertText('Ringo');
59 $this->assertText('George');
60 $this->assertText('Meredith');
61 $this->drupalPostForm(NULL, ['age' => '2'], t('Update preview'));
62 $this->assertText('John');
63 $this->assertText('Paul');
64 $this->assertNoText('Ringo');
65 $this->assertText('George');
66 $this->assertNoText('Meredith');
68 // Change the filter to a single filter to test the schema when the operator
70 $this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/filter/age', [], t('Single filter'));
72 $edit['options[value][value]'] = 25;
73 $this->drupalPostForm(NULL, $edit, t('Apply'));
74 $this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
75 $this->assertConfigSchemaByName('views.view.test_view');
77 // Test that the filter works as expected.
78 $this->drupalPostForm(NULL, [], t('Update preview'));
79 $this->assertText('John');
80 $this->assertNoText('Paul');
81 $this->assertNoText('Ringo');
82 $this->assertNoText('George');
83 $this->assertNoText('Meredith');
84 $this->drupalPostForm(NULL, ['age' => '26'], t('Update preview'));
85 $this->assertNoText('John');
86 $this->assertText('Paul');
87 $this->assertNoText('Ringo');
88 $this->assertNoText('George');
89 $this->assertNoText('Meredith');
91 // Change the filter to a 'between' filter to test if the label and
92 // description are set for the 'minimum' filter element.
93 $this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
95 $edit['options[expose][label]'] = 'Age between';
96 $edit['options[expose][description]'] = 'Description of the exposed filter';
97 $edit['options[operator]'] = 'between';
98 $edit['options[value][min]'] = 26;
99 $edit['options[value][max]'] = 28;
100 $this->drupalPostForm(NULL, $edit, t('Apply'));
101 $this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
102 $this->assertConfigSchemaByName('views.view.test_view');
104 $this->drupalPostForm(NULL, [], t('Update preview'));
105 // Check the max field label.
106 $this->assertRaw('<label for="edit-age-max">And</label>', 'Max field label found');
107 $this->assertRaw('<label for="edit-age-min">Age between</label>', 'Min field label found');
108 // Check that the description is shown in the right place.
109 $this->assertEqual(trim($this->cssSelect('.form-item-age-min .description')[0]), 'Description of the exposed filter');