final class OtherEventTest in Hook Event Dispatcher 8
Class OtherEventTest.
@group hook_event_dispatcher
Testing all variables gives expected PHPMD warnings.
Plugin annotation
@SuppressWarnings(PHPMD . CouplingBetweenObjects);
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\hook_event_dispatcher\Unit\Preprocess\OtherEventTest
Expanded class hierarchy of OtherEventTest
File
- tests/
src/ Unit/ Preprocess/ OtherEventTest.php, line 28
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\PreprocessView source
final class OtherEventTest extends UnitTestCase {
/**
* PreprocessEventService.
*
* @var \Drupal\hook_event_dispatcher\Service\PreprocessEventService
* PreprocessEventService.
*/
private $service;
/**
* SpyEventDispatcher.
*
* @var \Drupal\Tests\hook_event_dispatcher\Unit\Preprocess\Helpers\SpyEventDispatcher
* SpyEventDispatcher
*/
private $dispatcher;
/**
* Variables array.
*
* @var array
* Variables.
*/
private $variables;
/**
* {@inheritdoc}
*/
public function setUp() {
$loader = YamlDefinitionsLoader::getInstance();
$this->dispatcher = new SpyEventDispatcher();
$this->service = new PreprocessEventService($this->dispatcher, $loader
->getMapper());
$this->variables = [];
}
/**
* Test a BlockPreprocessEvent.
*/
public function testBlockEvent() {
$this
->createAndAssertEvent(BlockPreprocessEvent::class);
}
/**
* Test a FieldPreprocessEvent.
*/
public function testFieldEvent() {
$this
->createAndAssertEvent(FieldPreprocessEvent::class);
}
/**
* Test a FormPreprocessEvent.
*/
public function testFormEvent() {
$this
->createAndAssertEvent(FormPreprocessEvent::class);
}
/**
* Test a HtmlPreprocessEvent.
*/
public function testHtmlEvent() {
$this
->createAndAssertEvent(HtmlPreprocessEvent::class);
}
/**
* Test a ImagePreprocessEvent.
*/
public function testImageEvent() {
$this
->createAndAssertEvent(ImagePreprocessEvent::class);
}
/**
* Test a PagePreprocessEvent.
*/
public function testPageEvent() {
$this
->createAndAssertEvent(PagePreprocessEvent::class);
}
/**
* Test a ViewFieldPreprocessEvent.
*/
public function testViewFieldEvent() {
$this
->createAndAssertEvent(ViewFieldPreprocessEvent::class);
}
/**
* Test a ViewPreprocessEvent.
*/
public function testViewEvent() {
$this
->createAndAssertEvent(ViewPreprocessEvent::class);
}
/**
* Test a StatusMessagesPreprocessEvent.
*/
public function testStatusMessagesEvent() {
$this
->createAndAssertEvent(StatusMessagesPreprocessEvent::class);
}
/**
* Test a unknown hook.
*/
public function testNotMappingEvent() {
$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($class) {
/** @var \Drupal\hook_event_dispatcher\Event\Preprocess\AbstractPreprocessEvent $class */
$this->service
->createAndDispatchKnownEvents($class::getHook(), $this->variables);
self::assertSame($class::name(), $this->dispatcher
->getLastEventName());
/** @var \Drupal\hook_event_dispatcher\Event\Preprocess\AbstractPreprocessEvent $event */
$event = $this->dispatcher
->getLastEvent();
self::assertInstanceOf($class, $event);
self::assertInstanceOf(AbstractEventVariables::class, $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 |
Overrides UnitTestCase:: |
|
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. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |