You are here

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\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
MockGcEventSubscriber::$postNodeSaveCalled public static property
MockGcEventSubscriber::$preNodeSaveCalled public static property
MockGcEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
MockGcEventSubscriber::postNodeSave public function Post Node Save event listener.
MockGcEventSubscriber::preNodeSave public function Pre Node Save event listener.