You are here

class PostgresqlConnectionTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Database/Driver/pgsql/PostgresqlConnectionTest.php \Drupal\Tests\Core\Database\Driver\pgsql\PostgresqlConnectionTest

@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 16
Contains \Drupal\Tests\Core\Database\Driver\pgsql\PostgresqlConnectionTest.

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
      ->getMock('Drupal\\Tests\\Core\\Database\\Stub\\StubPDO');
  }

  /**
   * Data provider for testEscapeTable.
   *
   * @return []
   *   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 array(
      array(
        'nocase',
        'nocase',
      ),
      array(
        '"camelCase"',
        'camelCase',
      ),
      array(
        '"camelCase"',
        '"camelCase"',
      ),
      array(
        '"camelCase"',
        'camel/Case',
      ),
    );
  }

  /**
   * Data provider for testEscapeAlias.
   *
   * @return []
   *   Array of arrays with the following elements:
   *   - Expected escaped string.
   *   - String to escape.
   */
  public function providerEscapeAlias() {
    return array(
      array(
        'nocase',
        'nocase',
      ),
      array(
        '"camelCase"',
        '"camelCase"',
      ),
      array(
        '"camelCase"',
        'camelCase',
      ),
      array(
        '"camelCase"',
        'camel.Case',
      ),
    );
  }

  /**
   * Data provider for testEscapeField.
   *
   * @return []
   *   Array of arrays with the following elements:
   *   - Expected escaped string.
   *   - String to escape.
   */
  public function providerEscapeFields() {
    return array(
      array(
        'title',
        'title',
      ),
      array(
        '"isDefaultRevision"',
        'isDefaultRevision',
      ),
      array(
        '"isDefaultRevision"',
        '"isDefaultRevision"',
      ),
      array(
        'entity_test."isDefaultRevision"',
        'entity_test.isDefaultRevision',
      ),
      array(
        'entity_test."isDefaultRevision"',
        '"entity_test"."isDefaultRevision"',
      ),
      array(
        '"entityTest"."isDefaultRevision"',
        '"entityTest"."isDefaultRevision"',
      ),
      array(
        '"entityTest"."isDefaultRevision"',
        'entityTest.isDefaultRevision',
      ),
      array(
        '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
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.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in 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.