From df94b0c1efa43cba32a885a29e305d6c9afe579e Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 24 Jul 2018 17:04:38 +0100 Subject: [PATCH] Issue #2870462 by Lendude, michielnugter: Convert web tests to browser tests for text module --- .../Functional}/String/StringFieldTest.php | 12 +++++----- .../src/Functional}/TextFieldTest.php | 22 ++++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) rename core/modules/field/{src/Tests => tests/src/Functional}/String/StringFieldTest.php (88%) rename core/modules/text/{src/Tests => tests/src/Functional}/TextFieldTest.php (92%) diff --git a/core/modules/field/src/Tests/String/StringFieldTest.php b/core/modules/field/tests/src/Functional/String/StringFieldTest.php similarity index 88% rename from core/modules/field/src/Tests/String/StringFieldTest.php rename to core/modules/field/tests/src/Functional/String/StringFieldTest.php index 9e98890340a0..e9894f8103cc 100644 --- a/core/modules/field/src/Tests/String/StringFieldTest.php +++ b/core/modules/field/tests/src/Functional/String/StringFieldTest.php @@ -1,18 +1,18 @@ <?php -namespace Drupal\field\Tests\String; +namespace Drupal\Tests\field\Functional\String; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; -use Drupal\simpletest\WebTestBase; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\Tests\BrowserTestBase; /** * Tests the creation of string fields. * * @group text */ -class StringFieldTest extends WebTestBase { +class StringFieldTest extends BrowserTestBase { /** * Modules to enable. @@ -86,7 +86,7 @@ public function _testTextfieldWidgets($field_type, $widget_type) { "{$field_name}[0][value]" => $value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); @@ -94,8 +94,8 @@ public function _testTextfieldWidgets($field_type, $widget_type) { $entity = EntityTest::load($id); $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); $content = $display->build($entity); - $this->setRawContent(\Drupal::service('renderer')->renderRoot($content)); - $this->assertText($value, 'Filtered tags are not displayed'); + $rendered_entity = \Drupal::service('renderer')->renderRoot($content); + $this->assertContains($value, (string) $rendered_entity); } } diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/tests/src/Functional/TextFieldTest.php similarity index 92% rename from core/modules/text/src/Tests/TextFieldTest.php rename to core/modules/text/tests/src/Functional/TextFieldTest.php index ecdb0af06d4d..ac01dd78a7b1 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/tests/src/Functional/TextFieldTest.php @@ -1,12 +1,14 @@ <?php -namespace Drupal\text\Tests; +namespace Drupal\Tests\text\Functional; +use Drupal\Component\Utility\Html; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; -use Drupal\field\Tests\String\StringFieldTest; use Drupal\field\Entity\FieldStorageConfig; use Drupal\filter\Entity\FilterFormat; +use Drupal\Tests\field\Functional\String\StringFieldTest; +use Drupal\Tests\TestFileCreationTrait; /** * Tests the creation of text fields. @@ -15,6 +17,10 @@ */ class TextFieldTest extends StringFieldTest { + use TestFileCreationTrait { + getTestFiles as drupalGetTestFiles; + } + /** * A user with relevant administrative privileges. * @@ -190,7 +196,7 @@ public function _testTextfieldWidgetsFormatted($field_type, $widget_type) { "{$field_name}[0][value]" => $value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - preg_match('|entity_test/manage/(\d+)|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); @@ -198,9 +204,9 @@ public function _testTextfieldWidgetsFormatted($field_type, $widget_type) { $entity = EntityTest::load($id); $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); $content = $display->build($entity); - $this->setRawContent($renderer->renderRoot($content)); - $this->assertNoRaw($value, 'HTML tags are not displayed.'); - $this->assertEscaped($value, 'Escaped HTML is displayed correctly.'); + $rendered_entity = \Drupal::service('renderer')->renderRoot($content); + $this->assertNotContains($value, (string) $rendered_entity); + $this->assertContains(Html::escape($value), (string) $rendered_entity); // Create a new text format that does not escape HTML, and grant the user // access to it. @@ -237,8 +243,8 @@ public function _testTextfieldWidgetsFormatted($field_type, $widget_type) { $entity = EntityTest::load($id); $display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); $content = $display->build($entity); - $this->setRawContent($renderer->renderRoot($content)); - $this->assertRaw($value, 'Value is displayed unfiltered'); + $rendered_entity = \Drupal::service('renderer')->renderRoot($content); + $this->assertContains($value, (string) $rendered_entity); } } -- GitLab