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