function OptionsFormattersTest::testFormatter
Same name in other branches
- 9 core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest::testFormatter()
- 10 core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest::testFormatter()
- 11.x core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest::testFormatter()
Tests the formatters.
File
-
core/
modules/ options/ tests/ src/ Kernel/ OptionsFormattersTest.php, line 26
Class
- OptionsFormattersTest
- Tests the Options field type formatters.
Namespace
Drupal\Tests\options\KernelCode
public function testFormatter() {
$entity = EntityTest::create();
$entity->{$this->fieldName}->value = 1;
$items = $entity->get($this->fieldName);
$build = $items->view();
$this->assertEqual($build['#formatter'], 'list_default', 'Ensure to fall back to the default formatter.');
$this->assertEqual($build[0]['#markup'], 'One');
$build = $items->view([
'type' => 'list_key',
]);
$this->assertEqual($build['#formatter'], 'list_key', 'The chosen formatter is used.');
$this->assertEqual((string) $build[0]['#markup'], 1);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.