function ExposedFormTest::testExposedIdentifier

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testExposedIdentifier()
  2. 10 core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testExposedIdentifier()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testExposedIdentifier()

Tests the exposed form with a non-standard identifier.

File

core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php, line 106

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testExposedIdentifier() {
    // Alter the identifier of the filter to a random string.
    $view = Views::getView('test_exposed_form_buttons');
    $view->setDisplay();
    $identifier = 'new_identifier';
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'type' => [
            'exposed' => TRUE,
            'field' => 'type',
            'id' => 'type',
            'table' => 'node_field_data',
            'plugin_id' => 'in_operator',
            'entity_type' => 'node',
            'entity_field' => 'type',
            'expose' => [
                'identifier' => $identifier,
                'label' => 'Content: Type',
                'operator_id' => 'type_op',
                'reduce' => FALSE,
                'description' => 'Exposed overridden description',
            ],
        ],
    ]);
    $view->save();
    $this->drupalGet('test_exposed_form_buttons', [
        'query' => [
            $identifier => 'article',
        ],
    ]);
    $this->assertSession()
        ->fieldValueEquals(Html::getId('edit-' . $identifier), 'article');
    // Alter the identifier of the filter to a random string containing
    // restricted characters.
    $view = Views::getView('test_exposed_form_buttons');
    $view->setDisplay();
    $identifier = 'bad identifier';
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'type' => [
            'exposed' => TRUE,
            'field' => 'type',
            'id' => 'type',
            'table' => 'node_field_data',
            'plugin_id' => 'in_operator',
            'entity_type' => 'node',
            'entity_field' => 'type',
            'expose' => [
                'identifier' => $identifier,
                'label' => 'Content: Type',
                'operator_id' => 'type_op',
                'reduce' => FALSE,
                'description' => 'Exposed overridden description',
            ],
        ],
    ]);
    $this->executeView($view);
    $errors = $view->validate();
    $expected = [
        'default' => [
            'This identifier has illegal characters.',
        ],
        'page_1' => [
            'This identifier has illegal characters.',
        ],
    ];
    $this->assertEquals($expected, $errors);
}

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