Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / EventSubscriber / IgnoreReplicaSubscriberTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\EventSubscriber;
4
5 use Drupal\Core\Database\Database;
6 use Drupal\Core\EventSubscriber\ReplicaDatabaseIgnoreSubscriber;
7 use Drupal\Core\DrupalKernel;
8 use Drupal\KernelTests\KernelTestBase;
9 use Symfony\Component\HttpFoundation\Request;
10 use Symfony\Component\HttpKernel\HttpKernelInterface;
11 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
12
13 /**
14  * Tests that ReplicaDatabaseIgnoreSubscriber functions correctly.
15  *
16  * @group system
17  */
18 class IgnoreReplicaSubscriberTest extends KernelTestBase {
19
20   /**
21    * Tests \Drupal\Core\EventSubscriber\ReplicaDatabaseIgnoreSubscriber::checkReplicaServer().
22    */
23   public function testSystemInitIgnoresSecondaries() {
24     // Clone the master credentials to a replica connection.
25     // Note this will result in two independent connection objects that happen
26     // to point to the same place.
27     $connection_info = Database::getConnectionInfo('default');
28     Database::addConnectionInfo('default', 'replica', $connection_info['default']);
29
30     db_ignore_replica();
31     $class_loader = require $this->root . '/autoload.php';
32     $kernel = new DrupalKernel('testing', $class_loader, FALSE);
33     $event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST);
34     $subscriber = new ReplicaDatabaseIgnoreSubscriber();
35     $subscriber->checkReplicaServer($event);
36
37     $db1 = Database::getConnection('default', 'default');
38     $db2 = Database::getConnection('replica', 'default');
39
40     $this->assertSame($db1, $db2, 'System Init ignores secondaries when requested.');
41   }
42
43 }