Revert "Issue #3152398 by Hardik_Patel_12, ravi.shankar, rajandro, siddhant.bhosale, daffie, mondrake, mondrake, longwave, voleger, andypost, catch, Berdir: Change static queries to dynamic queries in core/tests/Drupal"

This reverts commit 65656ac660.
merge-requests/2/head
Alex Pott 2020-07-15 12:17:40 +01:00
parent 02d4434789
commit a178f53372
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
10 changed files with 29 additions and 59 deletions

View File

@ -24,17 +24,7 @@ class InstallerDatabaseErrorMessagesTest extends InstallerTestBase {
// it will try and create the drupal_install_test table as this is part of
// the standard database tests performed by the installer in
// Drupal\Core\Database\Install\Tasks.
$spec = [
'fields' => [
'id' => [
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => ['id'],
];
Database::getConnection('default')->schema()->createTable('drupal_install_test', $spec);
Database::getConnection('default')->query('CREATE TABLE {drupal_install_test} (id int NOT NULL PRIMARY KEY)');
parent::setUpSettings();
}

View File

@ -53,17 +53,7 @@ class InstallerTranslationTest extends InstallerTestBase {
// it will try and create the drupal_install_test table as this is part of
// the standard database tests performed by the installer in
// Drupal\Core\Database\Install\Tasks.
$spec = [
'fields' => [
'id' => [
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => ['id'],
];
Database::getConnection('default')->schema()->createTable('drupal_install_test', $spec);
Database::getConnection('default')->query('CREATE TABLE {drupal_install_test} (id int NOT NULL PRIMARY KEY)');
parent::setUpSettings();
// Ensure that the error message translation is working.
@ -73,7 +63,7 @@ class InstallerTranslationTest extends InstallerTestBase {
// cSpell:enable
// Now do it successfully.
Database::getConnection('default')->schema()->dropTable('drupal_install_test');
Database::getConnection('default')->query('DROP TABLE {drupal_install_test}');
parent::setUpSettings();
}

View File

@ -41,10 +41,7 @@ class UpdatePathTestBaseTest extends UpdatePathTestBase {
// Ensure that all {router} entries can be unserialized. If they cannot be
// unserialized a notice will be thrown by PHP.
$result = \Drupal::database()->select('router', 'r')
->fields('r', ['name', 'route'])
->execute()
->fetchAllKeyed(0, 1);
$result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1);
// For the purpose of fetching the notices and displaying more helpful error
// messages, let's override the error handler temporarily.
set_error_handler(function ($severity, $message, $filename, $lineno) {

View File

@ -213,7 +213,7 @@ class DbDumpTest extends KernelTestBase {
}
// Ensure the test config has been replaced.
$config = unserialize($connection->select('config', 'c')->fields('c', ['data'])->condition('name', 'test_config')->execute()->fetchField());
$config = unserialize($connection->query("SELECT data FROM {config} WHERE name = 'test_config'")->fetchField());
$this->assertIdentical($config, $this->data, 'Script has properly restored the config table data.');
// Ensure the cache data was not exported.

View File

@ -26,7 +26,7 @@ class DatabaseStorageTest extends ConfigStorageTestBase {
}
protected function read($name) {
$data = Database::getConnection()->select('config', 'c')->fields('c', ['data'])->condition('name', $name)->execute()->fetchField();
$data = Database::getConnection()->query('SELECT data FROM {config} WHERE name = :name', [':name' => $name])->fetchField();
return unserialize($data);
}

View File

@ -97,16 +97,15 @@ class EntityApiTest extends EntityKernelTestBase {
// Verify that all data got deleted.
$definition = \Drupal::entityTypeManager()->getDefinition($entity_type);
$connection = Database::getConnection();
$this->assertEqual(0, (int) $connection->select($definition->getBaseTable())->countQuery()->execute()->fetchField(), 'Base table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $definition->getBaseTable() . '}')->fetchField(), 'Base table was emptied');
if ($data_table = $definition->getDataTable()) {
$this->assertEqual(0, (int) $connection->select($data_table)->countQuery()->execute()->fetchField(), 'Data table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $data_table . '}')->fetchField(), 'Data table was emptied');
}
if ($revision_table = $definition->getRevisionTable()) {
$this->assertEqual(0, (int) $connection->select($revision_table)->countQuery()->execute()->fetchField(), 'Revision table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $revision_table . '}')->fetchField(), 'Data table was emptied');
}
if ($revision_data_table = $definition->getRevisionDataTable()) {
$this->assertEqual(0, (int) $connection->select($revision_data_table)->countQuery()->execute()->fetchField(), 'Revision data table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $revision_data_table . '}')->fetchField(), 'Data table was emptied');
}
// Test deleting a list of entities not indexed by entity id.
@ -126,16 +125,15 @@ class EntityApiTest extends EntityKernelTestBase {
// Verify that all data got deleted from the tables.
$definition = \Drupal::entityTypeManager()->getDefinition($entity_type);
$this->assertEqual(0, (int) $connection->select($definition->getBaseTable())->countQuery()->execute()->fetchField(), 'Base table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $definition->getBaseTable() . '}')->fetchField(), 'Base table was emptied');
if ($data_table = $definition->getDataTable()) {
$this->assertEqual(0, (int) $connection->select($data_table)->countQuery()->execute()->fetchField(), 'Data table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $data_table . '}')->fetchField(), 'Data table was emptied');
}
if ($revision_table = $definition->getRevisionTable()) {
$this->assertEqual(0, (int) $connection->select($revision_table)->countQuery()->execute()->fetchField(), 'Revision table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $revision_table . '}')->fetchField(), 'Data table was emptied');
}
if ($revision_data_table = $definition->getRevisionDataTable()) {
$this->assertEqual(0, (int) $connection->select($revision_data_table)->countQuery()->execute()->fetchField(), 'Revision data table was emptied');
$this->assertEqual(0, $connection->query('SELECT COUNT(*) FROM {' . $revision_data_table . '}')->fetchField(), 'Data table was emptied');
}
}

View File

@ -169,11 +169,10 @@ class RevisionableContentEntityBaseTest extends EntityKernelTestBase {
*/
protected function assertItemsTableCount($count, EntityTypeInterface $definition) {
$connection = Database::getConnection();
$this->assertEqual(1, (int) $connection->select($definition->getBaseTable())->countQuery()->execute()->fetchField());
$this->assertEqual(1, (int) $connection->select($definition->getDataTable())->countQuery()->execute()->fetchField());
$this->assertEqual($count, (int) $connection->select($definition->getRevisionTable())->countQuery()->execute()->fetchField());
$this->assertEqual($count, (int) $connection->select($definition->getRevisionDataTable())->countQuery()->execute()->fetchField());
$this->assertEqual(1, $connection->query('SELECT COUNT(*) FROM {' . $definition->getBaseTable() . '}')->fetchField());
$this->assertEqual(1, $connection->query('SELECT COUNT(*) FROM {' . $definition->getDataTable() . '}')->fetchField());
$this->assertEqual($count, $connection->query('SELECT COUNT(*) FROM {' . $definition->getRevisionTable() . '}')->fetchField());
$this->assertEqual($count, $connection->query('SELECT COUNT(*) FROM {' . $definition->getRevisionDataTable() . '}')->fetchField());
}
/**

View File

@ -60,11 +60,11 @@ class GarbageCollectionTest extends KernelTestBase {
system_cron();
// Query the database and confirm that the stale records were deleted.
$result = $connection->select('key_value_expire', 'kvp')
->fields('kvp', ['name'])
->condition('collection', $collection)
->execute()
->fetchAll();
$result = $connection->query(
'SELECT name, value FROM {key_value_expire} WHERE collection = :collection',
[
':collection' => $collection,
])->fetchAll();
$this->assertCount(1, $result, 'Only one item remains after garbage collection');
}

View File

@ -118,11 +118,7 @@ class MatcherDumperTest extends KernelTestBase {
$dumper->dump(['provider' => 'test']);
$record = $connection->select('test_routes', 'tr')
->fields('tr')
->condition('name', 'test_route')
->execute()
->fetchObject();
$record = $connection->query("SELECT * FROM {test_routes} WHERE name= :name", [':name' => 'test_route'])->fetchObject();
$loaded_route = unserialize($record->route);

View File

@ -297,11 +297,11 @@ class KernelTestBaseTest extends KernelTestBase {
$this->assertTrue(empty($tables), 'All test tables have been removed.');
}
else {
$result = $connection->select($this->databasePrefix . "sqlite_master", 'sql_m')->fields('sql_m', ['name'])
->condition('type', 'table')
->condition('name', '%', 'LIKE')
->condition('name', 'sqlite_%', 'NOT LIKE')
->execute()->fetchAllKeyed(0, 0);
$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->assertTrue(empty($result), 'All test tables have been removed.');
}