You are here

public function UrlConversionTest::providerGetConnectionInfoAsUrl 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::providerGetConnectionInfoAsUrl()
  2. 9 core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php \Drupal\Tests\Core\Database\UrlConversionTest::providerGetConnectionInfoAsUrl()

Data provider for testGetConnectionInfoAsUrl().

Return value

array Array of arrays with the following elements:

  • An array mocking the database connection info. Possible keys are database, username, password, prefix, host, port, namespace and driver.
  • The expected URL after conversion.

File

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

Class

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

Namespace

Drupal\Tests\Core\Database

Code

public function providerGetConnectionInfoAsUrl() {
  $info1 = [
    'database' => 'test_database',
    'username' => 'test_user',
    'password' => 'test_pass',
    'prefix' => '',
    'host' => 'test_host',
    'port' => '3306',
    'driver' => 'mysql',
  ];
  $expected_url1 = 'mysql://test_user:test_pass@test_host:3306/test_database?module=mysql';
  $info2 = [
    'database' => 'test_database',
    'username' => 'test_user',
    'password' => 'test_pass',
    'prefix' => 'pre',
    'host' => 'test_host',
    'port' => '3306',
    'driver' => 'mysql',
  ];
  $expected_url2 = 'mysql://test_user:test_pass@test_host:3306/test_database?module=mysql#pre';
  $info3 = [
    'database' => 'test_database',
    'driver' => 'sqlite',
  ];
  $expected_url3 = 'sqlite://localhost/test_database?module=sqlite';
  $info4 = [
    'database' => 'test_database',
    'driver' => 'sqlite',
    'prefix' => 'pre',
  ];
  $expected_url4 = 'sqlite://localhost/test_database?module=sqlite#pre';
  $info5 = [
    'database' => 'test_database',
    'username' => 'test_user',
    'password' => 'test_pass',
    'prefix' => '',
    'host' => 'test_host',
    'port' => '3306',
    'driver' => 'DrivertestMysql',
    'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestMysql',
    'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/',
  ];
  $expected_url5 = 'DrivertestMysql://test_user:test_pass@test_host:3306/test_database?module=driver_test';
  $info6 = [
    'database' => 'test_database',
    'username' => 'test_user',
    'password' => 'test_pass',
    'prefix' => 'pre',
    'host' => 'test_host',
    'port' => '3306',
    'driver' => 'DrivertestMysql',
    'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestMysql',
    'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/',
  ];
  $expected_url6 = 'DrivertestMysql://test_user:test_pass@test_host:3306/test_database?module=driver_test#pre';
  $info7 = [
    'database' => 'test_database',
    'username' => 'test_user',
    'password' => 'test_pass',
    'prefix' => '',
    'host' => 'test_host',
    'port' => '5432',
    'driver' => 'DrivertestPgsql',
    'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestPgsql',
    'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/drivertestpqsql/',
  ];
  $expected_url7 = 'DrivertestPgsql://test_user:test_pass@test_host:5432/test_database?module=driver_test';
  $info8 = [
    'database' => 'test_database',
    'username' => 'test_user',
    'password' => 'test_pass',
    'prefix' => 'pre',
    'host' => 'test_host',
    'port' => '5432',
    'driver' => 'DrivertestPgsql',
    'namespace' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestPgsql',
    'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/drivertestpqsql/',
  ];
  $expected_url8 = 'DrivertestPgsql://test_user:test_pass@test_host:5432/test_database?module=driver_test#pre';
  return [
    [
      $info1,
      $expected_url1,
    ],
    [
      $info2,
      $expected_url2,
    ],
    [
      $info3,
      $expected_url3,
    ],
    [
      $info4,
      $expected_url4,
    ],
    [
      $info5,
      $expected_url5,
    ],
    [
      $info6,
      $expected_url6,
    ],
    [
      $info7,
      $expected_url7,
    ],
    [
      $info8,
      $expected_url8,
    ],
  ];
}