summaryrefslogtreecommitdiffstats
path: root/core/tests/Drupal/Tests/Core/Database/Driver/pgsql/PostgresqlConnectionTest.php
blob: 2bf263962d9de300e9ff87a2d14d7ea072a5b24e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php

namespace Drupal\Tests\Core\Database\Driver\pgsql;

use Drupal\Core\Database\Driver\pgsql\Connection;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\Core\Database\Driver\pgsql\Connection
 * @group Database
 */
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));
  }

}