class UpdateFeedItemTest
Same name and namespace in other branches
- 8.9.x core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php \Drupal\Tests\aggregator\Functional\UpdateFeedItemTest
Update feed items from a feed.
@group aggregator @group legacy
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\aggregator\Functional\AggregatorTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\aggregator\Functional\UpdateFeedItemTest extends \Drupal\Tests\aggregator\Functional\AggregatorTestBase
- class \Drupal\Tests\aggregator\Functional\AggregatorTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of UpdateFeedItemTest
File
-
core/
modules/ aggregator/ tests/ src/ Functional/ UpdateFeedItemTest.php, line 15
Namespace
Drupal\Tests\aggregator\FunctionalView source
class UpdateFeedItemTest extends AggregatorTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests running "update items" from 'admin/config/services/aggregator' page.
*/
public function testUpdateFeedItem() {
$this->createSampleNodes();
// Create a feed and test updating feed items if possible.
$feed = $this->createFeed();
if (!empty($feed)) {
$this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
$this->deleteFeedItems($feed);
}
// Delete feed.
$this->deleteFeed($feed);
// Test updating feed items without valid timestamp information.
$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.');
// Verify that the creation message contains a link to a feed.
$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 for 3 second.
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,
]));
// Make sure updating items works even after uninstalling a module
// that provides the selected plugins.
$this->enableTestPlugins();
$this->container
->get('module_installer')
->uninstall([
'aggregator_test',
]);
$this->updateFeedItems($feed);
$this->assertSession()
->statusCodeEquals(200);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.