function RawStringFormatterTest::testStringFormatter
Same name in other branches
- 9 core/modules/field/tests/src/Kernel/String/RawStringFormatterTest.php \Drupal\Tests\field\Kernel\String\RawStringFormatterTest::testStringFormatter()
- 8.9.x core/modules/field/tests/src/Kernel/String/RawStringFormatterTest.php \Drupal\Tests\field\Kernel\String\RawStringFormatterTest::testStringFormatter()
- 10 core/modules/field/tests/src/Kernel/KernelString/RawStringFormatterTest.php \Drupal\Tests\field\Kernel\KernelString\RawStringFormatterTest::testStringFormatter()
Tests string formatter output.
File
-
core/
modules/ field/ tests/ src/ Kernel/ KernelString/ RawStringFormatterTest.php, line 110
Class
- RawStringFormatterTest
- Tests the raw string formatter.
Namespace
Drupal\Tests\field\Kernel\KernelStringCode
public function testStringFormatter() : void {
$value = $this->randomString();
$value .= "\n\n<strong>" . $this->randomString() . '</strong>';
$value .= "\n\n" . $this->randomString();
$entity = EntityTest::create([]);
$entity->{$this->fieldName}->value = $value;
// Verify that all HTML is escaped and newlines are retained.
$this->renderEntityFields($entity, $this->display);
$this->assertNoRaw($value);
$this->assertRaw(nl2br(Html::escape($value)));
// Verify the cache tags.
$build = $entity->{$this->fieldName}
->view();
$this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.