MockGcEventSubscriber.php in GatherContent 8.4
File
tests/modules/gathercontent_test/src/EventSubscriber/MockGcEventSubscriber.php
View source
<?php
namespace Drupal\gathercontent_test\EventSubscriber;
use Drupal\gathercontent\Event\GatherContentEvents;
use Drupal\gathercontent\Event\PostNodeSaveEvent;
use Drupal\gathercontent\Event\PreNodeSaveEvent;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MockGcEventSubscriber implements EventSubscriberInterface {
public static $preNodeSaveCalled = 0;
public static $postNodeSaveCalled = 0;
public static function getSubscribedEvents() {
return [
GatherContentEvents::PRE_NODE_SAVE => 'preNodeSave',
GatherContentEvents::POST_NODE_SAVE => 'postNodeSave',
];
}
public function preNodeSave(PreNodeSaveEvent $event) {
$node = $event
->getNode();
TestCase::assertTrue($node
->isNew(), 'The event was recieved after the entity got saved.');
static::$preNodeSaveCalled++;
}
public function postNodeSave(PostNodeSaveEvent $event) {
$node = $event
->getNode();
TestCase::assertFalse($node
->isNew(), 'The event was recieved before the entity got saved.');
static::$postNodeSaveCalled++;
}
}