Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / ServiceProvider / ServiceProviderTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\ServiceProvider;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8  * Tests service provider registration to the DIC.
9  *
10  * @group ServiceProvider
11  */
12 class ServiceProviderTest extends KernelTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['file', 'service_provider_test', 'system'];
20
21   /**
22    * Tests that services provided by module service providers get registered to the DIC.
23    */
24   public function testServiceProviderRegistration() {
25     $definition = $this->container->getDefinition('file.usage');
26     $this->assertTrue($definition->getClass() == 'Drupal\\service_provider_test\\TestFileUsage', 'Class has been changed');
27     $this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC');
28   }
29
30   /**
31    * Tests that the DIC keeps up with module enable/disable in the same request.
32    */
33   public function testServiceProviderRegistrationDynamic() {
34     // Uninstall the module and ensure the service provider's service is not registered.
35     \Drupal::service('module_installer')->uninstall(['service_provider_test']);
36     $this->assertFalse(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.');
37
38     // Install the module and ensure the service provider's service is registered.
39     \Drupal::service('module_installer')->install(['service_provider_test']);
40     $this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.');
41   }
42
43 }