You are here

class PathEventTest in Hook Event Dispatcher 8.2

Same name and namespace in other branches
  1. 8 tests/src/Unit/Path/PathEventTest.php \Drupal\Tests\hook_event_dispatcher\Unit\Path\PathEventTest
  2. 3.x modules/path_event_dispatcher/tests/src/Unit/Path/PathEventTest.php \Drupal\Tests\hook_event_dispatcher\Unit\Path\PathEventTest

Class PathEventTest.

@group path_event_dispatcher

Hierarchy

  • class \Drupal\Tests\hook_event_dispatcher\Unit\Path\PathEventTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of PathEventTest

File

modules/path_event_dispatcher/tests/src/Unit/Path/PathEventTest.php, line 19

Namespace

Drupal\Tests\hook_event_dispatcher\Unit\Path
View source
class PathEventTest 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 PathDeleteEvent.
   */
  public function testPathDeleteEvent() : void {
    $source = 'testSource';
    $alias = 'testAlias';
    $langcode = 'NL';
    $pid = 1337;
    $path = [
      'source' => $source,
      'alias' => $alias,
      'langcode' => $langcode,
      'pid' => $pid,
      'redirect' => TRUE,
    ];
    path_event_dispatcher_path_delete($path);

    /** @var \Drupal\path_event_dispatcher\Event\Path\PathDeleteEvent $event */
    $event = $this->manager
      ->getRegisteredEvent(HookEventDispatcherInterface::PATH_DELETE);
    self::assertSame($source, $event
      ->getSource());
    self::assertSame($alias, $event
      ->getAlias());
    self::assertSame($langcode, $event
      ->getLangcode());
    self::assertSame($pid, $event
      ->getPid());
    self::assertTrue($event
      ->isRedirect());
  }

  /**
   * Test PathDeleteEvent.
   */
  public function testPathDeleteEventWithoutRedirect() : void {
    $source = 'testSource';
    $alias = 'testAlias';
    $langcode = 'NL';
    $pid = 1337;
    $path = [
      'source' => $source,
      'alias' => $alias,
      'langcode' => $langcode,
      'pid' => $pid,
    ];
    path_event_dispatcher_path_delete($path);

    /** @var \Drupal\path_event_dispatcher\Event\Path\PathDeleteEvent $event */
    $event = $this->manager
      ->getRegisteredEvent(HookEventDispatcherInterface::PATH_DELETE);
    self::assertSame($source, $event
      ->getSource());
    self::assertSame($alias, $event
      ->getAlias());
    self::assertSame($langcode, $event
      ->getLangcode());
    self::assertSame($pid, $event
      ->getPid());
    self::assertFalse($event
      ->isRedirect());
  }

  /**
   * Test PathInsertEvent.
   */
  public function testPathInsertEvent() : void {
    $source = 'testSource';
    $alias = 'testAlias';
    $langcode = 'NL';
    $pid = 1337;
    $path = [
      'source' => $source,
      'alias' => $alias,
      'langcode' => $langcode,
      'pid' => $pid,
    ];
    path_event_dispatcher_path_insert($path);

    /** @var \Drupal\path_event_dispatcher\Event\Path\PathInsertEvent $event */
    $event = $this->manager
      ->getRegisteredEvent(HookEventDispatcherInterface::PATH_INSERT);
    self::assertSame($source, $event
      ->getSource());
    self::assertSame($alias, $event
      ->getAlias());
    self::assertSame($langcode, $event
      ->getLangcode());
    self::assertSame($pid, $event
      ->getPid());
  }

  /**
   * Test PathUpdateEvent.
   */
  public function testPathUpdateEvent() : void {
    $source = 'testSource';
    $alias = 'testAlias';
    $langcode = 'NL';
    $pid = 1337;
    $path = [
      'source' => $source,
      'alias' => $alias,
      'langcode' => $langcode,
      'pid' => $pid,
    ];
    path_event_dispatcher_path_update($path);

    /** @var \Drupal\path_event_dispatcher\Event\Path\PathUpdateEvent $event */
    $event = $this->manager
      ->getRegisteredEvent(HookEventDispatcherInterface::PATH_UPDATE);
    self::assertSame($source, $event
      ->getSource());
    self::assertSame($alias, $event
      ->getAlias());
    self::assertSame($langcode, $event
      ->getLangcode());
    self::assertSame($pid, $event
      ->getPid());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathEventTest::$manager private property The manager.
PathEventTest::setUp public function
PathEventTest::testPathDeleteEvent public function Test PathDeleteEvent.
PathEventTest::testPathDeleteEventWithoutRedirect public function Test PathDeleteEvent.
PathEventTest::testPathInsertEvent public function Test PathInsertEvent.
PathEventTest::testPathUpdateEvent public function Test PathUpdateEvent.