protected function IntegrationTest::checkFieldLabels in Search API 8
Tests that field labels are always properly escaped.
2 calls to IntegrationTest::checkFieldLabels()
- IntegrationTest::testFramework in tests/
src/ Functional/ IntegrationTest.php - Tests various operations via the Search API's admin UI.
- IntegrationTest::testIntegerIndex in tests/
src/ Functional/ IntegrationTest.php - Tests what happens when an index has an integer as id/label.
File
- tests/
src/ Functional/ IntegrationTest.php, line 749
Class
- IntegrationTest
- Tests the overall functionality of the Search API framework and admin UI.
Namespace
Drupal\Tests\search_api\FunctionalCode
protected function checkFieldLabels() {
$content_type_name = '&%@Content()_=';
// Add a new content type with funky chars.
$edit = [
'name' => $content_type_name,
'type' => '_content_',
];
$this
->drupalGet('admin/structure/types/add');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm($edit, 'Save and manage fields');
// Make sure this worked.
$entity_bundle_info = $this->container
->get('entity_type.bundle.info');
$entity_bundle_info
->clearCachedBundles();
$bundles = $entity_bundle_info
->getBundleInfo('node');
$this
->assertArrayHasKey('_content_', $bundles);
// Add a field to that content type with funky chars.
$field_name = '^6%{[*>.<"field';
FieldStorageConfig::create([
'field_name' => 'field__field_',
'type' => 'string',
'entity_type' => 'node',
])
->save();
FieldConfig::create([
'field_name' => 'field__field_',
'entity_type' => 'node',
'bundle' => '_content_',
'label' => $field_name,
])
->save();
$url_options['query']['datasource'] = 'entity:node';
$this
->drupalGet($this
->getIndexPath('fields/add/nojs'), $url_options);
$this
->assertHtmlEscaped($field_name);
$this
->assertSession()
->responseContains('(<code>field__field_</code>)');
$this
->addField('entity:node', 'field__field_', $field_name);
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->assertHtmlEscaped($field_name);
// Also check data type labels/descriptions.
$this
->assertHtmlEscaped('"Test" data type');
$this
->assertSession()
->responseContains('Dummy <em>data type</em> implementation');
$this
->submitForm([], 'Save changes');
$edit = [
'datasource_configs[entity:node][bundles][default]' => 1,
];
$this
->drupalGet($this
->getIndexPath('edit'));
$this
->assertHtmlEscaped($content_type_name);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->addField(NULL, 'rendered_item', 'Rendered HTML output');
$this
->assertHtmlEscaped($content_type_name);
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextContains(' The field configuration was successfully saved.');
$this
->addField(NULL, 'aggregated_field', 'Aggregated field');
$this
->assertHtmlEscaped($field_name);
$this
->submitForm([
'fields[entity:node/field__field_]' => TRUE,
], 'Save');
$this
->assertSession()
->pageTextContains(' The field configuration was successfully saved.');
}