public function ExposedFormTest::testExposedIdentifier in Drupal 9
Same name and namespace in other branches
- 8 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 103
Class
- ExposedFormTest
- Tests exposed forms functionality.
Namespace
Drupal\Tests\views\Functional\PluginCode
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);
}