3 namespace Drupal\Tests\aggregator\Functional;
5 use Drupal\aggregator\Entity\Feed;
8 * Update feed items from a feed.
12 class UpdateFeedItemTest extends AggregatorTestBase {
15 * Tests running "update items" from 'admin/config/services/aggregator' page.
17 public function testUpdateFeedItem() {
18 $this->createSampleNodes();
20 // Create a feed and test updating feed items if possible.
21 $feed = $this->createFeed();
23 $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
24 $this->deleteFeedItems($feed);
28 $this->deleteFeed($feed);
30 // Test updating feed items without valid timestamp information.
32 'title[0][value]' => "Feed without publish timestamp",
33 'url[0][value]' => $this->getRSS091Sample(),
36 $this->drupalGet($edit['url[0][value]']);
37 $this->assertResponse(200);
39 $this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
40 $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]']]));
42 // Verify that the creation message contains a link to a feed.
43 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
44 $this->assert(isset($view_link), 'The message area contains a link to a feed');
46 $fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", [':url' => $edit['url[0][value]']])->fetchField();
47 $feed = Feed::load($fid);
49 $feed->refreshItems();
50 $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
52 // Sleep for 3 second.
54 db_update('aggregator_feed')
55 ->condition('fid', $feed->id())
63 $feed->refreshItems();
65 $after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
66 $this->assertTrue($before === $after, format_string('Publish timestamp of feed item was not updated (@before === @after)', ['@before' => $before, '@after' => $after]));
68 // Make sure updating items works even after uninstalling a module
69 // that provides the selected plugins.
70 $this->enableTestPlugins();
71 $this->container->get('module_installer')->uninstall(['aggregator_test']);
72 $this->updateFeedItems($feed);
73 $this->assertResponse(200);