Unverified Commit bba4be92 authored by alexpott's avatar alexpott
Browse files

Issue #3160267 by nijolawrence, jungle, alexpott, daffie: Change static...

Issue #3160267 by nijolawrence, jungle, alexpott, daffie: Change static queries to dynamic queries in core/modules/{every module}/tests
parent fa20b88d
......@@ -39,7 +39,7 @@ public function testIPAddressValidation() {
$edit = [];
$edit['ip'] = '1.2.3.3';
$this->drupalPostForm('admin/config/people/ban', $edit, t('Add'));
$ip = $connection->query("SELECT iid from {ban_ip} WHERE ip = :ip", [':ip' => $edit['ip']])->fetchField();
$ip = $connection->select('ban_ip', 'bi')->fields('bi', ['iid'])->condition('ip', $edit['ip'])->execute()->fetchField();
$this->assertNotEmpty($ip, 'IP address found in database.');
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $edit['ip']]), 'IP address was banned.');
......@@ -70,7 +70,7 @@ public function testIPAddressValidation() {
// Pass an IP address as a URL parameter and submit it.
$submit_ip = '1.2.3.4';
$this->drupalPostForm('admin/config/people/ban/' . $submit_ip, [], t('Add'));
$ip = $connection->query("SELECT iid from {ban_ip} WHERE ip = :ip", [':ip' => $submit_ip])->fetchField();
$ip = $connection->select('ban_ip', 'bi')->fields('bi', ['iid'])->condition('ip', $submit_ip)->execute()->fetchField();
$this->assertNotEmpty($ip, 'IP address found in database');
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $submit_ip]), 'IP address was banned.');
......
......@@ -153,7 +153,7 @@ public function testBigPipe() {
$this->assertBigPipeNoJsCookieExists(FALSE);
$connection = Database::getConnection();
$log_count = $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
$log_count = $connection->select('watchdog')->countQuery()->execute()->fetchField();
// By not calling performMetaRefresh() here, we simulate JavaScript being
// enabled, because as far as the BigPipe module is concerned, JavaScript is
......@@ -191,10 +191,11 @@ public function testBigPipe() {
$this->assertContains('big_pipe/big_pipe', explode(',', $this->getDrupalSettings()['ajaxPageState']['libraries']), 'BigPipe asset library is present.');
// Verify that the two expected exceptions are logged as errors.
$this->assertEqual($log_count + 2, $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), 'Two new watchdog entries.');
// Using the method queryRange() allows contrib database drivers the ability
// to insert their own limit and offset functionality.
$records = $connection->queryRange('SELECT * FROM {watchdog} ORDER BY wid DESC', 0, 2)->fetchAll();
$this->assertEqual($log_count + 2, (int) $connection->select('watchdog')->countQuery()->execute()->fetchField(), 'Two new watchdog entries.');
// Using dynamic select queries with the method range() allows contrib
// database drivers the ability to insert their own limit and offset
// functionality.
$records = $connection->select('watchdog', 'w')->fields('w')->orderBy('wid', 'DESC')->range(0, 2)->execute()->fetchAll();
$this->assertEqual(RfcLogLevel::ERROR, $records[0]->severity);
$this->assertStringContainsString('Oh noes!', (string) unserialize($records[0]->variables)['@message']);
$this->assertEqual(RfcLogLevel::ERROR, $records[1]->severity);
......
......@@ -64,7 +64,12 @@ public function testWatchdog() {
// Write a log message to the DB.
$this->container->get('logger.channel.rest')->notice('Test message');
// Get the ID of the written message.
$id = Database::getConnection()->queryRange("SELECT wid FROM {watchdog} WHERE type = :type ORDER BY wid DESC", 0, 1, [':type' => 'rest'])
$id = Database::getConnection()->select('watchdog', 'w')
->fields('w', ['wid'])
->condition('type', 'rest')
->orderBy('wid', 'DESC')
->range(0, 1)
->execute()
->fetchField();
$this->initAuthentication();
......
......@@ -123,7 +123,9 @@ public function testLogEventPage() {
'timestamp' => REQUEST_TIME,
];
\Drupal::service('logger.dblog')->log(RfcLogLevel::NOTICE, 'Test message', $context);
$wid = Database::getConnection()->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
// Verify the links appear correctly.
$this->drupalGet('admin/reports/dblog/event/' . $wid);
......@@ -153,7 +155,10 @@ public function test403LogEventPage() {
$this->drupalLogin($this->adminUser);
$wid = Database::getConnection()->query("SELECT MAX(wid) FROM {watchdog} WHERE type='access denied'")->fetchField();
$query = Database::getConnection()->select('watchdog')
->condition('type', 'access denied');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
$table = $this->xpath("//table[@class='dblog-event']");
......@@ -208,7 +213,9 @@ public function testLogEventPageWithMissingInfo() {
$this->generateLogEntries(1, [
'referer' => NULL,
]);
$wid = $connection->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = $connection->select('watchdog');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
// Verify table headers are present, even though the referrer is missing.
......@@ -222,7 +229,9 @@ public function testLogEventPageWithMissingInfo() {
$this->generateLogEntries(1, [
'request_uri' => $request_uri,
]);
$wid = $connection->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = $connection->select('watchdog');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
// Verify table headers are present.
......@@ -322,7 +331,9 @@ private function verifyReports($response = 200) {
}
// View the database log event page.
$wid = Database::getConnection()->query('SELECT MIN(wid) FROM {watchdog}')->fetchField();
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MIN(wid)');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
$this->assertSession()->statusCodeEquals($response);
if ($response == 200) {
......@@ -335,7 +346,9 @@ private function verifyReports($response = 200) {
*/
private function verifyBreadcrumbs() {
// View the database log event page.
$wid = Database::getConnection()->query('SELECT MIN(wid) FROM {watchdog}')->fetchField();
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MIN(wid)');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
$xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
$this->assertEqual(current($this->xpath($xpath))->getText(), 'Recent log messages', 'DBLogs link displayed at breadcrumb in event page.');
......@@ -384,7 +397,7 @@ private function verifyLinkEscaping() {
'link' => $link,
]);
$result = Database::getConnection()->queryRange('SELECT wid FROM {watchdog} ORDER BY wid DESC', 0, 1);
$result = Database::getConnection()->select('watchdog', 'w')->fields('w', ['wid'])->orderBy('wid', 'DESC')->range(0, 1)->execute();
$this->drupalGet('admin/reports/dblog/event/' . $result->fetchField());
// Check if the link exists (unescaped).
......@@ -418,7 +431,7 @@ private function doUser() {
// Log out user.
$this->drupalLogout();
// Fetch the row IDs in watchdog that relate to the user.
$result = Database::getConnection()->query('SELECT wid FROM {watchdog} WHERE uid = :uid', [':uid' => $user->id()]);
$result = Database::getConnection()->select('watchdog', 'w')->fields('w', ['wid'])->condition('uid', $user->id())->execute();
foreach ($result as $row) {
$ids[] = $row->wid;
}
......@@ -590,7 +603,7 @@ public function testDBLogAddAndClear() {
global $base_root;
$connection = Database::getConnection();
// Get a count of how many watchdog entries already exist.
$count = $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
$count = $connection->select('watchdog')->countQuery()->execute()->fetchField();
$log = [
'channel' => 'system',
'message' => 'Log entry added to test the doClearTest clear down.',
......@@ -606,7 +619,7 @@ public function testDBLogAddAndClear() {
// Add a watchdog entry.
$this->container->get('logger.dblog')->log($log['severity'], $log['message'], $log);
// Make sure the table count has actually been incremented.
$this->assertEqual($count + 1, $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), new FormattableMarkup('\Drupal\dblog\Logger\DbLog->log() added an entry to the dblog :count', [':count' => $count]));
$this->assertEqual($count + 1, (int) $connection->select('watchdog')->countQuery()->execute()->fetchField(), new FormattableMarkup('\Drupal\dblog\Logger\DbLog->log() added an entry to the dblog :count', [':count' => $count]));
// Log in the admin user.
$this->drupalLogin($this->adminUser);
// Post in order to clear the database table.
......@@ -614,7 +627,7 @@ public function testDBLogAddAndClear() {
// Confirm that the logs should be cleared.
$this->drupalPostForm(NULL, [], 'Confirm');
// Count the rows in watchdog that previously related to the deleted user.
$count = $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
$count = $connection->select('watchdog')->countQuery()->execute()->fetchField();
$this->assertEqual($count, 0, new FormattableMarkup('DBLog contains :count records after a clear.', [':count' => $count]));
}
......@@ -803,7 +816,9 @@ public function testTemporaryUser() {
// Generate a single watchdog entry.
$this->generateLogEntries(1, ['user' => $tempuser, 'uid' => $tempuser_uid]);
$wid = Database::getConnection()->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
// Check if the full message displays on the details page.
$this->drupalGet('admin/reports/dblog/event/' . $wid);
......@@ -833,7 +848,9 @@ public function testOverviewLinks() {
// Make sure HTML tags are filtered out in admin/reports/dblog/event/ too.
$this->generateLogEntries(1, ['message' => "<script>alert('foo');</script> <strong>Lorem ipsum</strong>"]);
$wid = Database::getConnection()->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
$this->assertNoRaw("<script>alert('foo');</script>");
$this->assertRaw("alert('foo'); <strong>Lorem ipsum</strong>");
......@@ -864,7 +881,9 @@ public function testBacktrace() {
$this->drupalLogin($this->adminUser);
$this->drupalGet('/error-test/generate-warnings');
$wid = Database::getConnection()->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
$error_user_notice = [
......
......@@ -39,7 +39,10 @@ public function testConnectionFailureLogging() {
// Re-establish the default database connection.
$database = Database::getConnection();
$wid = $database->query("SELECT MAX(wid) FROM {watchdog} WHERE message = 'testConnectionFailureLogging'")->fetchField();
$query = $database->select('watchdog')
->condition('message', 'testConnectionFailureLogging');
$query->addExpression('MAX(wid)');
$wid = $query->execute()->fetchField();
$this->assertNotEmpty($wid, 'Watchdog entry has been stored in database.');
}
......
......@@ -40,7 +40,7 @@ public function testDbLogCron() {
// Generate additional log entries.
$this->generateLogEntries($row_limit + 10);
// Verify that the database log row count exceeds the row limit.
$count = Database::getConnection()->query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
$count = Database::getConnection()->select('watchdog')->countQuery()->execute()->fetchField();
$this->assertGreaterThan($row_limit, $count, new FormattableMarkup('Dblog row count of @count exceeds row limit of @limit', ['@count' => $count, '@limit' => $row_limit]));
// Get the number of enabled modules. Cron adds a log entry for each module.
......@@ -66,13 +66,17 @@ private function runCron() {
// Get last ID to compare against; log entries get deleted, so we can't
// reliably add the number of newly created log entries to the current count
// to measure number of log entries created by cron.
$last_id = $connection->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = $connection->select('watchdog');
$query->addExpression('MAX(wid)');
$last_id = $query->execute()->fetchField();
// Run a cron job.
$this->container->get('cron')->run();
// Get last ID after cron was run.
$current_id = $connection->query('SELECT MAX(wid) FROM {watchdog}')->fetchField();
$query = $connection->select('watchdog');
$query->addExpression('MAX(wid)');
$current_id = $query->execute()->fetchField();
return $current_id - $last_id;
}
......
......@@ -975,9 +975,10 @@ public function testGetIndividual() {
// contain a flattened response. Otherwise performance suffers.
// @see \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::flattenResponse()
$cache_items = $this->container->get('database')
->query("SELECT cid, data FROM {cache_dynamic_page_cache} WHERE cid LIKE :pattern", [
':pattern' => '%[route]=jsonapi.%',
])
->select('cache_dynamic_page_cache', 'cdp')
->fields('cdp', ['cid', 'data'])
->condition('cid', '%[route]=jsonapi.%', 'LIKE')
->execute()
->fetchAllAssoc('cid');
$this->assertTrue(count($cache_items) >= 2);
$found_cache_redirect = FALSE;
......
......@@ -202,7 +202,11 @@ public function testStandalonePoFile() {
// The database should now contain 6 customized strings (two imported
// strings are not translated).
$count = Database::getConnection()->query('SELECT COUNT(*) FROM {locales_target} WHERE customized = :custom', [':custom' => 1])->fetchField();
$count = Database::getConnection()->select('locales_target')
->condition('customized', 1)
->countQuery()
->execute()
->fetchField();
$this->assertEqual($count, 6, 'Customized translations successfully imported.');
// Try importing a .po file with overriding strings, and ensure existing
......
......@@ -197,7 +197,12 @@ public function testPluralEditDateFormatter() {
// not save our source string for performance optimization if we do not ask
// specifically for a language.
\Drupal::translation()->formatPlural(1, '1 second', '@count seconds', [], ['langcode' => 'fr'])->render();
$lid = Database::getConnection()->query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", [':source' => "1 second" . PoItem::DELIMITER . "@count seconds"])->fetchField();
$lid = Database::getConnection()->select('locales_source', 'ls')
->fields('ls', ['lid'])
->condition('source', "1 second" . PoItem::DELIMITER . "@count seconds")
->condition('context', '')
->execute()
->fetchField();
// Look up editing page for this plural string and check fields.
$search = [
'string' => '1 second',
......@@ -282,7 +287,12 @@ public function testPluralEditExport() {
$connection = Database::getConnection();
// Edit langcode hr translations and see if that took effect.
$lid = $connection->query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", [':source' => "1 hour" . PoItem::DELIMITER . "@count hours"])->fetchField();
$lid = $connection->select('locales_source', 'ls')
->fields('ls', ['lid'])
->condition('source', "1 hour" . PoItem::DELIMITER . "@count hours")
->condition('context', '')
->execute()
->fetchField();
$edit = [
"strings[$lid][translations][1]" => '@count sata edited',
];
......@@ -308,7 +318,12 @@ public function testPluralEditExport() {
// not save our source string for performance optimization if we do not ask
// specifically for a language.
\Drupal::translation()->formatPlural(1, '1 day', '@count days', [], ['langcode' => 'fr'])->render();
$lid = $connection->query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", [':source' => "1 day" . PoItem::DELIMITER . "@count days"])->fetchField();
$lid = $connection->select('locales_source', 'ls')
->fields('ls', ['lid'])
->condition('source', "1 day" . PoItem::DELIMITER . "@count days")
->condition('context', '')
->execute()
->fetchField();
// Look up editing page for this plural string and check fields.
$search = [
'string' => '1 day',
......
......@@ -301,7 +301,13 @@ protected function setCurrentTranslations() {
* (optional) A message to display with the assertion.
*/
protected function assertTranslation($source, $translation, $langcode, $message = '') {
$db_translation = Database::getConnection()->query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', [':source' => $source, ':langcode' => $langcode])->fetchField();
$query = Database::getConnection()->select('locales_target', 'lt');
$query->innerJoin('locales_source', 'ls', 'ls.lid = lt.lid');
$db_translation = $query->fields('lt', ['translation'])
->condition('ls.source', $source)
->condition('lt.language', $langcode)
->execute()
->fetchField();
$db_translation = $db_translation == FALSE ? '' : $db_translation;
$this->assertEqual($translation, $db_translation, $message ? $message : new FormattableMarkup('Correct translation of %source (%language)', ['%source' => $source, '%language' => $langcode]));
}
......
......@@ -359,14 +359,22 @@ public function testEnableLanguage() {
// Check if the language data is added to the database.
$connection = Database::getConnection();
$result = $connection->query("SELECT project FROM {locale_file} WHERE langcode='nl'")->fetchField();
$result = $connection->select('locale_file', 'lf')
->fields('lf', ['project'])
->condition('langcode', 'nl')
->execute()
->fetchField();
$this->assertNotEmpty($result, 'Files added to file history');
// Remove a language.
$this->drupalPostForm('admin/config/regional/language/delete/nl', [], t('Delete'));
// Check if the language data is removed from the database.
$result = $connection->query("SELECT project FROM {locale_file} WHERE langcode='nl'")->fetchField();
$result = $connection->select('locale_file', 'lf')
->fields('lf', ['project'])
->condition('langcode', 'nl')
->execute()
->fetchField();
$this->assertFalse($result, 'Files removed from file history');
// Check that the Dutch translation is gone.
......
......@@ -298,7 +298,9 @@ protected static function getWatchdogIdsForTestExceptionRollback() {
// PostgreSQL doesn't support bytea LIKE queries, so we need to unserialize
// first to check for the rollback exception message.
$matches = [];
$query = Database::getConnection()->query("SELECT wid, variables FROM {watchdog}");
$query = Database::getConnection()->select('watchdog', 'w')
->fields('w', ['wid', 'variables'])
->execute();
foreach ($query as $row) {
$variables = (array) unserialize($row->variables);
if (isset($variables['@message']) && $variables['@message'] === 'Test exception for rollback.') {
......
......@@ -30,7 +30,11 @@ public function testNodeAccessRecords() {
// Check to see if grants added by node_test_node_access_records made it in.
$connection = Database::getConnection();
$records = $connection->query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', [':nid' => $node1->id()])->fetchAll();
$records = $connection->select('node_access', 'na')
->fields('na', ['realm', 'gid'])
->condition('nid', $node1->id())
->execute()
->fetchAll();
$this->assertCount(1, $records, 'Returned the correct number of rows.');
$this->assertEqual($records[0]->realm, 'test_article_realm', 'Grant with article_realm acquired for node without alteration.');
$this->assertEqual($records[0]->gid, 1, 'Grant with gid = 1 acquired for node without alteration.');
......@@ -40,7 +44,11 @@ public function testNodeAccessRecords() {
$this->assertNotEmpty(Node::load($node2->id()), 'Unpromoted basic page node created.');
// Check to see if grants added by node_test_node_access_records made it in.
$records = $connection->query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', [':nid' => $node2->id()])->fetchAll();
$records = $connection->select('node_access', 'na')
->fields('na', ['realm', 'gid'])
->condition('nid', $node2->id())
->execute()
->fetchAll();
$this->assertCount(1, $records, 'Returned the correct number of rows.');
$this->assertEqual($records[0]->realm, 'test_page_realm', 'Grant with page_realm acquired for node without alteration.');
$this->assertEqual($records[0]->gid, 1, 'Grant with gid = 1 acquired for node without alteration.');
......@@ -50,7 +58,11 @@ public function testNodeAccessRecords() {
$this->assertNotEmpty(Node::load($node3->id()), 'Unpromoted, unpublished basic page node created.');
// Check to see if grants added by node_test_node_access_records made it in.
$records = $connection->query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', [':nid' => $node3->id()])->fetchAll();
$records = $connection->select('node_access', 'na')
->fields('na', ['realm', 'gid'])
->condition('nid', $node3->id())
->execute()
->fetchAll();
$this->assertCount(1, $records, 'Returned the correct number of rows.');
$this->assertEqual($records[0]->realm, 'test_page_realm', 'Grant with page_realm acquired for node without alteration.');
$this->assertEqual($records[0]->gid, 1, 'Grant with gid = 1 acquired for node without alteration.');
......@@ -61,7 +73,11 @@ public function testNodeAccessRecords() {
// Check to see if grant added by node_test_node_access_records was altered
// by node_test_node_access_records_alter.
$records = $connection->query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', [':nid' => $node4->id()])->fetchAll();
$records = $connection->select('node_access', 'na')
->fields('na', ['realm', 'gid'])
->condition('nid', $node4->id())
->execute()
->fetchAll();
$this->assertCount(1, $records, 'Returned the correct number of rows.');
$this->assertEqual($records[0]->realm, 'test_alter_realm', 'Altered grant with alter_realm acquired for node.');
$this->assertEqual($records[0]->gid, 2, 'Altered grant with gid = 2 acquired for node.');
......@@ -80,7 +96,11 @@ public function testNodeAccessRecords() {
// Check that core does not grant access to an unpublished node when an
// empty $grants array is returned.
$node6 = $this->drupalCreateNode(['status' => 0, 'disable_node_access' => TRUE]);
$records = $connection->query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', [':nid' => $node6->id()])->fetchAll();
$records = $connection->select('node_access', 'na')
->fields('na', ['realm', 'gid'])
->condition('nid', $node6->id())
->execute()
->fetchAll();
$this->assertCount(0, $records, 'Returned no records for unpublished node.');
}
......
......@@ -100,7 +100,11 @@ public function testSearchIndexUpdateOnNodeDeletion() {
// Get the node info from the search index tables.
$connection = Database::getConnection();
$search_index_dataset = $connection->query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", [':word' => 'dragons'])
$search_index_dataset = $connection->select('search_index', 'si')
->fields('si', ['sid'])
->condition('type', 'node_search')
->condition('word', 'dragons')
->execute()
->fetchField();
$this->assertNotEqual($search_index_dataset, FALSE, t('Node info found on the search_index'));
......@@ -108,7 +112,11 @@ public function testSearchIndexUpdateOnNodeDeletion() {
$node->delete();
// Check if the node info is gone from the search table.
$search_index_dataset = $connection->query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", [':word' => 'dragons'])
$search_index_dataset = $connection->select('search_index', 'si')
->fields('si', ['sid'])
->condition('type', 'node_search')
->condition('word', 'dragons')
->execute()
->fetchField();
$this->assertFalse($search_index_dataset, t('Node info successfully removed from search_index'));
......
......@@ -76,7 +76,9 @@ public function triggerException() {
*/
public function triggerPDOException() {
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
$this->database->query('SELECT * FROM bananas_are_awesome');
$this->database->select('bananas_are_awesome', 'b')
->fields('b')
->execute();
}
/**
......
......@@ -30,7 +30,7 @@ public function testEvenPagerQuery() {
// information forward to the actual query on the other side of the
// HTTP request.
$limit = 2;
$count = Database::getConnection()->query('SELECT COUNT(*) FROM {test}')->fetchField();
$count = Database::getConnection()->select('test')->countQuery()->execute()->fetchField();
$correct_number = $limit;
$num_pages = floor($count / $limit);
......@@ -64,7 +64,7 @@ public function testOddPagerQuery() {
// information forward to the actual query on the other side of the
// HTTP request.
$limit = 2;
$count = Database::getConnection()->query('SELECT COUNT(*) FROM {test_task}')->fetchField();
$count = Database::getConnection()->select('test_task')->countQuery()->execute()->fetchField();
$correct_number = $limit;
$num_pages = floor($count / $limit);
......
......@@ -189,7 +189,12 @@ public function testImmutableFormLegacyProtection() {
// Assert that a watchdog message was logged by
// \Drupal::formBuilder()->setCache().
$status = (bool) Database::getConnection()->queryRange('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, [':message' => 'Form build-id mismatch detected while attempting to store a form in the cache.']);
$status = (bool) Database::getConnection()->select('watchdog')
->condition('message', 'Form build-id mismatch detected while attempting to store a form in the cache.')
->range(0, 1)
->countQuery()
->execute()
->fetchField();
$this->assertTrue($status, 'A watchdog message was logged by \Drupal::formBuilder()->setCache');
// Ensure that the form state was not poisoned by the preceding call.
......
......@@ -31,7 +31,7 @@ class InstallTest extends BrowserTestBase {
*/
public function testGetSchemaAtInstallTime() {
// @see module_test_install()
$value = Database::getConnection()->query("SELECT data FROM {module_test}")->fetchField();
$value = Database::getConnection()->select('module_test', 'mt')->fields('mt', ['data'])->execute()->fetchField();
$this->assertIdentical($value, 'varchar');
}
......
......@@ -254,10 +254,7 @@ protected function getPathFromLocationHeader(ResponseInterface $response, $https
* has the given insecure and secure session IDs.
*/
protected function assertSessionIds($sid, $assertion_text) {
$args = [
':sid' => Crypt::hashBase64($sid),
];
return $this->assertNotEmpty(\Drupal::database()->query('SELECT timestamp FROM {sessions} WHERE sid = :sid', $args)->fetchField(), $assertion_text);
return $this->assertNotEmpty(\Drupal::database()->select('sessions', 's')->fields('s', ['timestamp'])->condition('sid', Crypt::hashBase64($sid))->execute()->fetchField(), $assertion_text);
}
/**
......
......@@ -233,8 +233,12 @@ public function testSessionWrite() {
$this->drupalLogin($user);
$connection = Database::getConnection();
$sql = 'SELECT u.access, s.timestamp FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE u.uid = :uid';
$times1 = $connection->query($sql, [':uid' => $user->id()])->fetchObject();
$query = $connection->select('users_field_data', 'u');
$query->innerJoin('sessions', 's', 'u.uid = s.uid');
$query->fields('u', ['access'])
->fields('s', ['timestamp'])
->condition('u.uid', $user->id());
$times1 = $query->execute()->fetchObject();
// Before every request we sleep one second to make sure that if the session
// is saved, its timestamp will change.
......@@ -242,21 +246,21 @@ public function testSessionWrite() {
// Modify the session.
sleep(1);
$this->drupalGet('session-test/set/foo');
$times2 = $connection->query($sql, [':uid' => $user->id()])->fetchObject();
$times2 = $query->execute()->fetchObject();
$this->assertEqual($times2->access, $times1->access, 'Users table was not updated.');
$this->assertNotEqual($times2->timestamp, $times1->timestamp, 'Sessions table was updated.');
// Write the same value again, i.e. do not modify the session.
sleep(1);
$this->drupalGet('session-test/set/foo');
$times3 = $connection->query($sql, [':uid' => $user->id()])->fetchObject();
$times3 = $query->execute()->fetchObject();
$this->assertEqual($times3->access, $times1->access, 'Users table was not updated.');
$this->assertEqual($times3->timestamp, $times2->timestamp, 'Sessions table was not updated.');
// Do not change the session.
sleep(1);
$this->drupalGet('');
$times4 = $connection->query($sql, [':uid' => $user->id()])->fetchObject();
$times4 = $query->execute()->fetchObject();