You are here

class PostgresqlSchemaTest in Zircon Profile 8

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

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

Hierarchy

Expanded class hierarchy of PostgresqlSchemaTest

File

core/tests/Drupal/Tests/Core/Database/Driver/pgsql/PostgresqlSchemaTest.php, line 16
Contains \Drupal\Tests\Core\Database\Driver\pgsql\PostgresqlSchemaTest.

Namespace

Drupal\Tests\Core\Database\Driver\pgsql
View source
class PostgresqlSchemaTest extends UnitTestCase {

  /**
   * The PostgreSql DB connection.
   *
   * @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\Database\Driver\pgsql\Connection
   */
  protected $connection;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->connection = $this
      ->getMockBuilder('\\Drupal\\Core\\Database\\Driver\\pgsql\\Connection')
      ->disableOriginalConstructor()
      ->getMock();
  }

  /**
   * Tests whether the actual constraint name is correctly computed.
   *
   * @param string $table_name
   *   The table name the constrained column belongs to.
   * @param string $name
   *   The constraint name.
   * @param string $expected
   *   The expected computed constraint name.
   *
   * @covers ::constraintExists
   * @dataProvider providerComputedConstraintName
   */
  public function testComputedConstraintName($table_name, $name, $expected) {
    $max_identifier_length = 63;
    $schema = new Schema($this->connection);
    $statement = $this
      ->getMock('\\Drupal\\Core\\Database\\StatementInterface');
    $statement
      ->expects($this
      ->any())
      ->method('fetchField')
      ->willReturn($max_identifier_length);
    $this->connection
      ->expects($this
      ->any())
      ->method('query')
      ->willReturn($statement);
    $this->connection
      ->expects($this
      ->at(2))
      ->method('query')
      ->with("SELECT 1 FROM pg_constraint WHERE conname = '{$expected}'")
      ->willReturn($this
      ->getMock('\\Drupal\\Core\\Database\\StatementInterface'));
    $schema
      ->constraintExists($table_name, $name);
  }

  /**
   * Data provider for ::testComputedConstraintName().
   */
  public function providerComputedConstraintName() {
    return [
      [
        'user_field_data',
        'pkey',
        'user_field_data____pkey',
      ],
      [
        'user_field_data',
        'name__key',
        'user_field_data__name__key',
      ],
      [
        'user_field_data',
        'a_veeeery_veery_very_super_long_field_name__key',
        'drupal_BGGYAXgbqlAF1rMOyFTdZGj9zIMXZtSvEjMAKZ9wGIk_key',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PostgresqlSchemaTest::$connection protected property The PostgreSql DB connection.
PostgresqlSchemaTest::providerComputedConstraintName public function Data provider for ::testComputedConstraintName().
PostgresqlSchemaTest::setUp protected function Overrides UnitTestCase::setUp
PostgresqlSchemaTest::testComputedConstraintName public function Tests whether the actual constraint name is correctly computed.
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.