class MockGcEventSubscriber in GatherContent 8.4
Class for testing events.
Hierarchy
- class \Drupal\gathercontent_test\EventSubscriber\MockGcEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of MockGcEventSubscriber
1 file declares its use of MockGcEventSubscriber
- ImporterTest.php in tests/
src/ Kernel/ ImporterTest.php
1 string reference to 'MockGcEventSubscriber'
- gathercontent_test.services.yml in tests/
modules/ gathercontent_test/ gathercontent_test.services.yml - tests/modules/gathercontent_test/gathercontent_test.services.yml
1 service uses MockGcEventSubscriber
- my_event_subscriber in tests/
modules/ gathercontent_test/ gathercontent_test.services.yml - \Drupal\gathercontent_test\EventSubscriber\MockGcEventSubscriber
File
- tests/
modules/ gathercontent_test/ src/ EventSubscriber/ MockGcEventSubscriber.php, line 14
Namespace
Drupal\gathercontent_test\EventSubscriberView source
class MockGcEventSubscriber implements EventSubscriberInterface {
public static $preNodeSaveCalled = 0;
public static $postNodeSaveCalled = 0;
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
GatherContentEvents::PRE_NODE_SAVE => 'preNodeSave',
GatherContentEvents::POST_NODE_SAVE => 'postNodeSave',
];
}
/**
* Pre Node Save event listener.
*/
public function preNodeSave(PreNodeSaveEvent $event) {
$node = $event
->getNode();
TestCase::assertTrue($node
->isNew(), 'The event was recieved after the entity got saved.');
static::$preNodeSaveCalled++;
}
/**
* Post Node Save event listener.
*/
public function postNodeSave(PostNodeSaveEvent $event) {
$node = $event
->getNode();
TestCase::assertFalse($node
->isNew(), 'The event was recieved before the entity got saved.');
static::$postNodeSaveCalled++;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MockGcEventSubscriber:: |
public static | property | ||
MockGcEventSubscriber:: |
public static | property | ||
MockGcEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
MockGcEventSubscriber:: |
public | function | Post Node Save event listener. | |
MockGcEventSubscriber:: |
public | function | Pre Node Save event listener. |