Skip to content
Snippets Groups Projects
Commit ff00a655 authored by David Cameron's avatar David Cameron
Browse files

Issue #3383550 by dcam, larowlan: Improve the new DefaultProcessorTest

parent 3bedab43
Branches
Tags
No related merge requests found
......@@ -16,6 +16,13 @@ class DefaultProcessorTest extends KernelTestBase {
*/
protected static $modules = ['aggregator', 'options'];
/**
* An instance of the DefaultProcessor plugin.
*
* @var \Drupal\aggregator\Plugin\aggregator\processor\DefaultProcessor
*/
protected $processor;
/**
* {@inheritdoc}
*/
......@@ -23,6 +30,11 @@ class DefaultProcessorTest extends KernelTestBase {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$this->installEntitySchema('aggregator_item');
/** @var \Drupal\aggregator\Plugin\AggregatorPluginManager $plugin_manager */
$plugin_manager = $this->container->get('plugin.manager.aggregator.processor');
/** @var \Drupal\aggregator\Plugin\aggregator\processor\DefaultProcessor $processor */
$this->processor = $plugin_manager->createInstance('aggregator');
}
/**
......@@ -30,23 +42,27 @@ class DefaultProcessorTest extends KernelTestBase {
*
* @dataProvider provideProcessData
*/
public function testProcess(array $items, int $expected_item_count) {
public function testProcess(array $items, array $expected_item_guids) {
$feed = Feed::create([
'title' => 'Processor test feed',
'url' => 'https://example.com/rss.xml',
'items' => $items,
]);
$feed->save();
/** @var \Drupal\aggregator\Plugin\AggregatorPluginManager $plugin_manager */
$plugin_manager = $this->container->get('plugin.manager.aggregator.processor');
/** @var \Drupal\aggregator\Plugin\aggregator\processor\DefaultProcessor $processor */
$processor = $plugin_manager->createInstance('aggregator');
$processor->process($feed);
$results = \Drupal::entityQuery('aggregator_item')
$this->processor->process($feed);
// Assert that the items we expected were created.
$guid_check_results = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('guid', $expected_item_guids)
->execute();
$this->assertSame(count($expected_item_guids), count($guid_check_results));
// Assert that no additional items were created.
$total_items_results = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->execute();
$this->assertSame($expected_item_count, count($results));
$this->assertSame(count($expected_item_guids), count($total_items_results));
}
/**
......@@ -75,7 +91,7 @@ class DefaultProcessorTest extends KernelTestBase {
'timestamp' => 0,
],
],
1,
[2],
],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment