Version 1
[yaffs-website] / web / core / modules / options / tests / src / Kernel / OptionsFormattersTest.php
1 <?php
2
3 namespace Drupal\Tests\options\Kernel;
4
5 use Drupal\entity_test\Entity\EntityTest;
6
7 /**
8  * Tests the Options field type formatters.
9  *
10  * @group options
11  * @see \Drupal\options\Plugin\Field\FieldFormatter\OptionsDefaultFormatter
12  * @see \Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter
13  */
14 class OptionsFormattersTest extends OptionsFieldUnitTestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function setUp() {
20     parent::setUp();
21   }
22
23   /**
24    * Tests the formatters.
25    */
26   public function testFormatter() {
27     $entity = EntityTest::create();
28     $entity->{$this->fieldName}->value = 1;
29
30     $items = $entity->get($this->fieldName);
31
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');
35
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);
39   }
40
41 }