function IgnoreSlaveSubscriberTest::testSystemInitIgnoresSlaves

Tests \Drupal\Core\EventSubscriber\SlaveDatabaseIgnoreSubscriber::checkSlaveServer().

File

drupal/core/modules/system/lib/Drupal/system/Tests/System/IgnoreSlaveSubscriberTest.php, line 33

Class

IgnoreSlaveSubscriberTest
Tests the event subscriber that disables the slave database.

Namespace

Drupal\system\Tests\System

Code

function testSystemInitIgnoresSlaves() {

  // Clone the master credentials to a slave connection.
  // Note this will result in two independent connection objects that happen
  // to point to the same place.
  $connection_info = Database::getConnectionInfo('default');
  Database::addConnectionInfo('default', 'slave', $connection_info['default']);
  db_ignore_slave();
  $kernel = new DrupalKernel('testing', FALSE, drupal_classloader(), FALSE);
  $event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST);
  $subscriber = new SlaveDatabaseIgnoreSubscriber();
  $subscriber
    ->checkSlaveServer($event);
  $db1 = Database::getConnection('default', 'default');
  $db2 = Database::getConnection('slave', 'default');
  $this
    ->assertIdentical($db1, $db2, 'System Init ignores slaves when requested.');
}