class MediaSourceInfoAlterEventTest in Hook Event Dispatcher 8.2
Same name and namespace in other branches
- 3.x modules/media_event_dispatcher/tests/src/Unit/Media/MediaSourceInfoAlterEventTest.php \Drupal\Tests\media_event_dispatcher\Unit\Media\MediaSourceInfoAlterEventTest
Class MediaSourceInfoAlterEventTest.
@group media_event_dispatcher
Hierarchy
- class \Drupal\Tests\media_event_dispatcher\Unit\Media\MediaSourceInfoAlterEventTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of MediaSourceInfoAlterEventTest
File
- modules/
media_event_dispatcher/ tests/ src/ Unit/ Media/ MediaSourceInfoAlterEventTest.php, line 19
Namespace
Drupal\Tests\media_event_dispatcher\Unit\MediaView source
class MediaSourceInfoAlterEventTest 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);
}
/**
* MediaSourceInfoAlterEvent sources array alter test.
*
* This tests altering the media source plugin definitions array.
*/
public function testMediaSourceInfoAlter() {
$sources = $expectedSources = [
'image' => [
'id' => 'image',
'label' => new TranslatableMarkup('Image'),
'description' => new TranslatableMarkup('Use local images for reusable media.'),
'class' => 'Drupal\\media\\Plugin\\media\\Source\\Image',
'allowed_field_types' => [
'image',
],
],
];
$this->manager
->setEventCallbacks([
HookEventDispatcherInterface::MEDIA_SOURCE_INFO_ALTER => static function (MediaSourceInfoAlterEvent $event) {
$sources =& $event
->getSources();
$sources['image']['allowed_field_types'][] = 'test';
},
]);
// Run the procedural hook which should trigger the above handler.
media_event_dispatcher_media_source_info_alter($sources);
/** @var \Drupal\media_event_dispatcher\Event\Media\MediaSourceInfoAlterEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::MEDIA_SOURCE_INFO_ALTER);
self::assertSame($sources, $event
->getSources());
$expectedSources['image']['allowed_field_types'][] = 'test';
self::assertSame($expectedSources, $sources);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MediaSourceInfoAlterEventTest:: |
private | property | The manager. | |
MediaSourceInfoAlterEventTest:: |
public | function | Sets up the test. | |
MediaSourceInfoAlterEventTest:: |
public | function | MediaSourceInfoAlterEvent sources array alter test. |