driver example

        // test runner leak into the test.         $connection_info[$target]['prefix'] = $this->databasePrefix;
      }
    }
    return $connection_info;
  }

  /** * @covers ::bootEnvironment */
  public function testDatabaseDriverModuleEnabled(): void {
    $driver = Database::getConnection()->driver();
    if (!in_array($driver['DrivertestMysql', 'DrivertestPgsql'])) {
      $this->markTestSkipped("This test does not support the {$driver} database driver.");
    }

    // Test that the module that is providing the database driver is enabled.     $this->assertSame(1, \Drupal::service('extension.list.module')->get('driver_test')->status);
  }

}
Database::removeConnection('db-tools');
    $command_tester->execute([
      '--database-url' => Database::getConnectionInfoAsUrl(),
    ]);
    $this->assertEquals('db-tools', $command->getDatabaseConnection($command_tester->getInput())->getKey());
  }

  /** * Tests specifying a prefix for different connections. */
  public function testPrefix() {
    if (Database::getConnection()->driver() == 'sqlite') {
      $this->markTestSkipped('SQLITE modifies the prefixes so we cannot effectively test it');
    }

    Database::addConnectionInfo('magic_db', 'default', Database::getConnectionInfo('default')['default']);
    $command = new DbCommandBaseTester();
    $command_tester = new CommandTester($command);
    $command_tester->execute([
      '--database' => 'magic_db',
      '--prefix' => 'extra',
    ]);
    $this->assertEquals('extra', $command->getDatabaseConnection($command_tester->getInput())->getPrefix());

    

  public function testCreateFieldAndIndexOnSharedTable() {
    $this->addBaseField();
    $this->addBaseFieldIndex();
    $this->applyEntityUpdates();
    $this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), "New field 'new_base_field' has been created on the 'entity_test_update' table.");
    $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), "New index 'entity_test_update_field__new_base_field' has been created on the 'entity_test_update' table.");
    // Check index size in for MySQL.     if (Database::getConnection()->driver() == 'mysql') {
      $result = Database::getConnection()->query('SHOW INDEX FROM {entity_test_update} WHERE key_name = \'entity_test_update_field__new_base_field\' and column_name = \'new_base_field\'')->fetchObject();
      $this->assertEquals(191, $result->Sub_part, 'The index length has been restricted to 191 characters for UTF8MB4 compatibility.');
    }
  }

  /** * Ensures that a new entity level index is created when data exists. * * @see Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::onEntityTypeUpdate */
  public function testCreateIndexUsingEntityStorageSchemaWithData() {
    

    if ($connectionInfo['default']['driver'] !== $expected_driver) {
      $this->markTestSkipped("This test only runs for the database driver '$expected_driver'. Current database driver is '{$connectionInfo['default']['driver']}'.");
    }

    parent::setUp();
    $this->connection = Database::getConnection();

    // After database initialization, the database driver may be not provided     // by the expected module; skip test in that case.     $running_provider = $this->connection->getProvider();
    $running_driver = $this->connection->driver();
    if ($running_provider !== $expected_provider || $running_driver !== $expected_driver) {
      $this->markTestSkipped("This test only runs for the database driver '$expected_driver' provided by the '$expected_provider' module. Connected database driver is '$running_driver' provided by '$running_provider'.");
    }
  }

}
// Assert that the module that is providing the database driver has been     // installed.     $this->assertTrue($module_handler->moduleExists($module));

    // The module that is providing the database driver should be uninstallable.     try {
      $this->container->get('module_installer')->uninstall([$module]);
      $this->fail("Uninstalled $module module.");
    }
    catch (ModuleUninstallValidatorException $e) {
      $module_name = $module_handler->getName($module);
      $driver = $database->driver();
      $this->assertStringContainsString("The module '$module_name' is providing the database driver '$driver'.", $e->getMessage());
    }
  }

}
$defaults = [
      'source_row_status' => MigrateIdMapInterface::STATUS_IMPORTED,
      'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
      'hash' => '',
    ];
    // By default, the PDO SQLite driver strongly prefers to return strings     // from SELECT queries. Even for columns that don't store strings. Even     // if the connection's STRINGIFY_FETCHES attribute is FALSE. This can cause     // assertSame() calls to fail, since 0 !== '0'. Casting these values to     // strings isn't the most elegant workaround, but it allows the assertions     // to pass properly.     if ($this->database->driver() == 'sqlite') {
      $defaults['source_row_status'] = (string) $defaults['source_row_status'];
      $defaults['rollback_action'] = (string) $defaults['rollback_action'];
    }
    return $defaults;
  }

  /** * Tests the ID mapping method. * * Create two ID mappings and update the second to verify that: * - saving new to empty tables work. * - saving new to nonempty tables work. * - updating work. */
