class PreprocessEventPassTest in Hook Event Dispatcher 8
Class PreprocessEventPassTest.
@group hook_event_dispatcher
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\hook_event_dispatcher\Unit\Preprocess\PreprocessEventPassTest
Expanded class hierarchy of PreprocessEventPassTest
File
- tests/
src/ Unit/ Preprocess/ PreprocessEventPassTest.php, line 23
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\PreprocessView source
class PreprocessEventPassTest extends UnitTestCase {
/**
* The Drupal ContainerBuilder.
*
* @var \Drupal\Core\DependencyInjection\ContainerBuilder
*/
private $builder;
/**
* The PreprocessEventPass.
*
* @var \Drupal\hook_event_dispatcher\Service\PreprocessEventPass
*/
private $pass;
/**
* {@inheritdoc}
*/
public function setUp() {
$this->builder = new ContainerBuilder();
$locator = new FileLocator([
dirname(dirname(dirname(dirname(__DIR__)))),
]);
$loader = new YamlFileLoader($this->builder, $locator);
$loader
->load('hook_event_dispatcher.services.yml');
$this->builder
->set('event_dispatcher', new SpyEventDispatcher());
$this->pass = new PreprocessEventPass();
}
/**
* Test if the ContainerBuilder has all services from the YAML file.
*/
public function testBuilderHasAllServices() {
$this->pass
->process($this->builder);
$this->builder
->compile();
$services = YamlDefinitionsLoader::getInstance()
->getServices();
foreach (array_keys($services) as $id) {
self::assertTrue($this->builder
->has($id));
}
}
/**
* Test if we can overwrite a default factory.
*
* Using the hook_event_dispatcher_factory tag.
*/
public function testOverwritingDefaultFactory() {
$fakeEckEntityFactory = new Definition(FakePreprocessEventFactory::class, [
EckEntityPreprocessEvent::getHook(),
]);
$fakeEckEntityFactory
->addTag('preprocess_event_factory');
$this->builder
->setDefinition('preprocess_event.fake_factory.eck_entity', $fakeEckEntityFactory);
$fakeHtmlFactory = new Definition(FakePreprocessEventFactory::class, [
HtmlPreprocessEvent::getHook(),
]);
$fakeHtmlFactory
->addTag('preprocess_event_factory');
$this->builder
->setDefinition('preprocess_event.fake_factory.html', $fakeHtmlFactory);
$this->pass
->process($this->builder);
$this->builder
->compile();
/** @var \Drupal\hook_event_dispatcher\Service\PreprocessEventFactoryMapper $mapper */
$mapper = $this->builder
->get('preprocess_event.factory_mapper');
$variables = [];
$eckMappedFactory = $mapper
->getFactory(EckEntityPreprocessEvent::getHook());
self::assertInstanceOf(FakePreprocessEventFactory::class, $eckMappedFactory);
self::assertEquals(EckEntityPreprocessEvent::getHook(), $eckMappedFactory
->getEventHook());
self::assertInstanceOf(FakePreprocessEvent::class, $eckMappedFactory
->createEvent($variables));
$htmlMappedFactory = $mapper
->getFactory(HtmlPreprocessEvent::getHook());
self::assertInstanceOf(FakePreprocessEventFactory::class, $htmlMappedFactory);
self::assertEquals(HtmlPreprocessEvent::getHook(), $htmlMappedFactory
->getEventHook());
self::assertInstanceOf(FakePreprocessEvent::class, $htmlMappedFactory
->createEvent($variables));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
PreprocessEventPassTest:: |
private | property | The Drupal ContainerBuilder. | |
PreprocessEventPassTest:: |
private | property | The PreprocessEventPass. | |
PreprocessEventPassTest:: |
public | function |
Overrides UnitTestCase:: |
|
PreprocessEventPassTest:: |
public | function | Test if the ContainerBuilder has all services from the YAML file. | |
PreprocessEventPassTest:: |
public | function | Test if we can overwrite a default factory. | |
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. |