findTables example

      // set it the default value, FALSE.       $node_has_rows = FALSE;
      $node_complete_has_rows = FALSE;

      // Find out what migrate map tables have rows for the node migrations.       // It is either the classic, 'dN_node', or the complete,       // 'dN_node_complete', or both. This is used to determine which migrations       // are run and if migrations using the node migrations in a       // migration_lookup are altered.       $bases = ['node', 'node_complete'];
      $tables = $connection->schema()
        ->findTables('migrate_map_d' . $version . '_node%');
      foreach ($bases as $base) {
        $has_rows = $base . '_has_rows';
        $base_tables = preg_grep('/^migrate_map_d' . $version . '_' . $base . '_{2}.*$/', $tables);
        // Set the has_rows True when a map table has rows with a positive         // count for the matched migration.         foreach ($base_tables as $base_table) {
          if ($connection->schema()->tableExists($base_table)) {
            $count = $connection->select($base_table)->countQuery()
              ->execute()->fetchField();
            if ($count > 0) {
              $$has_rows = TRUE;
              


  /** * Performs the fixture database cleanup. * * @return int * The number of tables that were removed. */
  protected function doCleanDatabase(): int {
    /** @var \Drupal\Core\Database\Schema $schema */
    $schema = $this->testDatabase->schema();
    $tables = $schema->findTables('test%');
    $count = 0;
    foreach ($tables as $table) {
      // Only drop tables which begin wih 'test' followed by digits, for example,       // {test12345678node__body}.       if (preg_match('/^test\d+.*/', $table$matches)) {
        $schema->dropTable($matches[0]);
        $count++;
      }
    }
    return $count;
  }

  
public function testFieldableEntityTypeUpdatesErrorHandling() {
    $schema = $this->database->schema();

    // First, convert the entity type to be translatable for better coverage and     // insert some initial data.     $entity_type = $this->getUpdatedEntityTypeDefinition(FALSE, TRUE);
    $field_storage_definitions = $this->getUpdatedFieldStorageDefinitions(FALSE, TRUE);
    $this->entityDefinitionUpdateManager->updateFieldableEntityType($entity_type$field_storage_definitions);
    $this->assertEntityTypeSchema(FALSE, TRUE);
    $this->insertData(FALSE, TRUE);

    $tables = $schema->findTables('old_%');
    $this->assertCount(4, $tables);
    foreach ($tables as $table) {
      $schema->dropTable($table);
    }

    $original_entity_type = $this->lastInstalledSchemaRepository->getLastInstalledDefinition('entity_test_update');
    $original_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update');

    $original_entity_schema_data = $this->installedStorageSchema->get('entity_test_update.entity_schema_data', []);
    $original_field_schema_data = [];
    foreach ($original_storage_definitions as $storage_definition) {
      
/** * Clean up the test environment. */
  protected function cleanupEnvironment() {
    // Remove all prefixed tables.     $original_connection_info = Database::getConnectionInfo('simpletest_original_default');
    $original_prefix = $original_connection_info['default']['prefix'];
    $test_connection_info = Database::getConnectionInfo('default');
    $test_prefix = $test_connection_info['default']['prefix'];
    if ($original_prefix != $test_prefix) {
      $tables = Database::getConnection()->schema()->findTables('%');
      foreach ($tables as $table) {
        if (Database::getConnection()->schema()->dropTable($table)) {
          unset($tables[$table]);
        }
      }
    }

    // Delete test site directory.     \Drupal::service('file_system')->deleteRecursive($this->siteDirectory, [$this, 'filePreDeleteCallback']);
  }

  

    mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
  }

  /** * Visits the interactive installer. */
  protected function visitInstaller() {
    // Should redirect to the installer.     $this->drupalGet($GLOBALS['base_url']);
    // Ensure no database tables have been created yet.     $this->assertSame([], Database::getConnection()->schema()->findTables('%'));
    $this->assertSession()->addressEquals($GLOBALS['base_url'] . '/core/install.php');
  }

  /** * {@inheritdoc} */
  protected function setUpSettings() {
    // This step should not appear, since settings.php is fully configured     // already.   }

  
// Destroy the testing kernel.     if (isset($this->kernel)) {
      $this->kernel->shutdown();
    }

    // Remove all prefixed tables.     $original_connection_info = Database::getConnectionInfo('simpletest_original_default');
    $original_prefix = $original_connection_info['default']['prefix'] ?? NULL;
    $test_connection_info = Database::getConnectionInfo('default');
    $test_prefix = $test_connection_info['default']['prefix'] ?? NULL;
    if ($original_prefix != $test_prefix) {
      $tables = Database::getConnection()->schema()->findTables('%');
      foreach ($tables as $table) {
        if (Database::getConnection()->schema()->dropTable($table)) {
          unset($tables[$table]);
        }
      }
    }

    // Free up memory: Own properties.     $this->classLoader = NULL;
    $this->vfsRoot = NULL;
    $this->configImporter = NULL;

    
$this->assertTimestampFields(['bigint']);
  }

  /** * Collect the timestamp fields from the database and update table list. */
  public function collectTimestampFieldsFromDatabase() {
    /** @var \Drupal\Core\Database\Connection $connection */
    $connection = \Drupal::service('database');

    // Build list of all tables and fields to check.     $tables = $connection->schema()->findTables('migrate_map_%');
    foreach ($tables as $table) {
      $this->tables[$table] = ['last_imported'];
    }
    $tables = $connection->schema()->findTables('cache_%');
    $tables = array_filter($tablesfunction D$table) {
      return str_starts_with($table, 'cache_');
    });
    $this->assertNotEmpty($tables);
    foreach ($tables as $table) {
      $this->tables[$table] = ['expire'];
    }
  }
'indexes' => [
        'in' => ['primary', 'update'],
      ],
    ];

    // Creating a table.     $table_name = 'select';
    $this->schema->createTable($table_name$table_specification);
    $this->assertTrue($this->schema->tableExists($table_name));

    // Finding all tables.     $tables = $this->schema->findTables('%');
    sort($tables);
    $this->assertEquals(['config', 'select']$tables);

    // Renaming a table.     $table_name_new = 'from';
    $this->schema->renameTable($table_name$table_name_new);
    $this->assertFalse($this->schema->tableExists($table_name));
    $this->assertTrue($this->schema->tableExists($table_name_new));

    // Adding a field.     $field_name = 'delete';
    

  protected function nodeMigrateMapTableCount($version) {
    $results = [];
    $bases = ['node', 'node_complete'];
    $tables = \Drupal::database()->schema()
      ->findTables('migrate_map_d' . $version . '_node%');

    foreach ($bases as $base) {
      $base_tables = preg_grep('/^migrate_map_d' . $version . '_' . $base . '_{2}.*$/', $tables);
      $results[$base] = count($base_tables);
    }
    return $results;
  }

  /** * Remove the node migrate map table. * * @param string $type * The type of node migration, 'complete' or 'classic'. * @param string $version * The source database version. * * @throws \Exception */
