class PathEventTest in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/path_event_dispatcher/tests/src/Unit/Path/PathEventTest.php \Drupal\Tests\hook_event_dispatcher\Unit\Path\PathEventTest
- 8 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\PathView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathEventTest:: |
private | property | The manager. | |
PathEventTest:: |
public | function | ||
PathEventTest:: |
public | function | Test PathDeleteEvent. | |
PathEventTest:: |
public | function | Test PathDeleteEvent. | |
PathEventTest:: |
public | function | Test PathInsertEvent. | |
PathEventTest:: |
public | function | Test PathUpdateEvent. |