View source
<?php
namespace Drupal\aggregator\Tests;
use Drupal\aggregator\Entity\Feed;
class UpdateFeedItemTest extends AggregatorTestBase {
public function testUpdateFeedItem() {
$this
->createSampleNodes();
$feed = $this
->createFeed();
if (!empty($feed)) {
$this
->updateFeedItems($feed, $this
->getDefaultFeedItemCount());
$this
->deleteFeedItems($feed);
}
$this
->deleteFeed($feed);
$edit = array(
'title[0][value]' => "Feed without publish timestamp",
'url[0][value]' => $this
->getRSS091Sample(),
);
$this
->drupalGet($edit['url[0][value]']);
$this
->assertResponse(200);
$this
->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
$this
->assertRaw(t('The feed %name has been added.', array(
'%name' => $edit['title[0][value]'],
)), format_string('The feed @name has been added.', array(
'@name' => $edit['title[0][value]'],
)));
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", array(
':url' => $edit['url[0][value]'],
))
->fetchField();
$feed = Feed::load($fid);
$feed
->refreshItems();
$before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(
':fid' => $feed
->id(),
))
->fetchField();
sleep(3);
db_update('aggregator_feed')
->condition('fid', $feed
->id())
->fields(array(
'checked' => 0,
'hash' => '',
'etag' => '',
'modified' => 0,
))
->execute();
$feed
->refreshItems();
$after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(
':fid' => $feed
->id(),
))
->fetchField();
$this
->assertTrue($before === $after, format_string('Publish timestamp of feed item was not updated (@before === @after)', array(
'@before' => $before,
'@after' => $after,
)));
$this
->enableTestPlugins();
$this->container
->get('module_installer')
->uninstall(array(
'aggregator_test',
));
$this
->updateFeedItems($feed);
$this
->assertResponse(200);
}
}