Commit df94b0c1 authored by alexpott's avatar alexpott

Issue #2870462 by Lendude, michielnugter: Convert web tests to browser tests for text module

parent 8c5075ad
<?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);
}
}
<?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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment