Commit 171bc5e5 authored by katbailey's avatar katbailey

Adding a test, and a test module, to show that bundles provided by modules...

Adding a test, and a test module, to show that bundles provided by modules have their services added to the DIC
parent 02fec435
<?php
/**
* @file
* Definition of Drupal\system\Tests\Bundle\BundleTest.
*/
namespace Drupal\system\Tests\Bundle;
use Drupal\simpletest\WebTestBase;
/**
* Test bundle registration to the DIC.
*/
class BundleTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Bundle Registration',
'description' => 'Tests bundle registration to the DIC.',
'group' => 'Bundle',
);
}
function setUp() {
parent::setUp('bundle_test');
}
/**
* Test that services provided by module bundles get registered to the DIC.
*/
function testBundleRegistration() {
$this->drupalGet('bundle_test');
$this->assertText(t('The service with id bundle_test_class is available in the DIC'), t('The bundle_test_class service has been registered to the DIC'));
$this->drupalGet('');
$this->assertText(t('The bundle_test event subscriber fired!'), t('The bundle_test event subscriber fired'));
}
}
name = "Bundle test"
description = "Support module for bundle testing."
package = Testing
version = VERSION
core = 8.x
hidden = TRUE
<?php
/**
* Implements hook_menu().
*/
function bundle_test_menu() {
$items['bundle_test'] = array(
'type' => MENU_CALLBACK,
'title' => t('Bundle test callback'),
'page callback' => 'bundle_test_callback',
'access callback' => TRUE,
);
return $items;
}
/**
* Simple callback for testing that the bundle_test_class service exists in the
* DIC.
*/
function bundle_test_callback() {
if (drupal_container()->has('bundle_test_class')) {
return t('The service with id bundle_test_class is available in the DIC');
}
return t('Service not found');
}
<?php
namespace Drupal\bundle_test;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Test bundle class.
*/
class BundleTestBundle extends Bundle
{
public function build(ContainerBuilder $container) {
$container->register('bundle_test_class', 'Drupal\bundle_test\TestClass')
->addTag('kernel.event_subscriber');
}
}
\ No newline at end of file
<?php
namespace Drupal\bundle_test;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TestClass implements EventSubscriberInterface {
/**
* A simple kernel listener method.
*/
public function onKernelRequestTest(GetResponseEvent $event) {
drupal_set_message(t('The bundle_test event subscriber fired!'));
}
/**
* Registers methods as kernel listeners.
*
* @return array
* An array of event listener definitions.
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('onKernelRequestTest', 100);
return $events;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment