class PostgresqlConnectionTest in Drupal 8
@coversDefaultClass \Drupal\Core\Database\Driver\pgsql\Connection @group Database
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Database\Driver\pgsql\PostgresqlConnectionTest
Expanded class hierarchy of PostgresqlConnectionTest
File
- core/
tests/ Drupal/ Tests/ Core/ Database/ Driver/ pgsql/ PostgresqlConnectionTest.php, line 12
Namespace
Drupal\Tests\Core\Database\Driver\pgsqlView source
class PostgresqlConnectionTest extends UnitTestCase {
/**
* Mock PDO object for use in tests.
*
* @var \PHPUnit\Framework\MockObject\MockObject|\Drupal\Tests\Core\Database\Stub\StubPDO
*/
protected $mockPdo;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->mockPdo = $this
->createMock('Drupal\\Tests\\Core\\Database\\Stub\\StubPDO');
}
/**
* Data provider for testEscapeTable.
*
* @return array
* An indexed array of where each value is an array of arguments to pass to
* testEscapeField. The first value is the expected value, and the second
* value is the value to test.
*/
public function providerEscapeTables() {
return [
[
'nocase',
'nocase',
],
[
'"camelCase"',
'camelCase',
],
[
'"camelCase"',
'"camelCase"',
],
[
'"camelCase"',
'camel/Case',
],
// Sometimes, table names are following the pattern database.schema.table.
[
'"camelCase".nocase.nocase',
'camelCase.nocase.nocase',
],
[
'nocase."camelCase".nocase',
'nocase.camelCase.nocase',
],
[
'nocase.nocase."camelCase"',
'nocase.nocase.camelCase',
],
[
'"camelCase"."camelCase"."camelCase"',
'camelCase.camelCase.camelCase',
],
];
}
/**
* Data provider for testEscapeAlias.
*
* @return array
* Array of arrays with the following elements:
* - Expected escaped string.
* - String to escape.
*/
public function providerEscapeAlias() {
return [
[
'nocase',
'nocase',
],
[
'"camelCase"',
'"camelCase"',
],
[
'"camelCase"',
'camelCase',
],
[
'"camelCase"',
'camel.Case',
],
];
}
/**
* Data provider for testEscapeField.
*
* @return array
* Array of arrays with the following elements:
* - Expected escaped string.
* - String to escape.
*/
public function providerEscapeFields() {
return [
[
'title',
'title',
],
[
'"isDefaultRevision"',
'isDefaultRevision',
],
[
'"isDefaultRevision"',
'"isDefaultRevision"',
],
[
'entity_test."isDefaultRevision"',
'entity_test.isDefaultRevision',
],
[
'entity_test."isDefaultRevision"',
'"entity_test"."isDefaultRevision"',
],
[
'"entityTest"."isDefaultRevision"',
'"entityTest"."isDefaultRevision"',
],
[
'"entityTest"."isDefaultRevision"',
'entityTest.isDefaultRevision',
],
[
'entity_test."isDefaultRevision"',
'entity_test.is.Default.Revision',
],
];
}
/**
* @covers ::escapeTable
* @dataProvider providerEscapeTables
*/
public function testEscapeTable($expected, $name) {
$pgsql_connection = new Connection($this->mockPdo, []);
$this
->assertEquals($expected, $pgsql_connection
->escapeTable($name));
}
/**
* @covers ::escapeAlias
* @dataProvider providerEscapeAlias
*/
public function testEscapeAlias($expected, $name) {
$pgsql_connection = new Connection($this->mockPdo, []);
$this
->assertEquals($expected, $pgsql_connection
->escapeAlias($name));
}
/**
* @covers ::escapeField
* @dataProvider providerEscapeFields
*/
public function testEscapeField($expected, $name) {
$pgsql_connection = new Connection($this->mockPdo, []);
$this
->assertEquals($expected, $pgsql_connection
->escapeField($name));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
PostgresqlConnectionTest:: |
protected | property | Mock PDO object for use in tests. | |
PostgresqlConnectionTest:: |
public | function | Data provider for testEscapeAlias. | |
PostgresqlConnectionTest:: |
public | function | Data provider for testEscapeField. | |
PostgresqlConnectionTest:: |
public | function | Data provider for testEscapeTable. | |
PostgresqlConnectionTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PostgresqlConnectionTest:: |
public | function | @covers ::escapeAlias @dataProvider providerEscapeAlias | |
PostgresqlConnectionTest:: |
public | function | @covers ::escapeField @dataProvider providerEscapeFields | |
PostgresqlConnectionTest:: |
public | function | @covers ::escapeTable @dataProvider providerEscapeTables | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |