public function IntegrationTest::testUnwantedValues in Facets 8
Tests that we disallow unwanted values when creating a facet trough the UI.
File
- tests/
src/ Functional/ IntegrationTest.php, line 349
Class
- IntegrationTest
- Tests the overall functionality of the Facets admin UI.
Namespace
Drupal\Tests\facets\FunctionalCode
public function testUnwantedValues() {
// Go to the Add facet page and make sure that returns a 200.
$facet_add_page = '/admin/config/search/facets/add-facet';
$this
->drupalGet($facet_add_page);
$this
->assertSession()
->statusCodeEquals(200);
// Configure the facet source by selecting one of the Search API views.
$this
->drupalGet($facet_add_page);
$this
->drupalPostForm(NULL, [
'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
], 'Configure facet source');
// Fill in all fields and make sure the 'field is required' message is no
// longer shown.
$facet_source_form = [
'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
'facet_source_configs[search_api:views_page__search_api_test_view__page_1][field_identifier]' => 'type',
];
$this
->drupalPostForm(NULL, $facet_source_form, 'Save');
$form_values = [
'name' => 'name 1',
'id' => 'name 1',
];
$this
->drupalPostForm(NULL, $form_values, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
$form_values = [
'name' => 'name 1',
'id' => 'name:&1',
];
$this
->drupalPostForm(NULL, $form_values, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
// Post the form with valid values, so we can test the next step.
$form_values = [
'name' => 'name 1',
'id' => 'name_1',
];
$this
->drupalPostForm(NULL, $form_values, 'Save');
// Create an array of values that are not allowed in the url.
$unwanted_values = [
' ',
'!',
'@',
'#',
'$',
'%',
'^',
'&',
];
foreach ($unwanted_values as $unwanted_value) {
$form_values = [
'facet_settings[url_alias]' => 'alias' . $unwanted_value . '1',
];
$this
->drupalPostForm(NULL, $form_values, 'Save');
$this
->assertSession()
->pageTextContains('The URL alias contains characters that are not allowed.');
}
// Post an alias with allowed values.
$form_values = [
'facet_settings[url_alias]' => 'alias~-_.1',
];
$this
->drupalPostForm(NULL, $form_values, 'Save');
$this
->assertSession()
->pageTextContains('Facet name 1 has been updated.');
}