You are here

public function UrlConversionTest::providerConvertDbUrlToConnectionInfo in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php \Drupal\Tests\Core\Database\UrlConversionTest::providerConvertDbUrlToConnectionInfo()
  2. 9 core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php \Drupal\Tests\Core\Database\UrlConversionTest::providerConvertDbUrlToConnectionInfo()

Data provider for testDbUrlToConnectionConversion().

Return value

array Array of arrays with the following elements:

  • url: The full URL string to be tested.
  • database_array: An array containing the expected results.

File

core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php, line 64

Class

UrlConversionTest
Tests for database URL to/from database connection array conversions.

Namespace

Drupal\Tests\Core\Database

Code

public function providerConvertDbUrlToConnectionInfo() {
  $root = dirname(__FILE__, 7);
  return [
    'MySql without prefix' => [
      'mysql://test_user:test_pass@test_host:3306/test_database',
      [
        'driver' => 'mysql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'port' => 3306,
        'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
        'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
      ],
    ],
    'SQLite, relative to root, without prefix' => [
      'sqlite://localhost/test_database',
      [
        'driver' => 'sqlite',
        'host' => 'localhost',
        'database' => $root . '/test_database',
        'namespace' => 'Drupal\\sqlite\\Driver\\Database\\sqlite',
        'autoload' => 'core/modules/sqlite/src/Driver/Database/sqlite/',
      ],
    ],
    'MySql with prefix' => [
      'mysql://test_user:test_pass@test_host:3306/test_database#bar',
      [
        'driver' => 'mysql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'prefix' => 'bar',
        'port' => 3306,
        'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
        'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
      ],
    ],
    'SQLite, relative to root, with prefix' => [
      'sqlite://localhost/test_database#foo',
      [
        'driver' => 'sqlite',
        'host' => 'localhost',
        'database' => $root . '/test_database',
        'prefix' => 'foo',
        'namespace' => 'Drupal\\sqlite\\Driver\\Database\\sqlite',
        'autoload' => 'core/modules/sqlite/src/Driver/Database/sqlite/',
      ],
    ],
    'SQLite, absolute path, without prefix' => [
      'sqlite://localhost//baz/test_database',
      [
        'driver' => 'sqlite',
        'host' => 'localhost',
        'database' => '/baz/test_database',
        'namespace' => 'Drupal\\sqlite\\Driver\\Database\\sqlite',
        'autoload' => 'core/modules/sqlite/src/Driver/Database/sqlite/',
      ],
    ],
    'MySQL contrib test driver without prefix' => [
      'DrivertestMysql://test_user:test_pass@test_host:3306/test_database?module=driver_test',
      [
        'driver' => 'DrivertestMysql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'port' => 3306,
        'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestMysql',
        'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/',
      ],
    ],
    'MySQL contrib test driver with prefix' => [
      'DrivertestMysql://test_user:test_pass@test_host:3306/test_database?module=driver_test#bar',
      [
        'driver' => 'DrivertestMysql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'prefix' => 'bar',
        'port' => 3306,
        'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestMysql',
        'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/',
      ],
    ],
    'PostgreSQL contrib test driver without prefix' => [
      'DrivertestPgsql://test_user:test_pass@test_host:5432/test_database?module=driver_test',
      [
        'driver' => 'DrivertestPgsql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'port' => 5432,
        'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestPgsql',
        'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/',
      ],
    ],
    'PostgreSQL contrib test driver with prefix' => [
      'DrivertestPgsql://test_user:test_pass@test_host:5432/test_database?module=driver_test#bar',
      [
        'driver' => 'DrivertestPgsql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'prefix' => 'bar',
        'port' => 5432,
        'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestPgsql',
        'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/',
      ],
    ],
    'MySql with a custom query parameter' => [
      'mysql://test_user:test_pass@test_host:3306/test_database?extra=value',
      [
        'driver' => 'mysql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'port' => 3306,
        'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
        'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
      ],
    ],
    'MySql with the module name mysql' => [
      'mysql://test_user:test_pass@test_host:3306/test_database?module=mysql',
      [
        'driver' => 'mysql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'port' => 3306,
        'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
        'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
      ],
    ],
    'PostgreSql without the module name set' => [
      'pgsql://test_user:test_pass@test_host/test_database',
      [
        'driver' => 'pgsql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'namespace' => 'Drupal\\pgsql\\Driver\\Database\\pgsql',
        'autoload' => 'core/modules/pgsql/src/Driver/Database/pgsql/',
      ],
    ],
    'PostgreSql with the module name pgsql' => [
      'pgsql://test_user:test_pass@test_host/test_database?module=pgsql',
      [
        'driver' => 'pgsql',
        'username' => 'test_user',
        'password' => 'test_pass',
        'host' => 'test_host',
        'database' => 'test_database',
        'namespace' => 'Drupal\\pgsql\\Driver\\Database\\pgsql',
        'autoload' => 'core/modules/pgsql/src/Driver/Database/pgsql/',
      ],
    ],
    'SQLite, relative to root, without prefix and with the module name sqlite' => [
      'sqlite://localhost/test_database?module=sqlite',
      [
        'driver' => 'sqlite',
        'host' => 'localhost',
        'database' => $root . '/test_database',
        'namespace' => 'Drupal\\sqlite\\Driver\\Database\\sqlite',
        'autoload' => 'core/modules/sqlite/src/Driver/Database/sqlite/',
      ],
    ],
  ];
}