final class OtherEventTest in Hook Event Dispatcher 3.x
Same name and namespace in other branches
- 8.2 modules/preprocess_event_dispatcher/tests/src/Unit/OtherEventTest.php \Drupal\Tests\preprocess_event_dispatcher\Unit\OtherEventTest
Class OtherEventTest.
@group preprocess_event_dispatcher
Testing all variables gives expected PHPMD warnings.
Plugin annotation
@SuppressWarnings(PHPMD . CouplingBetweenObjects);
Hierarchy
- class \Drupal\Tests\preprocess_event_dispatcher\Unit\OtherEventTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of OtherEventTest
File
- modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ OtherEventTest.php, line 28
Namespace
Drupal\Tests\preprocess_event_dispatcher\UnitView source
final class OtherEventTest extends TestCase {
/**
* PreprocessEventService.
*
* @var \Drupal\preprocess_event_dispatcher\Service\PreprocessEventService
* PreprocessEventService.
*/
private $service;
/**
* SpyEventDispatcher.
*
* @var \Drupal\Tests\preprocess_event_dispatcher\Unit\Helpers\SpyEventDispatcher
* SpyEventDispatcher
*/
private $dispatcher;
/**
* Variables array.
*
* @var array
* Variables.
*/
private $variables;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$loader = YamlDefinitionsLoader::getInstance();
$this->dispatcher = new SpyEventDispatcher();
$this->service = new PreprocessEventService($this->dispatcher, $loader
->getMapper());
$this->variables = [];
}
/**
* Test a BlockPreprocessEvent.
*/
public function testBlockEvent() : void {
$this
->createAndAssertEvent(BlockPreprocessEvent::class);
}
/**
* Test a FieldPreprocessEvent.
*/
public function testFieldEvent() : void {
$this
->createAndAssertEvent(FieldPreprocessEvent::class);
}
/**
* Test a FormPreprocessEvent.
*/
public function testFormEvent() : void {
$this
->createAndAssertEvent(FormPreprocessEvent::class);
}
/**
* Test a HtmlPreprocessEvent.
*/
public function testHtmlEvent() : void {
$this
->createAndAssertEvent(HtmlPreprocessEvent::class);
}
/**
* Test a ImagePreprocessEvent.
*/
public function testImageEvent() : void {
$this
->createAndAssertEvent(ImagePreprocessEvent::class);
}
/**
* Test a PagePreprocessEvent.
*/
public function testPageEvent() : void {
$this
->createAndAssertEvent(PagePreprocessEvent::class);
}
/**
* Test a ViewFieldPreprocessEvent.
*/
public function testViewFieldEvent() : void {
$this
->createAndAssertEvent(ViewFieldPreprocessEvent::class);
}
/**
* Test a ViewPreprocessEvent.
*/
public function testViewEvent() : void {
$this
->createAndAssertEvent(ViewPreprocessEvent::class);
}
/**
* Test a StatusMessagesPreprocessEvent.
*/
public function testStatusMessagesEvent() : void {
$this
->createAndAssertEvent(StatusMessagesPreprocessEvent::class);
}
/**
* Test a unknown hook.
*/
public function testNotMappingEvent() : void {
$this->service
->createAndDispatchKnownEvents('NoneExistingHook', $this->variables);
self::assertSame([], $this->dispatcher
->getEvents());
}
/**
* Create and assert the given event class.
*
* @param string $class
* Event class name.
*/
private function createAndAssertEvent(string $class) : void {
/** @var \Drupal\preprocess_event_dispatcher\Event\AbstractPreprocessEvent $class */
$this->service
->createAndDispatchKnownEvents($class::getHook(), $this->variables);
self::assertSame($class::name(), $this->dispatcher
->getLastEventName());
/** @var \Drupal\preprocess_event_dispatcher\Event\AbstractPreprocessEvent $event */
$event = $this->dispatcher
->getLastEvent();
self::assertInstanceOf($class, $event);
$variablesClass = str_replace([
'\\Event\\',
'PreprocessEvent',
], [
'\\Variables\\',
'EventVariables',
], $class);
self::assertInstanceOf($variablesClass, $event
->getVariables());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OtherEventTest:: |
private | property | SpyEventDispatcher. | |
OtherEventTest:: |
private | property | PreprocessEventService. | |
OtherEventTest:: |
private | property | Variables array. | |
OtherEventTest:: |
private | function | Create and assert the given event class. | |
OtherEventTest:: |
public | function | ||
OtherEventTest:: |
public | function | Test a BlockPreprocessEvent. | |
OtherEventTest:: |
public | function | Test a FieldPreprocessEvent. | |
OtherEventTest:: |
public | function | Test a FormPreprocessEvent. | |
OtherEventTest:: |
public | function | Test a HtmlPreprocessEvent. | |
OtherEventTest:: |
public | function | Test a ImagePreprocessEvent. | |
OtherEventTest:: |
public | function | Test a unknown hook. | |
OtherEventTest:: |
public | function | Test a PagePreprocessEvent. | |
OtherEventTest:: |
public | function | Test a StatusMessagesPreprocessEvent. | |
OtherEventTest:: |
public | function | Test a ViewPreprocessEvent. | |
OtherEventTest:: |
public | function | Test a ViewFieldPreprocessEvent. |