Commit b7a29016 authored by catch's avatar catch

Issue #2462653 by chx, alexpott, daffie, neclimdul: Connection::getDriverClass...

Issue #2462653 by chx, alexpott, daffie, neclimdul: Connection::getDriverClass doesn't support non-core drivers
parent 389d6635
......@@ -753,14 +753,11 @@ protected function expandArguments(&$query, &$args) {
*/
public function getDriverClass($class) {
if (empty($this->driverClasses[$class])) {
$driver = $this->driver();
if (!empty($this->connectionOptions['namespace'])) {
$driver_class = $this->connectionOptions['namespace'] . '\\' . $class;
}
else {
// Fallback for Drupal 7 settings.php.
$driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\{$class}";
if (empty($this->connectionOptions['namespace'])) {
// Fallback for Drupal 7 settings.php and the test runner script.
$this->connectionOptions['namespace'] = (new \ReflectionObject($this))->getNamespaceName();
}
$driver_class = $this->connectionOptions['namespace'] . '\\' . $class;
$this->driverClasses[$class] = class_exists($driver_class) ? $driver_class : $class;
}
return $this->driverClasses[$class];
......
......@@ -97,6 +97,8 @@ function testConnectionOptions() {
// Set up identical replica and confirm connection options are identical.
Database::addConnectionInfo('default', 'replica', $connection_info['default']);
$db2 = Database::getConnection('replica', 'default');
// Getting a driver class ensures the namespace option is set.
$this->assertEquals($db->getDriverClass('select'), $db2->getDriverClass('select'));
$connectionOptions2 = $db2->getConnectionOptions();
// Get a fresh copy of the default connection options.
......
......@@ -150,19 +150,16 @@ public function providerGetDriverClass() {
return array(
array(
'nonexistent_class',
'stub',
'\\',
'nonexistent_class',
),
array(
'Drupal\\Core\\Database\\Driver\\mysql\\Select',
'mysql',
'Drupal\Tests\Core\Database\Stub\Select',
NULL,
'Select',
),
array(
'Drupal\\Tests\\Core\\Database\\Stub\\Driver\\Schema',
'stub',
'Drupal\\Tests\\Core\\Database\\Stub\\Driver',
'Schema',
),
......@@ -174,11 +171,10 @@ public function providerGetDriverClass() {
*
* @dataProvider providerGetDriverClass
*/
public function testGetDriverClass($expected, $driver, $namespace, $class) {
public function testGetDriverClass($expected, $namespace, $class) {
$mock_pdo = $this->getMock('Drupal\Tests\Core\Database\Stub\StubPDO');
$connection = new StubConnection($mock_pdo, array('namespace' => $namespace));
// Set the driver using our stub class' public property.
$connection->driver = $driver;
$this->assertEquals($expected, $connection->getDriverClass($class));
}
......
<?php
namespace Drupal\Tests\Core\Database\Stub;
use Drupal\Core\Database\Driver\mysql\Select as QuerySelect;
class Select extends QuerySelect {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment