diff --git a/core/modules/aggregator/tests/src/Functional/DeleteFeedTest.php b/core/modules/aggregator/tests/src/Functional/DeleteFeedTest.php index 557720658d..9ab4960100 100644 --- a/core/modules/aggregator/tests/src/Functional/DeleteFeedTest.php +++ b/core/modules/aggregator/tests/src/Functional/DeleteFeedTest.php @@ -43,8 +43,12 @@ public function testDeleteFeed() { $this->assertResponse(404, 'Deleted feed source does not exist.'); // Check database for feed. - $result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", [':title' => $feed1->label(), ':url' => $feed1->getUrl()])->fetchField(); - $this->assertFalse($result, 'Feed not found in database'); + $result = \Drupal::entityQuery('aggregator_feed') + ->condition('title', $feed1->label()) + ->condition('url', $feed1->getUrl()) + ->count() + ->execute(); + $this->assertEquals(0, $result, 'Feed not found in database'); } } diff --git a/core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php b/core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php index e9037175ed..98b974a4c1 100644 --- a/core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php +++ b/core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php @@ -46,7 +46,8 @@ public function openImportForm() { * Submits form filled with invalid fields. */ public function validateImportFormFields() { - $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $count_query = \Drupal::entityQuery('aggregator_feed')->count(); + $before = $count_query->execute(); $edit = []; $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import')); @@ -64,7 +65,7 @@ public function validateImportFormFields() { $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import')); $this->assertText(t('The URL invalidUrl://empty is not valid.'), 'Error if the URL is invalid.'); - $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $after = $count_query->execute(); $this->assertEqual($before, $after, 'No feeds were added during the three last form submissions.'); } @@ -73,7 +74,8 @@ public function validateImportFormFields() { */ protected function submitImportForm() { $connection = Database::getConnection(); - $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $count_query = \Drupal::entityQuery('aggregator_feed')->count(); + $before = $count_query->execute(); $form['files[upload]'] = $this->getInvalidOpml(); $this->drupalPostForm('admin/config/services/aggregator/add/opml', $form, t('Import')); @@ -83,7 +85,7 @@ protected function submitImportForm() { $this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import')); $this->assertText(t('No new feed has been added.'), 'Attempting to load empty OPML from remote URL.'); - $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $after = $count_query->execute(); $this->assertEqual($before, $after, 'No feeds were added during the two last form submissions.'); $connection->delete('aggregator_feed')->execute(); @@ -99,7 +101,7 @@ protected function submitImportForm() { $this->assertRaw(t('A feed with the URL %url already exists.', ['%url' => $feeds[0]['url[0][value]']]), 'Verifying that a duplicate URL was identified'); $this->assertRaw(t('A feed named %title already exists.', ['%title' => $feeds[1]['title[0][value]']]), 'Verifying that a duplicate title was identified'); - $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $after = $count_query->execute(); $this->assertEqual($after, 2, 'Verifying that two distinct feeds were added.'); $feeds_from_db = db_query("SELECT title, url, refresh FROM {aggregator_feed}"); diff --git a/core/modules/taxonomy/tests/src/Functional/TermIndexTest.php b/core/modules/taxonomy/tests/src/Functional/TermIndexTest.php index 83ab04d5e1..2474e61247 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermIndexTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermIndexTest.php @@ -88,9 +88,11 @@ protected function setUp() { */ public function testTaxonomyIndex() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); - // Create terms in the vocabulary. + // Create terms in the vocabulary, and prepare count queries. $term_1 = $this->createTerm($this->vocabulary); $term_2 = $this->createTerm($this->vocabulary); + $count_query_1 = \Drupal::entityQuery('taxonomy_index')->condition('nid', $node->id())->condition('tid', $term_1->id())->count(); + $count_query_2 = \Drupal::entityQuery('taxonomy_index')->condition('nid', $node->id())->condition('tid', $term_2->id())->count(); // Post an article. $edit = []; @@ -102,10 +104,7 @@ public function testTaxonomyIndex() { // Check that the term is indexed, and only once. $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_1->id(), - ])->fetchField(); + $index_count = $count_query_1->execute(); $this->assertEqual(1, $index_count, 'Term 1 is indexed once.'); // Update the article to change one term. @@ -113,15 +112,9 @@ public function testTaxonomyIndex() { $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); // Check that both terms are indexed. - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_1->id(), - ])->fetchField(); + $index_count = $count_query_1->execute(); $this->assertEqual(1, $index_count, 'Term 1 is indexed.'); - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_2->id(), - ])->fetchField(); + $index_count = $count_query_2->execute(); $this->assertEqual(1, $index_count, 'Term 2 is indexed.'); // Update the article to change another term. @@ -129,15 +122,9 @@ public function testTaxonomyIndex() { $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); // Check that only one term is indexed. - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_1->id(), - ])->fetchField(); + $index_count = $count_query_1->execute(); $this->assertEqual(0, $index_count, 'Term 1 is not indexed.'); - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_2->id(), - ])->fetchField(); + $index_count = $count_query_2->execute(); $this->assertEqual(1, $index_count, 'Term 2 is indexed once.'); // Redo the above tests without interface. @@ -149,15 +136,9 @@ public function testTaxonomyIndex() { $node->save(); // Check that the index was not changed. - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_1->id(), - ])->fetchField(); + $index_count = $count_query_1->execute(); $this->assertEqual(0, $index_count, 'Term 1 is not indexed.'); - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_2->id(), - ])->fetchField(); + $index_count = $count_query_2->execute(); $this->assertEqual(1, $index_count, 'Term 2 is indexed once.'); // Update the article to change one term. @@ -165,15 +146,9 @@ public function testTaxonomyIndex() { $node->save(); // Check that both terms are indexed. - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_1->id(), - ])->fetchField(); + $index_count = $count_query_1->execute(); $this->assertEqual(1, $index_count, 'Term 1 is indexed.'); - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_2->id(), - ])->fetchField(); + $index_count = $count_query_2->execute(); $this->assertEqual(1, $index_count, 'Term 2 is indexed.'); // Update the article to change another term. @@ -181,15 +156,9 @@ public function testTaxonomyIndex() { $node->save(); // Check that only one term is indexed. - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_1->id(), - ])->fetchField(); + $index_count = $count_query_1->execute(); $this->assertEqual(1, $index_count, 'Term 1 is indexed once.'); - $index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [ - ':nid' => $node->id(), - ':tid' => $term_2->id(), - ])->fetchField(); + $index_count = $count_query_2->execute(); $this->assertEqual(0, $index_count, 'Term 2 is not indexed.'); }