function FilterUITest::testFilterIdentifier

Same name and namespace in other branches
  1. 8.9.x core/modules/views_ui/tests/src/Functional/FilterUITest.php \Drupal\Tests\views_ui\Functional\FilterUITest::testFilterIdentifier()
  2. 10 core/modules/views_ui/tests/src/Functional/FilterUITest.php \Drupal\Tests\views_ui\Functional\FilterUITest::testFilterIdentifier()
  3. 11.x core/modules/views_ui/tests/src/Functional/FilterUITest.php \Drupal\Tests\views_ui\Functional\FilterUITest::testFilterIdentifier()

Tests the identifier settings and restrictions.

File

core/modules/views_ui/tests/src/Functional/FilterUITest.php, line 105

Class

FilterUITest
Tests for the filters from the UI.

Namespace

Drupal\Tests\views_ui\Functional

Code

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';
    // Set an empty identifier.
    $edit = [
        'options[expose][identifier]' => '',
    ];
    $this->drupalGet($path);
    $this->submitForm($edit, 'Apply');
    $this->assertSession()
        ->pageTextContains('The identifier is required if the filter is exposed.');
    // Set the identifier to 'value'.
    $edit = [
        'options[expose][identifier]' => 'value',
    ];
    $this->drupalGet($path);
    $this->submitForm($edit, 'Apply');
    $this->assertSession()
        ->pageTextContains('This identifier is not allowed.');
    // Try a few restricted values for the identifier.
    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.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.