Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[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   /**
15    * Tests running "update items" from 'admin/config/services/aggregator' page.
16    */
17   public function testUpdateFeedItem() {
18     $this->createSampleNodes();
19
20     // Create a feed and test updating feed items if possible.
21     $feed = $this->createFeed();
22     if (!empty($feed)) {
23       $this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
24       $this->deleteFeedItems($feed);
25     }
26
27     // Delete feed.
28     $this->deleteFeed($feed);
29
30     // Test updating feed items without valid timestamp information.
31     $edit = [
32       'title[0][value]' => "Feed without publish timestamp",
33       'url[0][value]' => $this->getRSS091Sample(),
34     ];
35
36     $this->drupalGet($edit['url[0][value]']);
37     $this->assertResponse(200);
38
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]']]));
41
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');
45
46     $fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", [':url' => $edit['url[0][value]']])->fetchField();
47     $feed = Feed::load($fid);
48
49     $feed->refreshItems();
50     $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
51
52     // Sleep for 3 second.
53     sleep(3);
54     db_update('aggregator_feed')
55       ->condition('fid', $feed->id())
56       ->fields([
57         'checked' => 0,
58         'hash' => '',
59         'etag' => '',
60         'modified' => 0,
61       ])
62       ->execute();
63     $feed->refreshItems();
64
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]));
67
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);
74   }
75
76 }