diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php index 17ebba0..eccd463 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php @@ -7,9 +7,13 @@ namespace Drupal\aggregator\Plugin\Block; +use Drupal\aggregator\CategoryStorageControllerInterface; use Drupal\block\BlockBase; use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Database\Connection; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides an 'Aggregator category' block for the latest items in a category. @@ -19,7 +23,7 @@ * admin_label = @Translation("Aggregator category") * ) */ -class AggregatorCategoryBlock extends BlockBase { +class AggregatorCategoryBlock extends BlockBase implements ContainerFactoryPluginInterface { /** * The database connection. @@ -29,6 +33,13 @@ class AggregatorCategoryBlock extends BlockBase { protected $connection; /** + * The category storage controller. + * + * @var \Drupal\aggregator\CategoryStorageControllerInterface + */ + protected $categoryStorageController; + + /** * Constructs an AggregatorFeedBlock object. * * @param array $configuration @@ -40,9 +51,10 @@ class AggregatorCategoryBlock extends BlockBase { * @param \Drupal\Core\Database\Connection $connection * The database connection. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, Connection $connection) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, Connection $connection, CategoryStorageControllerInterface $category_storage_controller) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->connection = $connection; + $this->categoryStorageController = $category_storage_controller; } @@ -54,7 +66,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('database') + $container->get('database'), + $container->get('aggregator.category.storage') ); } @@ -115,7 +128,7 @@ public function blockSubmit($form, &$form_state) { */ public function build() { $cid = $this->configuration['cid']; - if ($category = aggregator_category_load($cid)) { + if ($category = $this->categoryStorageController->load($cid)) { $result = $this->connection->queryRange('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid)); $more_link = array( '#theme' => 'more_link', diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php index 404f156..b34a46f 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php @@ -11,6 +11,14 @@ * Tests categorization functionality in the Aggregator module. */ class CategorizeFeedItemTest extends AggregatorTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('block'); + public static function getInfo() { return array( 'name' => 'Categorize feed item functionality', @@ -54,7 +62,7 @@ function testCategorizeFeedItem() { // For each category of a feed, ensure feed items have that category, too. if (!empty($feed->categories) && !empty($feed->items)) { - foreach ($feed->categories as $category) { + foreach ($feed->categories as $cid) { $categorized_count = db_select('aggregator_category_item') ->condition('iid', $feed->items, 'IN') ->countQuery() @@ -65,6 +73,20 @@ function testCategorizeFeedItem() { } } + // Place a category block. + $block = $this->drupalPlaceBlock("aggregator_category_block", array('label' => 'category-' . $category->title)); + + // Configure the feed that should be displayed. + $block->getPlugin()->setConfigurationValue('cid', $category->cid); + $block->save(); + + // Visit the frontpage, assert that the block and the feeds are displayed. + $this->drupalGet(''); + $this->assertText('category-' . $category->title); + foreach (\Drupal::entityManager()->getStorageController('aggregator_item')->loadMultiple() as $item) { + $this->assertText($item->label()); + } + // Delete feed. $this->deleteFeed($feed); }