From 8471aac3db638372598f039539325d1315c176f8 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Thu, 29 Nov 2018 15:35:24 +0000 Subject: [PATCH] Issue #3014771 by anya_m, voleger, andypost, mondrake, goodboy: Replace queryRange call in AggregatorTestBase classes --- .../aggregator/src/Tests/AggregatorTestBase.php | 15 +++++++++++---- .../tests/src/Functional/AggregatorTestBase.php | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/core/modules/aggregator/src/Tests/AggregatorTestBase.php b/core/modules/aggregator/src/Tests/AggregatorTestBase.php index 1edf9aba435..3181eae91ab 100644 --- a/core/modules/aggregator/src/Tests/AggregatorTestBase.php +++ b/core/modules/aggregator/src/Tests/AggregatorTestBase.php @@ -6,7 +6,7 @@ namespace Drupal\aggregator\Tests; use Drupal\aggregator\Entity\Feed; use Drupal\Component\Utility\Html; -use Drupal\Core\Database\Database; +use Drupal\node\NodeInterface; use Drupal\simpletest\WebTestBase; use Drupal\aggregator\FeedInterface; @@ -154,9 +154,16 @@ abstract class AggregatorTestBase extends WebTestBase { * Number of feed items on default feed created by createFeed(). */ public function getDefaultFeedItemCount() { - // Our tests are based off of rss.xml, so let's find out how many elements should be related. - $feed_count = Database::getConnection()->queryRange('SELECT COUNT(DISTINCT nid) FROM {node_field_data} n WHERE n.promote = 1 AND n.status = 1', 0, $this->config('system.rss')->get('items.limit'))->fetchField(); - return $feed_count > 10 ? 10 : $feed_count; + // Our tests are based off of rss.xml, so let's find out how many elements + // should be related. + $feed_count = \Drupal::entityQuery('node') + ->condition('promote', NodeInterface::PROMOTED) + ->condition('status', NodeInterface::PUBLISHED) + ->accessCheck(FALSE) + ->range(0, $this->config('system.rss')->get('items.limit')) + ->count() + ->execute(); + return min($feed_count, 10); } /** diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php b/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php index 7d503d98a98..25ca2bf3b33 100644 --- a/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php +++ b/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php @@ -4,7 +4,7 @@ namespace Drupal\Tests\aggregator\Functional; use Drupal\aggregator\Entity\Feed; use Drupal\Component\Utility\Html; -use Drupal\Core\Database\Database; +use Drupal\node\NodeInterface; use Drupal\Tests\BrowserTestBase; use Drupal\aggregator\FeedInterface; @@ -147,9 +147,16 @@ abstract class AggregatorTestBase extends BrowserTestBase { * Number of feed items on default feed created by createFeed(). */ public function getDefaultFeedItemCount() { - // Our tests are based off of rss.xml, so let's find out how many elements should be related. - $feed_count = Database::getConnection()->queryRange('SELECT COUNT(DISTINCT nid) FROM {node_field_data} n WHERE n.promote = 1 AND n.status = 1', 0, $this->config('system.rss')->get('items.limit'))->fetchField(); - return $feed_count > 10 ? 10 : $feed_count; + // Our tests are based off of rss.xml, so let's find out how many elements + // should be related. + $feed_count = \Drupal::entityQuery('node') + ->condition('promote', NodeInterface::PROMOTED) + ->condition('status', NodeInterface::PUBLISHED) + ->accessCheck(FALSE) + ->range(0, $this->config('system.rss')->get('items.limit')) + ->count() + ->execute(); + return min($feed_count, 10); } /**