BundleTest.php 1.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php

/**
 * @file
 * Definition of Drupal\system\Tests\Bundle\BundleTest.
 */

namespace Drupal\system\Tests\Bundle;

use Drupal\simpletest\WebTestBase;

/**
13
 * Tests bundle registration to the DIC.
14 15
 */
class BundleTest extends WebTestBase {
16 17 18 19 20 21 22 23

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('bundle_test');

24 25 26 27 28 29 30 31 32
  public static function getInfo() {
    return array(
      'name' => 'Bundle Registration',
      'description' => 'Tests bundle registration to the DIC.',
      'group' => 'Bundle',
    );
  }

  /**
33
   * Tests that services provided by module bundles get registered to the DIC.
34 35
   */
  function testBundleRegistration() {
36
    $this->assertTrue(drupal_container()->getDefinition('file.usage')->getClass() == 'Drupal\\bundle_test\\TestFileUsage', 'Class has been changed');
37
    $this->assertTrue(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service has been registered to the DIC');
katbailey's avatar
katbailey committed
38 39 40
    // The event subscriber method in the test class calls drupal_set_message with
    // a message saying it has fired. This will fire on every page request so it
    // should show up on the front page.
41
    $this->drupalGet('');
42
    $this->assertText(t('The bundle_test event subscriber fired!'), 'The bundle_test event subscriber fired');
43
  }
44 45 46 47 48 49 50 51 52 53 54 55 56 57

  /**
   * Tests that the DIC keeps up with module enable/disable in the same request.
   */
  function testBundleRegistrationDynamic() {
    // Disable the module and ensure the bundle's service is not registered.
    module_disable(array('bundle_test'));
    $this->assertFalse(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service does not exist in the DIC.');

    // Enable the module and ensure the bundle's service is registered.
    module_enable(array('bundle_test'));
    $this->assertTrue(drupal_container()->has('bundle_test_class'), 'The bundle_test_class service exists in the DIC.');
  }

58
}