Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / aggregator / tests / src / Functional / UpdateFeedItemTest.php
1 <?php
2
3 namespace Drupal\Tests\aggregator\Functional;
4
5 use Drupal\aggregator\Entity\Feed;
6
7 /**
8  * Update feed items from a feed.
9  *
10  * @group aggregator
11  */
12 class UpdateFeedItemTest extends AggregatorTestBase {
13   /**
14    * Tests running "update items" from 'admin/config/services/aggregator' page.
15    */
16   public function testUpdateFeedItem() {
17     $this->createSampleNodes();
18
19     // Create a feed and test updating feed items if possible.
20     $feed = $this->createFeed();
21     if (!empty($feed)) {
22       $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
23       $this->deleteFeedItems($feed);
24     }
25
26     // Delete feed.
27     $this->deleteFeed($feed);
28
29     // Test updating feed items without valid timestamp information.
30     $edit = [
31       'title[0][value]' => "Feed without publish timestamp",
32       'url[0][value]' => $this->getRSS091Sample(),
33     ];
34
35     $this->drupalGet($edit['url[0][value]']);
36     $this->assertResponse(200);
37
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]']]));
40
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');
44
45     $fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", [':url' => $edit['url[0][value]']])->fetchField();
46     $feed = Feed::load($fid);
47
48     $feed->refreshItems();
49     $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
50
51     // Sleep for 3 second.
52     sleep(3);
53     db_update('aggregator_feed')
54       ->condition('fid', $feed->id())
55       ->fields([
56         'checked' => 0,
57         'hash' => '',
58         'etag' => '',
59         'modified' => 0,
60       ])
61       ->execute();
62     $feed->refreshItems();
63
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]));
66
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);
73   }
74
75 }