Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / FilterNumericWebTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\Tests\SchemaCheckTestTrait;
6
7 /**
8  * Tests the numeric filter UI.
9  *
10  * @group views_ui
11  * @see \Drupal\views\Plugin\views\filter\NumericFilter
12  */
13 class FilterNumericWebTest extends UITestBase {
14   use SchemaCheckTestTrait;
15
16   /**
17    * Views used by this test.
18    *
19    * @var array
20    */
21   public static $testViews = ['test_view'];
22
23   /**
24    * Tests the filter numeric UI.
25    */
26   public function testFilterNumericUI() {
27     // Add a page display to the test_view to be able to test the filtering.
28     $path = 'test_view-path';
29     $this->drupalPostForm('admin/structure/views/view/test_view/edit', [], 'Add Page');
30     $this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', ['path' => $path], 'Apply');
31     $this->drupalPostForm(NULL, [], t('Save'));
32
33     $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')]));
34
35     $this->drupalPostForm(NULL, [], t('Expose filter'));
36     $this->drupalPostForm(NULL, [], t('Grouped filters'));
37
38     $edit = [];
39     $edit['options[group_info][group_items][1][title]'] = 'Old';
40     $edit['options[group_info][group_items][1][operator]'] = '>';
41     $edit['options[group_info][group_items][1][value][value]'] = 27;
42     $edit['options[group_info][group_items][2][title]'] = 'Young';
43     $edit['options[group_info][group_items][2][operator]'] = '<=';
44     $edit['options[group_info][group_items][2][value][value]'] = 27;
45     $edit['options[group_info][group_items][3][title]'] = 'From 26 to 28';
46     $edit['options[group_info][group_items][3][operator]'] = 'between';
47     $edit['options[group_info][group_items][3][value][min]'] = 26;
48     $edit['options[group_info][group_items][3][value][max]'] = 28;
49
50     $this->drupalPostForm(NULL, $edit, t('Apply'));
51
52     $this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
53     foreach ($edit as $name => $value) {
54       $this->assertFieldByName($name, $value);
55     }
56
57     $this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
58     $this->assertConfigSchemaByName('views.view.test_view');
59
60     // Test that the exposed filter works as expected.
61     $this->drupalGet('test_view-path');
62     $this->assertText('John');
63     $this->assertText('Paul');
64     $this->assertText('Ringo');
65     $this->assertText('George');
66     $this->assertText('Meredith');
67     $this->drupalPostForm(NULL, ['age' => '2'], 'Apply');
68     $this->assertText('John');
69     $this->assertText('Paul');
70     $this->assertNoText('Ringo');
71     $this->assertText('George');
72     $this->assertNoText('Meredith');
73
74     // Change the filter to a single filter to test the schema when the operator
75     // is not exposed.
76     $this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/filter/age', [], t('Single filter'));
77     $edit = [];
78     $edit['options[value][value]'] = 25;
79     $this->drupalPostForm(NULL, $edit, t('Apply'));
80     $this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
81     $this->assertConfigSchemaByName('views.view.test_view');
82
83     // Test that the filter works as expected.
84     $this->drupalGet('test_view-path');
85     $this->assertText('John');
86     $this->assertNoText('Paul');
87     $this->assertNoText('Ringo');
88     $this->assertNoText('George');
89     $this->assertNoText('Meredith');
90     $this->drupalPostForm(NULL, ['age' => '26'], t('Apply'));
91     $this->assertNoText('John');
92     $this->assertText('Paul');
93     $this->assertNoText('Ringo');
94     $this->assertNoText('George');
95     $this->assertNoText('Meredith');
96
97     // Change the filter to a 'between' filter to test if the label and
98     // description are set for the 'minimum' filter element.
99     $this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
100     $edit = [];
101     $edit['options[expose][label]'] = 'Age between';
102     $edit['options[expose][description]'] = 'Description of the exposed filter';
103     $edit['options[operator]'] = 'between';
104     $edit['options[value][min]'] = 26;
105     $edit['options[value][max]'] = 28;
106     $this->drupalPostForm(NULL, $edit, t('Apply'));
107     $this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
108     $this->assertConfigSchemaByName('views.view.test_view');
109
110     $this->drupalPostForm(NULL, [], t('Update preview'));
111     // Check the max field label.
112     $this->assertRaw('<label for="edit-age-max">And</label>', 'Max field label found');
113     $this->assertRaw('<label for="edit-age-min">Age between</label>', 'Min field label found');
114     // Check that the description is shown in the right place.
115     $this->assertEqual(trim($this->cssSelect('.form-item-age-min .description')[0]->getText()), 'Description of the exposed filter');
116   }
117
118 }