Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / src / Tests / FilterNumericWebTest.php
1 <?php
2
3 namespace Drupal\views_ui\Tests;
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     $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')]));
28
29     $this->drupalPostForm(NULL, [], t('Expose filter'));
30     $this->drupalPostForm(NULL, [], t('Grouped filters'));
31
32     $edit = [];
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;
43
44     $this->drupalPostForm(NULL, $edit, t('Apply'));
45
46     $this->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
47     foreach ($edit as $name => $value) {
48       $this->assertFieldByName($name, $value);
49     }
50
51     $this->drupalPostForm('admin/structure/views/view/test_view', [], t('Save'));
52     $this->assertConfigSchemaByName('views.view.test_view');
53
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');
67
68     // Change the filter to a single filter to test the schema when the operator
69     // is not exposed.
70     $this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/filter/age', [], t('Single filter'));
71     $edit = [];
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');
76
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');
90
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');
94     $edit = [];
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');
103
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');
110   }
111
112 }