Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / DrupalKernel / DrupalKernelSiteTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\DrupalKernel;
4
5 use Drupal\Core\Site\Settings;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests site-specific service overrides.
10  *
11  * @group DrupalKernel
12  */
13 class DrupalKernelSiteTest extends KernelTestBase {
14
15   /**
16    * Tests services.yml in site directory.
17    */
18   public function testServicesYml() {
19     $container_yamls = Settings::get('container_yamls');
20     $container_yamls[] = $this->siteDirectory . '/services.yml';
21     $this->setSetting('container_yamls', $container_yamls);
22     $this->assertFalse($this->container->has('site.service.yml'));
23     // A service provider class always has precedence over services.yml files.
24     // KernelTestBase::buildContainer() swaps out many services with in-memory
25     // implementations already, so those cannot be tested.
26     $this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\Core\Cache\DatabaseBackendFactory');
27
28     $class = __CLASS__;
29     $doc = <<<EOD
30 services:
31   # Add a new service.
32   site.service.yml:
33     class: $class
34   # Swap out a core service.
35   cache.backend.database:
36     class: Drupal\Core\Cache\MemoryBackendFactory
37 EOD;
38     file_put_contents($this->siteDirectory . '/services.yml', $doc);
39
40     // Rebuild the container.
41     $this->container->get('kernel')->rebuildContainer();
42
43     $this->assertTrue($this->container->has('site.service.yml'));
44     $this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\Core\Cache\MemoryBackendFactory');
45   }
46
47 }