class EntityEventTest in Hook Event Dispatcher 3.x
Same name in this branch
- 3.x modules/preprocess_event_dispatcher/tests/src/Unit/EntityEventTest.php \Drupal\Tests\preprocess_event_dispatcher\Unit\EntityEventTest
- 3.x modules/core_event_dispatcher/tests/src/Unit/Entity/EntityEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityEventTest
Same name and namespace in other branches
- 8.2 modules/core_event_dispatcher/tests/src/Unit/Entity/EntityEventTest.php \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityEventTest
Class EntityEventTest.
@group core_event_dispatcher
Hierarchy
- class \Drupal\Tests\core_event_dispatcher\Unit\Entity\EntityEventTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of EntityEventTest
File
- modules/
core_event_dispatcher/ tests/ src/ Unit/ Entity/ EntityEventTest.php, line 26
Namespace
Drupal\Tests\core_event_dispatcher\Unit\EntityView source
class EntityEventTest extends TestCase {
/**
* The manager.
*
* @var \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
*/
private $manager;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$builder = new ContainerBuilder();
$this->manager = new HookEventDispatcherManagerSpy();
$builder
->set('hook_event_dispatcher.manager', $this->manager);
$builder
->compile();
Drupal::setContainer($builder);
}
/**
* Test EntityCreateEvent.
*/
public function testEntityCreateEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
core_event_dispatcher_entity_create($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityCreateEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_CREATE);
self::assertSame($entity, $event
->getEntity());
}
/**
* Test EntityDeleteEvent.
*/
public function testEntityDeleteEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
core_event_dispatcher_entity_delete($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityDeleteEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_DELETE);
self::assertSame($entity, $event
->getEntity());
}
/**
* Test EntityInsertEvent.
*/
public function testEntityInsertEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
core_event_dispatcher_entity_insert($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityInsertEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_INSERT);
self::assertSame($entity, $event
->getEntity());
}
/**
* Test EntityLoadEvent.
*/
public function testEntityLoadEvent() : void {
$entities = [
$this
->createMock(EntityInterface::class),
$this
->createMock(EntityInterface::class),
$this
->createMock(EntityInterface::class),
];
$entityTypeId = 'test';
core_event_dispatcher_entity_load($entities, $entityTypeId);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityLoadEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_LOAD);
self::assertSame($entities, $event
->getEntities());
self::assertSame($entityTypeId, $event
->getEntityTypeId());
}
/**
* Test EntityTranslationInsertEvent.
*/
public function testEntityTranslationInsertEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
core_event_dispatcher_entity_translation_insert($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityTranslationInsertEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_TRANSLATION_INSERT);
self::assertSame($entity, $event
->getEntity());
}
/**
* Test EntityTranslationDeleteEvent.
*/
public function testEntityTranslationDeleteEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
core_event_dispatcher_entity_translation_delete($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityTranslationDeleteEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_TRANSLATION_DELETE);
self::assertSame($entity, $event
->getEntity());
}
/**
* Test EntityPredeleteEvent.
*/
public function testEntityPredeleteEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
core_event_dispatcher_entity_predelete($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityPredeleteEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_PRE_DELETE);
self::assertSame($entity, $event
->getEntity());
}
/**
* Test EntityPresaveEvent.
*/
public function testEntityPresaveEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
$originalEntity = $this
->createMock(EntityInterface::class);
$entity->original = $originalEntity;
core_event_dispatcher_entity_presave($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_PRE_SAVE);
self::assertSame($entity, $event
->getEntity());
self::assertSame($originalEntity, $event
->getOriginalEntity());
}
/**
* Test EntityPresaveEvent without original.
*/
public function testEntityPresaveEventWithoutOriginal() : void {
$entity = $this
->createMock(EntityInterface::class);
core_event_dispatcher_entity_presave($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_PRE_SAVE);
self::assertSame($entity, $event
->getEntity());
self::assertNull($event
->getOriginalEntity());
}
/**
* Test EntityUpdateEvent.
*/
public function testEntityUpdateEvent() : void {
$entity = $this
->createMock(EntityInterface::class);
$originalEntity = $this
->createMock(EntityInterface::class);
$entity->original = $originalEntity;
core_event_dispatcher_entity_update($entity);
/** @var \Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_UPDATE);
self::assertSame($entity, $event
->getEntity());
self::assertSame($originalEntity, $event
->getOriginalEntity());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityEventTest:: |
private | property | The manager. | |
EntityEventTest:: |
public | function | ||
EntityEventTest:: |
public | function | Test EntityCreateEvent. | |
EntityEventTest:: |
public | function | Test EntityDeleteEvent. | |
EntityEventTest:: |
public | function | Test EntityInsertEvent. | |
EntityEventTest:: |
public | function | Test EntityLoadEvent. | |
EntityEventTest:: |
public | function | Test EntityPredeleteEvent. | |
EntityEventTest:: |
public | function | Test EntityPresaveEvent. | |
EntityEventTest:: |
public | function | Test EntityPresaveEvent without original. | |
EntityEventTest:: |
public | function | Test EntityTranslationDeleteEvent. | |
EntityEventTest:: |
public | function | Test EntityTranslationInsertEvent. | |
EntityEventTest:: |
public | function | Test EntityUpdateEvent. |