3 namespace Drupal\Tests\options\Kernel;
5 use Drupal\entity_test\Entity\EntityTest;
8 * Tests the Options field type formatters.
11 * @see \Drupal\options\Plugin\Field\FieldFormatter\OptionsDefaultFormatter
12 * @see \Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter
14 class OptionsFormattersTest extends OptionsFieldUnitTestBase {
19 protected function setUp() {
24 * Tests the formatters.
26 public function testFormatter() {
27 $entity = EntityTest::create();
28 $entity->{$this->fieldName}->value = 1;
30 $items = $entity->get($this->fieldName);
32 $build = $items->view();
33 $this->assertEqual($build['#formatter'], 'list_default', 'Ensure to fall back to the default formatter.');
34 $this->assertEqual($build[0]['#markup'], 'One');
36 $build = $items->view(['type' => 'list_key']);
37 $this->assertEqual($build['#formatter'], 'list_key', 'The chosen formatter is used.');
38 $this->assertEqual((string) $build[0]['#markup'], 1);