WidgetPluginManagerTest.php in Zircon Profile 8
File
core/modules/field/src/Tests/WidgetPluginManagerTest.php
View source
<?php
namespace Drupal\field\Tests;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\WidgetPluginManager;
class WidgetPluginManagerTest extends FieldUnitTestBase {
function testWidgetDefinitionAlter() {
$widget_definition = \Drupal::service('plugin.manager.field.widget')
->getDefinition('test_field_widget_multiple');
$this
->assertTrue(in_array('test_field', $widget_definition['field_types']), "The 'test_field_widget_multiple' widget is enabled for the 'test_field' field type in field_test_field_widget_info_alter().");
}
public function testNotApplicableFallback() {
$widget_plugin_manager = \Drupal::service('plugin.manager.field.widget');
$base_field_definition = BaseFieldDefinition::create('test_field')
->setName('field_multiwidgetfield');
$widget_options = array(
'field_definition' => $base_field_definition,
'form_mode' => 'default',
'configuration' => array(
'type' => 'test_field_widget_multiple',
),
);
$instance = $widget_plugin_manager
->getInstance($widget_options);
$this
->assertEqual($instance
->getPluginId(), 'test_field_widget_multiple');
$base_field_definition
->setName('field_onewidgetfield');
$instance = $widget_plugin_manager
->getInstance($widget_options);
$this
->assertNotEqual($instance
->getPluginId(), 'test_field_widget_multiple');
$this
->assertEqual($instance
->getPluginId(), 'test_field_widget');
}
}