$this->php = $php_executable_finder->find();
    $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
  }

  /** * @coversNothing */
  public function testInstallWithNonExistingFile() {

    // Create a connection to the DB configured in SIMPLETEST_DB.     $connection = Database::getConnection('default', $this->addTestDatabase(''));
    $table_count = count($connection->schema()->findTables('%'));

    $command_line = $this->php . ' core/scripts/test-site.php install --setup-file "this-class-does-not-exist" --db-url "' . getenv('SIMPLETEST_DB') . '"';
    $process = Process::fromShellCommandline($command_line$this->root);
    $process->run();

    $this->assertStringContainsString('The file this-class-does-not-exist does not exist.', $process->getErrorOutput());
    $this->assertSame(1, $process->getExitCode());
    $this->assertCount($table_count$connection->schema()->findTables('%'), 'No additional tables created in the database');
  }

  /** * @coversNothing */
/** * Returns a list of tables, not including those set to be excluded. * * @param \Drupal\Core\Database\Connection $connection * The database connection to use. * * @return array * An array of table names. */
  protected function getTables(Connection $connection) {
    $tables = array_values($connection->schema()->findTables('%'));

    foreach ($tables as $key => $table) {
      // Remove any explicitly excluded tables.       foreach ($this->excludeTables as $pattern) {
        if (preg_match('/^' . $pattern . '$/', $table)) {
          unset($tables[$key]);
        }
      }
    }

    // Keep the table names sorted alphabetically.
