You are here

class PostgresqlConnectionTest in Drupal 8

@coversDefaultClass \Drupal\Core\Database\Driver\pgsql\Connection @group Database

Hierarchy

Expanded class hierarchy of PostgresqlConnectionTest

File

core/tests/Drupal/Tests/Core/Database/Driver/pgsql/PostgresqlConnectionTest.php, line 12

Namespace

Drupal\Tests\Core\Database\Driver\pgsql
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
PostgresqlConnectionTest::$mockPdo protected property Mock PDO object for use in tests.
PostgresqlConnectionTest::providerEscapeAlias public function Data provider for testEscapeAlias.
PostgresqlConnectionTest::providerEscapeFields public function Data provider for testEscapeField.
PostgresqlConnectionTest::providerEscapeTables public function Data provider for testEscapeTable.
PostgresqlConnectionTest::setUp protected function Overrides UnitTestCase::setUp
PostgresqlConnectionTest::testEscapeAlias public function @covers ::escapeAlias @dataProvider providerEscapeAlias
PostgresqlConnectionTest::testEscapeField public function @covers ::escapeField @dataProvider providerEscapeFields
PostgresqlConnectionTest::testEscapeTable public function @covers ::escapeTable @dataProvider providerEscapeTables
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.