You are here

public function RawStringFormatterTest::testStringFormatter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/String/RawStringFormatterTest.php \Drupal\field\Tests\String\RawStringFormatterTest::testStringFormatter()

Tests string formatter output.

File

core/modules/field/src/Tests/String/RawStringFormatterTest.php, line 111
Contains \Drupal\field\Tests\String\RawStringFormatterTest.

Class

RawStringFormatterTest
Tests the raw string formatter

Namespace

Drupal\field\Tests\String

Code

public function testStringFormatter() {
  $value = $this
    ->randomString();
  $value .= "\n\n<strong>" . $this
    ->randomString() . '</strong>';
  $value .= "\n\n" . $this
    ->randomString();
  $entity = EntityTest::create(array());
  $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.');
}