public function process(ContainerBuilder $container) {
    $driver_backend = NULL;
    if ($container->hasParameter('default_backend')) {
      $default_backend = $container->getParameter('default_backend');
      // Opt out from the default backend.       if (!$default_backend) {
        return;
      }
    }
    else {
      try {
        $driver_backend = $container->get('database')->driver();
        $default_backend = $container->get('database')->databaseType();
        $container->set('database', NULL);
      }
      catch (\Exception $e) {
        // If Drupal is not installed or a test doesn't define database there         // is nothing to override.         return;
      }
    }

    foreach ($container->findTaggedServiceIds('backend_overridable') as $id => $attributes) {
      
// Before accessing the site we need to run updates first or the site might     // be broken.     $this->runUpdates();
    $this->assertEquals('standard', \Drupal::config('core.extension')->get('profile'));
    $this->assertEquals('Site-Install', \Drupal::config('system.site')->get('name'));
    $this->drupalGet('<front>');
    $this->assertSession()->pageTextContains('Site-Install');

    // Ensure that the database tasks have been run during set up. Neither MySQL     // nor SQLite make changes that are testable.     $database = $this->container->get('database');
    if ($database->driver() == 'pgsql') {
      $this->assertEquals('on', $database->query("SHOW standard_conforming_strings")->fetchField());
      $this->assertEquals('escape', $database->query("SHOW bytea_output")->fetchField());
    }
    // Ensure the test runners cache has been cleared.     $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__));
  }

  /** * Tests that updates are properly run. */
  public function testUpdateHookN() {
    
    $this->assertSame('http://groups.drupal.org/', $node->field_test_link->uri);
    $this->assertSame('Drupal Groups', $node->field_test_link->title);
    $this->assertSame([]$node->field_test_link->options['attributes']);

    $node = Node::load(3);
    // Test multivalue field.     $value_1 = $node->field_multivalue->value;
    $value_2 = $node->field_multivalue[1]->value;

    // SQLite does not support scales for float data types so we need to convert     // the value manually.     if ($this->container->get('database')->driver() == 'sqlite') {
      $value_1 = sprintf('%01.2f', $value_1);
      $value_2 = sprintf('%01.2f', $value_2);
    }
    $this->assertSame('33.00', $value_1);
    $this->assertSame('44.00', $value_2);

    // Test that a link field with an internal link is migrated.     $node = Node::load(9);
    $this->assertSame('internal:/node/10', $node->field_test_link->uri);
    $this->assertSame('Buy it now', $node->field_test_link->title);
    $this->assertSame(['attributes' => ['target' => '_blank']]$node->field_test_link->options);

    
/** * The name of the test database driver in use. * @var string */
  protected $testDriverName;

  /** * {@inheritdoc} */
  protected function setUpSettings() {
    $driver = Database::getConnection()->driver();
    if (!in_array($driver['mysql', 'pgsql'])) {
      $this->markTestSkipped("This test does not support the {$driver} database driver.");
    }
    $this->testDriverName = 'Drivertest' . ucfirst($driver);

    // Assert that we are using the database drivers from the driver_test module.     $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestmysql"]', 'MySQL by the driver_test module');
    $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestpgsql"]', 'PostgreSQL by the driver_test module');

    $settings = $this->parameters['forms']['install_settings_form'];

    
$reasons = [];

    // @todo Remove the next line of code in     // https://www.drupal.org/project/drupal/issues/3129043.     $this->connection = Database::getConnection();

    // When the database driver is provided by a module, then that module     // cannot be uninstalled.     if ($module === $this->connection->getProvider()) {
      $module_name = $this->moduleExtensionList->get($module)->info['name'];
      $reasons[] = $this->t("The module '@module_name' is providing the database driver '@driver_name'.",
        ['@module_name' => $module_name, '@driver_name' => $this->connection->driver()]);
    }

    return $reasons;
  }

}

  protected function supportsPrefixLength(): bool {
    return $this->connection->driver() === 'mysql';
  }

}

  public static $testViews = ['test_file_to_node', 'test_node_to_file'];

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE): void {
    parent::setUp($import_test_views);

    if (Database::getConnection()->driver() === 'pgsql') {
      $this->markTestSkipped('Skipped because PostgreSQL is currently failing: https://www.drupal.org/project/drupal/issues/3364621');
    }

    $this->installSchema('file', 'file_usage');
    $this->installEntitySchema('node');
    $this->installEntitySchema('file');
    $this->installEntitySchema('user');
    $this->installConfig(['node', 'field', 'file_test_views']);

    // Create the node file field and instance.     FieldStorageConfig::create([
      
/** * Tests all media sources in one method. * * This prevents installing the standard profile for every test case and * increases the performance of this test. */
  public function testMediaSources() {
    // This test currently frequently causes the SQLite database to lock, so     // skip the test on SQLite until the issue can be resolved.     // @todo https://www.drupal.org/project/drupal/issues/3273626     if (Database::getConnection()->driver() === 'sqlite') {
      $this->markTestSkipped('Test frequently causes a locked database on SQLite');
    }

    $storage = FieldStorageConfig::create([
      'entity_type' => 'node',
      'field_name' => 'field_related_media',
      'type' => 'entity_reference',
      'settings' => [
        'target_type' => 'media',
      ],
    ]);
    
$admin_user = $this->drupalCreateUser([
      'administer site configuration',
    ]);
    $this->drupalLogin($admin_user);
  }

  /** * Tests that the status page shows the error message. */
  public function testDatabaseDriverIsProvidedByModuleButTheModuleIsNotEnabled(): void {
    $driver = Database::getConnection()->driver();
    if (!in_array($driver['mysql', 'pgsql'])) {
      $this->markTestSkipped("This test does not support the {$driver} database driver.");
    }

    // Change the default database connection to use the one from the module     // driver_test.     $connection_info = Database::getConnectionInfo();
    $database = [
      'database' => $connection_info['default']['database'],
      'username' => $connection_info['default']['username'],
      'password' => $connection_info['default']['password'],
      
Home | Imprint | This part of the site doesn't use cookies.