UpdateFeedItemTest.php in Drupal 9
File
core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php
View source
<?php
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\Entity\Item;
class UpdateFeedItemTest extends AggregatorTestBase {
protected $defaultTheme = 'stark';
public function testUpdateFeedItem() {
$this
->createSampleNodes();
$feed = $this
->createFeed();
if (!empty($feed)) {
$this
->updateFeedItems($feed, $this
->getDefaultFeedItemCount());
$this
->deleteFeedItems($feed);
}
$this
->deleteFeed($feed);
$edit = [
'title[0][value]' => "Feed without publish timestamp",
'url[0][value]' => $this
->getRSS091Sample(),
];
$this
->drupalGet($edit['url[0][value]']);
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('aggregator/sources/add');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The feed ' . $edit['title[0][value]'] . ' has been added.');
$this
->assertSession()
->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
$fids = \Drupal::entityQuery('aggregator_feed')
->accessCheck(FALSE)
->condition('url', $edit['url[0][value]'])
->execute();
$feed = Feed::load(array_values($fids)[0]);
$feed
->refreshItems();
$item_ids = \Drupal::entityQuery('aggregator_item')
->accessCheck(FALSE)
->condition('fid', $feed
->id())
->execute();
$before = Item::load(array_values($item_ids)[0])
->getPostedTime();
sleep(3);
$feed
->setLastCheckedTime(0)
->setHash('')
->setEtag('')
->setLastModified(0)
->save();
$feed
->refreshItems();
$after = Item::load(array_values($item_ids)[0])
->getPostedTime();
$this
->assertSame($before, $after, new FormattableMarkup('Publish timestamp of feed item was not updated (@before === @after)', [
'@before' => $before,
'@after' => $after,
]));
$this
->enableTestPlugins();
$this->container
->get('module_installer')
->uninstall([
'aggregator_test',
]);
$this
->updateFeedItems($feed);
$this
->assertSession()
->statusCodeEquals(200);
}
}