View source
<?php
namespace Drupal\Tests\views_ui\Functional;
use Drupal\Tests\SchemaCheckTestTrait;
class FilterNumericWebTest extends UITestBase {
use SchemaCheckTestTrait;
public static $testViews = [
'test_view',
];
protected $defaultTheme = 'stark';
public function testFilterNumericUI() {
$path = 'test_view-path';
$this
->drupalGet('admin/structure/views/view/test_view/edit');
$this
->submitForm([], 'Add Page');
$this
->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
$this
->submitForm([
'path' => $path,
], 'Apply');
$this
->submitForm([], 'Save');
$this
->drupalGet('admin/structure/views/nojs/add-handler/test_view/default/filter');
$this
->submitForm([
'name[views_test_data.age]' => TRUE,
], 'Add and configure filter criteria');
$this
->submitForm([], 'Expose filter');
$this
->submitForm([], 'Grouped filters');
$edit = [];
$edit['options[group_info][group_items][1][title]'] = 'Old';
$edit['options[group_info][group_items][1][operator]'] = '>';
$edit['options[group_info][group_items][1][value][value]'] = 27;
$edit['options[group_info][group_items][2][title]'] = 'Young';
$edit['options[group_info][group_items][2][operator]'] = '<=';
$edit['options[group_info][group_items][2][value][value]'] = 27;
$edit['options[group_info][group_items][3][title]'] = 'From 26 to 28';
$edit['options[group_info][group_items][3][operator]'] = 'between';
$edit['options[group_info][group_items][3][value][min]'] = 26;
$edit['options[group_info][group_items][3][value][max]'] = 28;
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
foreach ($edit as $name => $value) {
$this
->assertSession()
->fieldValueEquals($name, $value);
}
$this
->drupalGet('admin/structure/views/view/test_view');
$this
->submitForm([], 'Save');
$this
->assertConfigSchemaByName('views.view.test_view');
$this
->drupalGet('test_view-path');
$this
->assertSession()
->pageTextContains('John');
$this
->assertSession()
->pageTextContains('Paul');
$this
->assertSession()
->pageTextContains('Ringo');
$this
->assertSession()
->pageTextContains('George');
$this
->assertSession()
->pageTextContains('Meredith');
$this
->submitForm([
'age' => '2',
], 'Apply');
$this
->assertSession()
->pageTextContains('John');
$this
->assertSession()
->pageTextContains('Paul');
$this
->assertSession()
->pageTextNotContains('Ringo');
$this
->assertSession()
->pageTextContains('George');
$this
->assertSession()
->pageTextNotContains('Meredith');
$this
->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
$this
->submitForm([], 'Single filter');
$edit = [];
$edit['options[value][value]'] = 25;
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/view/test_view');
$this
->submitForm([], 'Save');
$this
->assertConfigSchemaByName('views.view.test_view');
$this
->drupalGet('test_view-path');
$this
->assertSession()
->pageTextContains('John');
$this
->assertSession()
->pageTextNotContains('Paul');
$this
->assertSession()
->pageTextNotContains('Ringo');
$this
->assertSession()
->pageTextNotContains('George');
$this
->assertSession()
->pageTextNotContains('Meredith');
$this
->submitForm([
'age' => '26',
], 'Apply');
$this
->assertSession()
->pageTextNotContains('John');
$this
->assertSession()
->pageTextContains('Paul');
$this
->assertSession()
->pageTextNotContains('Ringo');
$this
->assertSession()
->pageTextNotContains('George');
$this
->assertSession()
->pageTextNotContains('Meredith');
$this
->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
$edit = [];
$edit['options[expose][label]'] = 'Age between';
$edit['options[expose][description]'] = 'Description of the exposed filter';
$edit['options[operator]'] = 'between';
$edit['options[value][min]'] = 26;
$edit['options[value][max]'] = 28;
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/view/test_view');
$this
->submitForm([], 'Save');
$this
->assertConfigSchemaByName('views.view.test_view');
$this
->submitForm([], 'Update preview');
$this
->assertSession()
->elementTextContains('css', 'fieldset#edit-age-wrapper legend', 'Age between');
$this
->assertSession()
->elementsCount('xpath', '//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-min") and contains(text(), "Min")]', 1);
$this
->assertSession()
->elementsCount('xpath', '//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-max") and contains(text(), "Max")]', 1);
$this
->assertEquals('Description of the exposed filter', trim($this
->cssSelect('#edit-age-wrapper--description')[0]
->getText()));
$this
->drupalGet('admin/structure/views/nojs/handler/test_view/default/filter/age');
$edit = [];
$edit['options[expose][label]'] = 'Age greater than';
$edit['options[expose][description]'] = 'Description of the exposed filter';
$edit['options[operator]'] = '>';
$edit['options[value][value]'] = 1000;
$this
->submitForm($edit, 'Apply');
$this
->drupalGet('admin/structure/views/view/test_view');
$this
->submitForm([], 'Save');
$this
->assertConfigSchemaByName('views.view.test_view');
$this
->submitForm([], 'Update preview');
$this
->assertSession()
->elementsCount('xpath', '//label[contains(@for, "edit-age") and contains(text(), "Age greater than")]', 1);
$fieldset = $this
->xpath('//fieldset[contains(@id, "edit-age-wrapper")]');
$this
->assertEmpty($fieldset);
}
}