class OptionsFormattersTest
Same name and namespace in other branches
- 11.x core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest
- 10 core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest
- 8.9.x core/modules/options/tests/src/Kernel/OptionsFormattersTest.php \Drupal\Tests\options\Kernel\OptionsFormattersTest
Tests the Options field type formatters.
@group options
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\field\Kernel\FieldKernelTestBase implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\options\Kernel\OptionsFieldUnitTestBase implements \Drupal\Tests\field\Kernel\FieldKernelTestBase
- class \Drupal\Tests\options\Kernel\OptionsFormattersTest implements \Drupal\Tests\options\Kernel\OptionsFieldUnitTestBase
- class \Drupal\Tests\options\Kernel\OptionsFieldUnitTestBase implements \Drupal\Tests\field\Kernel\FieldKernelTestBase
- class \Drupal\Tests\field\Kernel\FieldKernelTestBase implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of OptionsFormattersTest
See also
\Drupal\options\Plugin\Field\FieldFormatter\OptionsDefaultFormatter
\Drupal\options\Plugin\Field\FieldFormatter\OptionsKeyFormatter
File
-
core/
modules/ options/ tests/ src/ Kernel/ OptionsFormattersTest.php, line 14
Namespace
Drupal\Tests\options\KernelView source
class OptionsFormattersTest extends OptionsFieldUnitTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
}
/**
* Tests the formatters.
*/
public function testFormatter() {
$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.