function FormatterPluginManagerTest::testNotApplicableFallback
Same name in other branches
- 9 core/modules/field/tests/src/Kernel/FormatterPluginManagerTest.php \Drupal\Tests\field\Kernel\FormatterPluginManagerTest::testNotApplicableFallback()
- 10 core/modules/field/tests/src/Kernel/FormatterPluginManagerTest.php \Drupal\Tests\field\Kernel\FormatterPluginManagerTest::testNotApplicableFallback()
- 11.x core/modules/field/tests/src/Kernel/FormatterPluginManagerTest.php \Drupal\Tests\field\Kernel\FormatterPluginManagerTest::testNotApplicableFallback()
Tests that getInstance falls back on default if current is not applicable.
See also
\Drupal\field\Tests\WidgetPluginManagerTest::testNotApplicableFallback()
File
-
core/
modules/ field/ tests/ src/ Kernel/ FormatterPluginManagerTest.php, line 19
Class
- FormatterPluginManagerTest
- Tests the field formatter plugin manager.
Namespace
Drupal\Tests\field\KernelCode
public function testNotApplicableFallback() {
/** @var \Drupal\Core\Field\FormatterPluginManager $formatter_plugin_manager */
$formatter_plugin_manager = \Drupal::service('plugin.manager.field.formatter');
$base_field_definition = BaseFieldDefinition::create('test_field')->setName('field_test_field');
$formatter_options = [
'field_definition' => $base_field_definition,
'view_mode' => 'default',
'configuration' => [
'type' => 'field_test_applicable',
],
];
$instance = $formatter_plugin_manager->getInstance($formatter_options);
$this->assertEqual($instance->getPluginId(), 'field_test_applicable');
// Now set name to something that makes isApplicable() return FALSE.
$base_field_definition->setName('deny_applicable');
$instance = $formatter_plugin_manager->getInstance($formatter_options);
// Instance should be default widget.
$this->assertNotEqual($instance->getPluginId(), 'field_test_applicable');
$this->assertEqual($instance->getPluginId(), 'field_test_default');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.