You are here

public function FilterUITest::testFilterIdentifier in Drupal 8

Same name and namespace in other branches
  1. 9 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 104

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
    ->drupalPostForm($path, $edit, t('Apply'));
  $this
    ->assertText('The identifier is required if the filter is exposed.');

  // Set the identifier to 'value'.
  $edit = [
    'options[expose][identifier]' => 'value',
  ];
  $this
    ->drupalPostForm($path, $edit, t('Apply'));
  $this
    ->assertText('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
      ->drupalPostForm($path, $edit, t('Apply'));
    $this
      ->assertText('This identifier has illegal characters.');
  }
}