diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index 455d363..e26a04c 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -78,6 +78,8 @@ class IntegrationTest extends WebTestBase { $this->createIndex(); $this->checkContentEntityTracking(); + $this->checkFieldLabels(); + $this->addFieldsToIndex(); $this->addAdditionalFieldsToIndex(); $this->removeFieldsFromIndex(); @@ -96,34 +98,56 @@ class IntegrationTest extends WebTestBase { /** * Test that field labels are not double escaped nor not escaped at all. */ - public function testFieldLabels() { - // Login with an admin user. - $this->drupalLogin($this->createUser(array('administer search_api', 'access administration pages', 'administer content types', 'administer node fields'))); - - // Create a server and index to be used for testing. - $this->createServer(); - $this->createIndex(); + protected function checkFieldLabels() { + $permissions = array( + 'administer search_api', + 'access administration pages', + 'administer content types', + 'administer node fields' + ); + $this->drupalLogin($this->createUser($permissions)); $content_type_name = '&%@Content()_='; // Add a new content type with funky chars. + $edit = array( + 'name' => $content_type_name, + 'type' => '_content_' + ); $this->drupalGet('admin/structure/types/add'); $this->assertResponse(200); - $this->drupalPostForm(NULL, array('name' => $content_type_name, 'type' => '_content_'), $this->t('Save and manage fields')); + $this->drupalPostForm(NULL, $edit, $this->t('Save and manage fields')); $field_name = '^6%{[*>.<"field'; // Add a field to that content type with funky chars. + $edit = array( + 'new_storage_type' => 'string', + 'label' => $field_name, + 'field_name' => '_field_' + ); $this->drupalGet('admin/structure/types/manage/_content_/fields/add-field'); $this->assertResponse(200); - $this->drupalPostForm(NULL, array('new_storage_type' => 'string', 'label' => $field_name, 'field_name' => '_field_'), $this->t('Save and continue')); + $this->drupalPostForm(NULL, $edit, $this->t('Save and continue')); $this->drupalPostForm(NULL, array(), $this->t('Save field settings')); + $edit = array('fields[entity:node/field__field_][indexed]' => 1); $this->drupalGet($this->getIndexPath('fields')); - $this->assertRaw(Html::escape($field_name)); + $this->drupalPostForm(NULL, $edit, $this->t('Save changes')); + $this->checkHtmlEscaping($field_name); + $edit = array( + 'datasource_configs[entity:node][default]' => 1, + ); $this->drupalGet($this->getIndexPath('edit')); - $this->assertRaw(Html::escape($content_type_name)); + $this->checkHtmlEscaping($content_type_name); + $this->drupalPostForm(NULL, $edit, $this->t('Save')); + + $edit = array('status[ignore_character]' => 1); + $this->drupalGet($this->getIndexPath('processors')); + $this->drupalPostForm(NULL, $edit, $this->t('Save')); + $this->checkHtmlEscaping($content_type_name); + $this->checkHtmlEscaping($field_name); } /** @@ -679,4 +703,16 @@ class IntegrationTest extends WebTestBase { return $path; } + /** + * Test for how well a string is escaped. + * + * @param string $string + * The text to check for. + */ + protected function checkHtmlEscaping($string) { + $this->assertRaw(Html::escape($string)); + $this->assertNoRaw(Html::escape(Html::escape($string))); + $this->assertNoRaw($string); + } + }