3 namespace Drupal\Tests\aggregator\Functional;
4 use Drupal\aggregator\Entity\Feed;
7 * Update feed items from a feed.
11 class UpdateFeedItemTest extends AggregatorTestBase {
13 * Tests running "update items" from 'admin/config/services/aggregator' page.
15 public function testUpdateFeedItem() {
16 $this->createSampleNodes();
18 // Create a feed and test updating feed items if possible.
19 $feed = $this->createFeed();
21 $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
22 $this->deleteFeedItems($feed);
26 $this->deleteFeed($feed);
28 // Test updating feed items without valid timestamp information.
30 'title[0][value]' => "Feed without publish timestamp",
31 'url[0][value]' => $this->getRSS091Sample(),
34 $this->drupalGet($edit['url[0][value]']);
35 $this->assertResponse(200);
37 $this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
38 $this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), format_string('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
40 // Verify that the creation message contains a link to a feed.
41 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
42 $this->assert(isset($view_link), 'The message area contains a link to a feed');
44 $fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", [':url' => $edit['url[0][value]']])->fetchField();
45 $feed = Feed::load($fid);
47 $feed->refreshItems();
48 $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
50 // Sleep for 3 second.
52 db_update('aggregator_feed')
53 ->condition('fid', $feed->id())
61 $feed->refreshItems();
63 $after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
64 $this->assertTrue($before === $after, format_string('Publish timestamp of feed item was not updated (@before === @after)', ['@before' => $before, '@after' => $after]));
66 // Make sure updating items works even after uninstalling a module
67 // that provides the selected plugins.
68 $this->enableTestPlugins();
69 $this->container->get('module_installer')->uninstall(['aggregator_test']);
70 $this->updateFeedItems($feed);
71 $this->assertResponse(200);