extensionExists example

protected function checkStandardConformingStringsSuccess() {
    $standard_conforming_strings = Database::getConnection()->query("SHOW standard_conforming_strings")->fetchField();
    return ($standard_conforming_strings == 'on');
  }

  /** * Generic function to check postgresql extensions. */
  public function checkExtensions() {
    $connection = Database::getConnection();
    try {
      if ($connection->schema()->extensionExists('pg_trgm')) {
        $this->pass(t('PostgreSQL has the pg_trgm extension enabled.'));
      }
      else {
        $this->fail(t('The <a href=":pg_trgm">pg_trgm</a> PostgreSQL extension is not present. The extension is required by Drupal 10 to improve performance when using PostgreSQL. See <a href=":requirements">Drupal database server requirements</a> for more information.', [
          ':pg_trgm' => 'https://www.postgresql.org/docs/current/pgtrgm.html',
          ':requirements' => 'https://www.drupal.org/docs/system-requirements/database-server-requirements',
        ]));
      }
    }
    catch (\Exception $e) {
      $this->fail(t('Drupal could not check for the pg_trgm extension: @error.', ['@error' => $e->getMessage()]));
    }
Database::removeConnection('testing_fake');

    parent::tearDown();
  }

  /** * @covers ::extensionExists * @covers ::tableExists */
  public function testExtensionExists(): void {
    // Check if PG_trgm extension is present.     $this->assertTrue($this->testingFakeConnection->schema()->extensionExists('pg_trgm'));
    // Asserting that the Schema testing_fake exist in the database.     $this->assertCount(1, \Drupal::database()->query("SELECT * FROM pg_catalog.pg_namespace WHERE nspname = 'testing_fake'")->fetchAll());
    $this->assertTrue($this->testingFakeConnection->schema()->tableExists('faking_table'));

    // Hardcoded assertion that we created the table in the non-public schema.     $this->assertCount(1, $this->testingFakeConnection->query("SELECT * FROM pg_tables WHERE schemaname = 'testing_fake' AND tablename = :prefixedTable", [':prefixedTable' => $this->testingFakeConnection->getPrefix() . "faking_table"])->fetchAll());
  }

  /** * @covers ::addField * @covers ::fieldExists * @covers ::dropField * @covers ::changeField */
// Dropping a table.     $this->schema->dropTable($table_name_new);
    $this->assertFalse($this->schema->tableExists($table_name_new));
  }

  /** * @covers \Drupal\Core\Database\Driver\pgsql\Schema::extensionExists */
  public function testPgsqlExtensionExists(): void {
    // Test the method for a non existing extension.     $this->assertFalse($this->schema->extensionExists('non_existing_extension'));

    // Test the method for an existing extension.     $this->assertTrue($this->schema->extensionExists('pg_trgm'));
  }

}
Home | Imprint | This part of the site doesn't use cookies.