class EntityEventTest in Hook Event Dispatcher 8
Same name in this branch
- 8 tests/src/Unit/Entity/EntityEventTest.php \Drupal\Tests\hook_event_dispatcher\Unit\Entity\EntityEventTest
- 8 tests/src/Unit/Preprocess/EntityEventTest.php \Drupal\Tests\hook_event_dispatcher\Unit\Preprocess\EntityEventTest
Class EntityEventTest.
@package Drupal\Tests\hook_event_dispatcher\Unit\Entity
@group hook_event_dispatcher
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\hook_event_dispatcher\Unit\Entity\EntityEventTest
Expanded class hierarchy of EntityEventTest
File
- tests/
src/ Unit/ Entity/ EntityEventTest.php, line 18
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\EntityView source
class EntityEventTest extends UnitTestCase {
/**
* The manager.
*
* @var \Drupal\Tests\hook_event_dispatcher\Unit\HookEventDispatcherManagerSpy
*/
private $manager;
/**
* {@inheritdoc}
*/
public function setUp() {
$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() {
$entity = $this
->createMock(EntityInterface::class);
hook_event_dispatcher_entity_create($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityCreateEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_CREATE);
self::assertEquals($entity, $event
->getEntity());
}
/**
* Test EntityDeleteEvent.
*/
public function testEntityDeleteEvent() {
$entity = $this
->createMock(EntityInterface::class);
hook_event_dispatcher_entity_delete($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityDeleteEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_DELETE);
self::assertEquals($entity, $event
->getEntity());
}
/**
* Test EntityInsertEvent.
*/
public function testEntityInsertEvent() {
$entity = $this
->createMock(EntityInterface::class);
hook_event_dispatcher_entity_insert($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityInsertEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_INSERT);
self::assertEquals($entity, $event
->getEntity());
}
/**
* Test EntityLoadEvent.
*/
public function testEntityLoadEvent() {
$entities = [
$this
->createMock(EntityInterface::class),
$this
->createMock(EntityInterface::class),
$this
->createMock(EntityInterface::class),
];
$entityTypeId = 'test';
hook_event_dispatcher_entity_load($entities, $entityTypeId);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityLoadEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_LOAD);
self::assertEquals($entities, $event
->getEntities());
self::assertEquals($entityTypeId, $event
->getEntityTypeId());
}
/**
* Test EntityTranslationInsertEvent.
*/
public function testEntityTranslationInsertEvent() {
$entity = $this
->createMock(EntityInterface::class);
hook_event_dispatcher_entity_translation_insert($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityTranslationInsertEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_TRANSLATION_INSERT);
self::assertEquals($entity, $event
->getEntity());
}
/**
* Test EntityTranslationDeleteEvent.
*/
public function testEntityTranslationDeleteEvent() {
$entity = $this
->createMock(EntityInterface::class);
hook_event_dispatcher_entity_translation_delete($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityTranslationDeleteEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_TRANSLATION_DELETE);
self::assertEquals($entity, $event
->getEntity());
}
/**
* Test EntityPredeleteEvent.
*/
public function testEntityPredeleteEvent() {
$entity = $this
->createMock(EntityInterface::class);
hook_event_dispatcher_entity_predelete($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityPredeleteEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_PRE_DELETE);
self::assertEquals($entity, $event
->getEntity());
}
/**
* Test EntityPresaveEvent.
*/
public function testEntityPresaveEvent() {
$entity = $this
->createMock(EntityInterface::class);
$originalEntity = $this
->createMock(EntityInterface::class);
$entity->original = $originalEntity;
hook_event_dispatcher_entity_presave($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityPresaveEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_PRE_SAVE);
self::assertEquals($entity, $event
->getEntity());
self::assertEquals($originalEntity, $event
->getOriginalEntity());
}
/**
* Test EntityUpdateEvent.
*/
public function testEntityUpdateEvent() {
$entity = $this
->createMock(EntityInterface::class);
$originalEntity = $this
->createMock(EntityInterface::class);
$entity->original = $originalEntity;
hook_event_dispatcher_entity_update($entity);
/** @var \Drupal\hook_event_dispatcher\Event\Entity\EntityUpdateEvent $event */
$event = $this->manager
->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_UPDATE);
self::assertEquals($entity, $event
->getEntity());
self::assertEquals($originalEntity, $event
->getOriginalEntity());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityEventTest:: |
private | property | The manager. | |
EntityEventTest:: |
public | function |
Overrides UnitTestCase:: |
|
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 EntityTranslationDeleteEvent. | |
EntityEventTest:: |
public | function | Test EntityTranslationInsertEvent. | |
EntityEventTest:: |
public | function | Test EntityUpdateEvent. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |