From c393119b77039a208fe858252cfdeb113ecca716 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Fri, 20 Mar 2015 14:24:07 +0000 Subject: [PATCH] Issue #2348773 by geertvd, IT-Cru: Aggregator item counts are formatted as date intervals --- .../src/Controller/AggregatorController.php | 2 +- .../aggregator/processor/DefaultProcessor.php | 2 +- ...rationTest.php => AggregatorAdminTest.php} | 32 +++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) rename core/modules/aggregator/src/Tests/{AggregatorConfigurationTest.php => AggregatorAdminTest.php} (59%) diff --git a/core/modules/aggregator/src/Controller/AggregatorController.php b/core/modules/aggregator/src/Controller/AggregatorController.php index 937b40c2a4ac..303b43c8a080 100644 --- a/core/modules/aggregator/src/Controller/AggregatorController.php +++ b/core/modules/aggregator/src/Controller/AggregatorController.php @@ -124,7 +124,7 @@ class AggregatorController extends ControllerBase { foreach ($feeds as $feed) { $row = array(); $row[] = $feed->link(); - $row[] = $this->dateFormatter->formatInterval($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items'); + $row[] = $this->formatPlural($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items'); $last_checked = $feed->getLastCheckedTime(); $refresh_rate = $feed->getRefreshRate(); $row[] = ($last_checked ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked))) : $this->t('never')); diff --git a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php index cadd84b721d6..a42c39a40660 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php @@ -124,7 +124,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor $info = $this->getPluginDefinition(); $counts = array(3, 5, 10, 15, 20, 25); $items = array_map(function ($count) { - return $this->dateFormatter->formatInterval($count, '1 item', '@count items'); + return $this->formatPlural($count, '1 item', '@count items'); }, array_combine($counts, $counts)); $intervals = array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800); $period = array_map(array($this->dateFormatter, 'formatInterval'), array_combine($intervals, $intervals)); diff --git a/core/modules/aggregator/src/Tests/AggregatorConfigurationTest.php b/core/modules/aggregator/src/Tests/AggregatorAdminTest.php similarity index 59% rename from core/modules/aggregator/src/Tests/AggregatorConfigurationTest.php rename to core/modules/aggregator/src/Tests/AggregatorAdminTest.php index d6225826599e..edc594b35f21 100644 --- a/core/modules/aggregator/src/Tests/AggregatorConfigurationTest.php +++ b/core/modules/aggregator/src/Tests/AggregatorAdminTest.php @@ -2,17 +2,18 @@ /** * @file - * Definition of Drupal\aggregator\Tests\AggregatorConfigurationTest. + * Contains \Drupal\aggregator\Tests\AggregatorAdminTest. */ namespace Drupal\aggregator\Tests; /** - * Tests aggregator settings page. + * Tests aggregator admin pages. * * @group aggregator */ -class AggregatorConfigurationTest extends AggregatorTestBase { +class AggregatorAdminTest extends AggregatorTestBase { + /** * Tests the settings form to ensure the correct default values are used. */ @@ -59,4 +60,29 @@ class AggregatorConfigurationTest extends AggregatorTestBase { $this->drupalGet('admin/config/services/aggregator/settings'); $this->assertResponse(200); } + + /** + * Tests the overview page. + */ + function testOverviewPage() { + $feed = $this->createFeed($this->getRSS091Sample()); + $this->drupalGet('admin/config/services/aggregator'); + + $result = $this->xpath('//table/tbody/tr'); + // Check if the amount of feeds in the overview matches the amount created. + $this->assertEqual(1, count($result), 'Created feed is found in the overview'); + // Check if the fields in the table match with what's expected. + $this->assertEqual($feed->label(), (string) $result[0]->td[0]->a); + $count = $this->container->get('entity.manager')->getStorage('aggregator_item')->getItemCount($feed); + $this->assertEqual(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), (string) $result[0]->td[1]); + + // Update the items of the first feed. + $feed->refreshItems(); + $this->drupalGet('admin/config/services/aggregator'); + $result = $this->xpath('//table/tbody/tr'); + // Check if the fields in the table match with what's expected. + $this->assertEqual($feed->label(), (string) $result[0]->td[0]->a); + $count = $this->container->get('entity.manager')->getStorage('aggregator_item')->getItemCount($feed); + $this->assertEqual(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), (string) $result[0]->td[1]); + } }