class FieldFormatterInfoAlterEventTest in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/field_event_dispatcher/tests/src/Unit/Field/FieldFormatterInfoAlterEventTest.php \Drupal\Tests\field_event_dispatcher\Unit\Field\FieldFormatterInfoAlterEventTest
Class FieldFormatterInfoAlterEventTest.
@group field_event_dispatcher
Hierarchy
- class \Drupal\Tests\field_event_dispatcher\Unit\Field\FieldFormatterInfoAlterEventTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of FieldFormatterInfoAlterEventTest
File
- modules/
field_event_dispatcher/ tests/ src/ Unit/ Field/ FieldFormatterInfoAlterEventTest.php, line 18
Namespace
Drupal\Tests\field_event_dispatcher\Unit\FieldView source
class FieldFormatterInfoAlterEventTest extends TestCase {
/**
* The manager.
*
* @var \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
*/
private $manager;
/**
* Sets up the test.
*/
public function setUp() : void {
$builder = new ContainerBuilder();
$this->manager = new HookEventDispatcherManagerSpy();
$builder
->set('hook_event_dispatcher.manager', $this->manager);
$builder
->compile();
Drupal::setContainer($builder);
}
/**
* FieldFormatterInfoAlterEvent array alter test.
*
* This tests altering the field formatter type definitions array.
*/
public function testInfoAlter() {
$info = $expectedInfo = [
'image' => [
'id' => 'image',
'class' => 'Drupal\\image\\Plugin\\Field\\FieldFormatter\\ImageFormatter',
],
];
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::FIELD_FORMATTER_INFO_ALTER => static function (FieldFormatterInfoAlterEvent $event) {
$info =& $event
->getInfo();
$info['image']['class'] = 'Drupal\\another_module\\Plugin\\Field\\FieldFormatter\\ImageFormatter';
},
]);
// Run the procedural hook which should trigger the above handler.
field_event_dispatcher_field_formatter_info_alter($info);
/** @var \Drupal\field_event_dispatcher\Event\Field\FieldFormatterInfoAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::FIELD_FORMATTER_INFO_ALTER);
self::assertSame($info, $event
->getInfo());
$expectedInfo['image']['class'] = 'Drupal\\another_module\\Plugin\\Field\\FieldFormatter\\ImageFormatter';
self::assertSame($expectedInfo, $info);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldFormatterInfoAlterEventTest:: |
private | property | The manager. | |
FieldFormatterInfoAlterEventTest:: |
public | function | Sets up the test. | |
FieldFormatterInfoAlterEventTest:: |
public | function | FieldFormatterInfoAlterEvent array alter test. |