View source
<?php
namespace Drupal\Tests\views_ui\Functional;
class FilterUITest extends UITestBase {
public static $testViews = [
'test_filter_in_operator_ui',
'test_filter_groups',
];
protected static $modules = [
'views_ui',
'node',
];
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->drupalCreateContentType([
'type' => 'page',
]);
}
public function testFilterInOperatorUi() {
$admin_user = $this
->drupalCreateUser([
'administer views',
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
$path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type';
$this
->drupalGet($path);
$this
->assertSession()
->fieldValueEquals('options[expose][reduce]', FALSE);
$edit = [
'options[expose][reduce]' => TRUE,
];
$this
->drupalGet($path);
$this
->submitForm($edit, 'Apply');
$this
->drupalGet($path);
$this
->assertSession()
->fieldValueEquals('options[expose][reduce]', TRUE);
}
public function testFiltersUI() {
$admin_user = $this
->drupalCreateUser([
'administer views',
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/structure/views/view/test_filter_groups');
$this
->assertSession()
->linkExists('Content: ID (= 1)', 0, 'Content: ID (= 1) link appears correctly.');
$this
->drupalGet('admin/structure/views/nojs/rearrange-filter/test_filter_groups/page');
$this
->assertSession()
->elementNotExists('xpath', '//span[text()="Group 3"]');
$this
->submitForm([], 'Create new filter group');
$this
->submitForm([], 'Create new filter group');
$this
->submitForm([], 'Remove group 3');
$this
->assertSession()
->responseContains('<span>Group 3</span>');
$this
->submitForm([], 'Remove group 3');
$this
->assertSession()
->elementNotExists('xpath', '//span[text()="Group 3"]');
}
public function testFilterIdentifier() {
$admin_user = $this
->drupalCreateUser([
'administer views',
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
$path = 'admin/structure/views/nojs/handler/test_filter_in_operator_ui/default/filter/type';
$edit = [
'options[expose][identifier]' => '',
];
$this
->drupalGet($path);
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->pageTextContains('The identifier is required if the filter is exposed.');
$edit = [
'options[expose][identifier]' => 'value',
];
$this
->drupalGet($path);
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->pageTextContains('This identifier is not allowed.');
foreach ([
'value value',
'value^value',
] as $identifier) {
$edit = [
'options[expose][identifier]' => $identifier,
];
$this
->drupalGet($path);
$this
->submitForm($edit, 'Apply');
$this
->assertSession()
->pageTextContains('This identifier has illegal characters.');
}
}
}