public function TextFormatterTest::testFormatters in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/text/src/Tests/Formatter/TextFormatterTest.php \Drupal\text\Tests\Formatter\TextFormatterTest::testFormatters()
Tests all text field formatters.
File
- core/
modules/ text/ src/ Tests/ Formatter/ TextFormatterTest.php, line 75 - Contains \Drupal\text\Tests\Formatter\TextFormatterTest.
Class
- TextFormatterTest
- Tests the text formatters functionality.
Namespace
Drupal\text\Tests\FormatterCode
public function testFormatters() {
$formatters = array(
'text_default',
'text_trimmed',
'text_summary_or_trimmed',
);
// Create the entity to be referenced.
$entity = entity_create($this->entityType, array(
'name' => $this
->randomMachineName(),
));
$entity->formatted_text = array(
'value' => 'Hello, world!',
'format' => 'my_text_format',
);
$entity
->save();
foreach ($formatters as $formatter) {
// Verify the text field formatter's render array.
$build = $entity
->get('formatted_text')
->view(array(
'type' => $formatter,
));
\Drupal::service('renderer')
->renderRoot($build[0]);
$this
->assertEqual($build[0]['#markup'], "<p>Hello, world!</p>\n");
$this
->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')
->getCacheTags(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array(
'@formatter' => $formatter,
)));
}
}