function OptionsFormattersTest::testFormatter

Same name in other branches
  1. 9 core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest::testFormatter()
  2. 8.9.x core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest::testFormatter()
  3. 10 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 28

Class

OptionsFormattersTest
Tests the Options field type formatters.

Namespace

Drupal\Tests\options\Kernel

Code

public function testFormatter() : void {
    $entity = EntityTest::create();
    $entity->{$this->fieldName}->value = 1;
    $items = $entity->get($this->fieldName);
    $build = $items->view();
    $this->assertEquals('list_default', $build['#formatter'], 'Ensure to fall back to the default formatter.');
    $this->assertEquals('One', $build[0]['#markup']);
    $build = $items->view([
        'type' => 'list_key',
    ]);
    $this->assertEquals('list_key', $build['#formatter'], 'The chosen formatter is used.');
    $this->assertEquals(1, (string) $build[0]['#markup']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.