function ExposedFormTest::testExposedIdentifier
Same name in other branches
- 9 core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testExposedIdentifier()
- 10 core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testExposedIdentifier()
- 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 93
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->assertFieldById(Html::getId('edit-' . $identifier), 'article', "Article type filter set with new identifier.");
// 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->assertEqual($errors, $expected);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.