function SchemaTest::testTableExists

Same name and namespace in other branches
  1. 10 core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php \Drupal\Tests\pgsql\Kernel\pgsql\SchemaTest::testTableExists()

Tests the method tableExists().

File

core/modules/pgsql/tests/src/Kernel/pgsql/SchemaTest.php, line 315

Class

SchemaTest
Tests schema API for the PostgreSQL driver.

Namespace

Drupal\Tests\pgsql\Kernel\pgsql

Code

public function testTableExists() : void {
    $table_name = 'test_table';
    $table_specification = [
        'fields' => [
            'id' => [
                'type' => 'int',
                'default' => NULL,
            ],
        ],
    ];
    $this->schema
        ->createTable($table_name, $table_specification);
    $prefixed_table_name = $this->connection
        ->getPrefix($table_name) . $table_name;
    // Three different calls to the method Schema::tableExists() with an
    // unprefixed table name.
    $this->assertTrue($this->schema
        ->tableExists($table_name));
    $this->assertTrue($this->schema
        ->tableExists($table_name, TRUE));
    $this->assertFalse($this->schema
        ->tableExists($table_name, FALSE));
    // Three different calls to the method Schema::tableExists() with a
    // prefixed table name.
    $this->assertFalse($this->schema
        ->tableExists($prefixed_table_name));
    $this->assertFalse($this->schema
        ->tableExists($prefixed_table_name, TRUE));
    $this->assertTrue($this->schema
        ->tableExists($prefixed_table_name, FALSE));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.