function UrlConversionTest::providerGetConnectionInfoAsUrl

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php \Drupal\Tests\Core\Database\UrlConversionTest::providerGetConnectionInfoAsUrl()
  2. 10 core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php \Drupal\Tests\Core\Database\UrlConversionTest::providerGetConnectionInfoAsUrl()
  3. 11.x core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php \Drupal\Tests\Core\Database\UrlConversionTest::providerGetConnectionInfoAsUrl()

Dataprovider 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 259

Class

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

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';
    $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#pre';
    $info3 = [
        'database' => 'test_database',
        'driver' => 'sqlite',
    ];
    $expected_url3 = 'sqlite://localhost/test_database';
    $info4 = [
        'database' => 'test_database',
        'driver' => 'sqlite',
        'prefix' => 'pre',
    ];
    $expected_url4 = 'sqlite://localhost/test_database#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,
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.