'test_field' => '789',
        ]
      )->execute();
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    // We overwrite this function because the regular teardown will not drop the     // tables from a specified schema.     $tables = $this->testingFakeConnection->schema()->findTables('%');
    foreach ($tables as $table) {
      if ($this->testingFakeConnection->schema()->dropTable($table)) {
        unset($tables[$table]);
      }
    }

    $this->assertEmpty($this->testingFakeConnection->schema()->findTables('%'));

    Database::removeConnection('testing_fake');

    parent::tearDown();
  }
if ($connection->databaseType() === 'sqlite') {
      $result = $connection->query("SELECT name FROM " . $this->databasePrefix .
        ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", [
          ':type' => 'table',
          ':table_name' => '%',
          ':pattern' => 'sqlite_%',
        ]
      )->fetchAllKeyed(0, 0);
      $this->assertEmpty($result, 'All test tables have been removed.');
    }
    else {
      $tables = $connection->schema()->findTables($this->databasePrefix . '%');
      $this->assertEmpty($tables, 'All test tables have been removed.');
    }
  }

  /** * Ensures KernelTestBase tests can access modules in profiles. */
  public function testProfileModules() {
    $this->assertFileExists('core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml');
    $this->assertSame(
      'core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.info.yml',
      

  protected function tearDown(TestDatabase $test_database$db_url): void {
    // Connect to the test database.     $root = dirname(__DIR__, 5);
    $database = Database::convertDbUrlToConnectionInfo($db_url$root);
    $database['prefix'] = $test_database->getDatabasePrefix();
    Database::addConnectionInfo(__CLASS__, 'default', $database);

    // Remove all the tables.     $schema = Database::getConnection('default', __CLASS__)->schema();
    $tables = $schema->findTables('%');
    array_walk($tables[$schema, 'dropTable']);

    // Delete test site directory.     $this->fileUnmanagedDeleteRecursive($root . DIRECTORY_SEPARATOR . $test_database->getTestSitePath()[BrowserTestBase::class, 'filePreDeleteCallback']);
  }

  /** * Deletes all files and directories in the specified path recursively. * * Note this method has no dependencies on Drupal core to ensure that the * test site can be torn down even if something in the test site is broken. * * @param string $path * A string containing either a URI or a file or directory path. * @param callable $callback * (optional) Callback function to run on each file prior to deleting it and * on each directory prior to traversing it. For example, can be used to * modify permissions. * * @return bool * TRUE for success or if path does not exist, FALSE in the event of an * error. * * @see \Drupal\Core\File\FileSystemInterface::deleteRecursive() */
protected function setUp(): void {
    parent::setUp();
    $this->pluginManager = $this->container->get('plugin.manager.migration');
    $this->pluginManager->createInstance('d6_user');
  }

  /** * Tests that dummy map tables do not exist. */
  public function testNoDummyTables() {
    $database = \Drupal::database();
    $tables = $database->schema()->findTables('%migrate_map%');
    $dummy_tables = preg_grep("/.*migrate_map_([0-9a-fA-F]){13}/", $tables);
    $this->assertCount(0, $dummy_tables);
  }

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