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