public function testStringFormatter() { // Create an aggregator feed. $aggregator_feed = Feed::create(['title' => 'testing title', 'url' => 'http://www.example.com']); $aggregator_feed->save(); // Create an aggregator feed item. $aggregator_item = Item::create(['title' => 'test title', 'fid' => $aggregator_feed->id(), 'link' => 'http://www.example.com']); $aggregator_item->save(); // Verify aggregator feed title with and without links. $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]); $result = $this->render($build); $this->assertTrue(strpos($result, 'testing title')); $this->assertTrue(strpos($result, 'href="' . $aggregator_feed->getUrl()) . '"'); $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]); $result = $this->render($build); $this->assertTrue(strpos($result, 'testing title') === 0); $this->assertTrue(strpos($result, $aggregator_feed->getUrl()) === FALSE); // Verify aggregator item title with and without links. $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]); $result = $this->render($build); $this->assertTrue(strpos($result, 'test title')); $this->assertTrue(strpos($result, 'href="' . $aggregator_item->getLink()) . '"'); $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]); $result = $this->render($build); $this->assertTrue(strpos($result, 'test title') === 0); $this->assertTrue(strpos($result, $aggregator_item->getLink()) === FALSE); }
/** * {@inheritdoc} */ protected function createEntity() { // Create a "Llama" feed. $feed = Feed::create(array('title' => 'Llama', 'url' => 'https://www.drupal.org/', 'refresh' => 900, 'checked' => 1389919932, 'description' => 'Drupal.org')); $feed->save(); return $feed; }
/** * 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 = 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 for 3 second. 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))); // Make sure updating items works even after uninstalling a module // that provides the selected plugins. $this->enableTestPlugins(); $this->container->get('module_installer')->uninstall(array('aggregator_test')); $this->updateFeedItems($feed); $this->assertResponse(200); }
/** * Creates an aggregator feed. * * This method simulates the form submission on path aggregator/sources/add. * * @param string $feed_url * (optional) If given, feed will be created with this URL, otherwise * /rss.xml will be used. Defaults to NULL. * @param array $edit * Array with additional form fields. * * @return \Drupal\aggregator\FeedInterface * Full feed object if possible. * * @see getFeedEditArray() */ public function createFeed($feed_url = NULL, array $edit = array()) { $edit = $this->getFeedEditArray($feed_url, $edit); $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 title = :title AND url = :url", array(':title' => $edit['title[0][value]'], ':url' => $edit['url[0][value]']))->fetchField(); $this->assertTrue(!empty($fid), 'The feed found in database.'); return Feed::load($fid); }
/** * Checks access for aggregator_feed fields. */ public function testAggregatorFeedFields() { $feed = Feed::create(['title' => 'Drupal org', 'url' => 'https://www.drupal.org/rss.xml', 'link' => 'https://www.drupal.org/rss.xml']); $feed->save(); // @todo Expand the test coverage in https://www.drupal.org/node/2464635 // $this->assertFieldAccess('aggregator_feed', 'title', $feed->label()); $this->assertFieldAccess('aggregator_feed', 'langcode', $feed->language()->getName()); $this->assertFieldAccess('aggregator_feed', 'url', $feed->getUrl()); }
/** * {@inheritdoc} */ protected function createEntity() { // Create a "Camelids" feed. $feed = Feed::create(array('title' => 'Camelids', 'url' => 'https://groups.drupal.org/not_used/167169', 'refresh' => 900, 'checked' => 1389919932, 'description' => 'Drupal Core Group feed')); $feed->save(); // Create a "Llama" aggregator feed item. $item = Item::create(array('fid' => $feed->id(), 'title' => t('Llama'), 'path' => 'https://www.drupal.org/')); $item->save(); return $item; }
/** * Checks access for aggregator_item fields. */ public function testAggregatorItemFields() { $feed = Feed::create(['title' => 'Drupal org', 'url' => 'https://www.drupal.org/rss.xml']); $feed->save(); $item = Item::create(['title' => 'Test title', 'fid' => $feed->id(), 'description' => 'Test description']); $item->save(); // @todo Expand the test coverage in https://www.drupal.org/node/2464635 $this->assertFieldAccess('aggregator_item', 'title', $item->getTitle()); $this->assertFieldAccess('aggregator_item', 'langcode', $item->language()->getName()); $this->assertFieldAccess('aggregator_item', 'description', $item->getDescription()); }
/** * Test post-processing functionality. */ public function testPostProcess() { $feed = $this->createFeed(NULL, array('refresh' => 1800)); $this->updateFeedItems($feed); $feed_id = $feed->id(); // Reset entity cache manually. \Drupal::entityManager()->getStorage('aggregator_feed')->resetCache(array($feed_id)); // Reload the feed to get new values. $feed = Feed::load($feed_id); // Make sure its refresh rate doubled. $this->assertEqual($feed->getRefreshRate(), 3600); }
/** * Tests migration of aggregator feeds. */ public function testAggregatorFeedImport() { /** @var \Drupal\aggregator\Entity\Feed $feed */ $feed = Feed::load(5); $this->assertIdentical('Know Your Meme', $feed->title->value); $this->assertIdentical('en', $feed->language()->getId()); $this->assertIdentical('http://knowyourmeme.com/newsfeed.rss', $feed->url->value); $this->assertIdentical('900', $feed->refresh->value); $this->assertIdentical('1387659487', $feed->checked->value); $this->assertIdentical('0', $feed->queued->value); $this->assertIdentical('http://knowyourmeme.com', $feed->link->value); $this->assertIdentical('New items added to the News Feed', $feed->description->value); $this->assertIdentical('http://b.thumbs.redditmedia.com/harEHsUUZVajabtC.png', $feed->image->value); $this->assertIdentical('"213cc1365b96c310e92053c5551f0504"', $feed->etag->value); $this->assertIdentical('0', $feed->modified->value); }
/** * Tests the feed validation constraints. */ public function testValidation() { // Add feed. $feed = Feed::create(['title' => 'Feed 1', 'url' => 'https://www.drupal.org/planet/rss.xml', 'refresh' => 900]); $violations = $feed->validate(); $this->assertEqual(count($violations), 0); $feed->save(); // Add another feed. /* @var \Drupal\aggregator\FeedInterface $feed */ $feed = Feed::create(['title' => 'Feed 1', 'url' => 'https://www.drupal.org/planet/rss.xml', 'refresh' => 900]); $violations = $feed->validate(); $this->assertEqual(count($violations), 2); $this->assertEqual($violations[0]->getPropertyPath(), 'title'); $this->assertEqual($violations[0]->getMessage(), t('A feed named %value already exists. Enter a unique title.', ['%value' => $feed->label()])); $this->assertEqual($violations[1]->getPropertyPath(), 'url'); $this->assertEqual($violations[1]->getMessage(), t('A feed with this URL %value already exists. Enter a unique URL.', ['%value' => $feed->getUrl()])); }
/** * Tests migration of aggregator feeds. */ public function testAggregatorFeedImport() { /** @var Feed $feed */ $feed = Feed::load(5); $this->assertNotNull($feed->uuid()); $this->assertEqual($feed->title->value, 'Know Your Meme'); $this->assertEqual($feed->language()->getId(), 'en'); $this->assertEqual($feed->url->value, 'http://knowyourmeme.com/newsfeed.rss'); $this->assertEqual($feed->refresh->value, 900); $this->assertEqual($feed->checked->value, 1387659487); $this->assertEqual($feed->queued->value, 0); $this->assertEqual($feed->link->value, 'http://knowyourmeme.com'); $this->assertEqual($feed->description->value, 'New items added to the News Feed'); $this->assertEqual($feed->image->value, 'http://b.thumbs.redditmedia.com/harEHsUUZVajabtC.png'); $this->assertEqual($feed->hash->value, ''); $this->assertEqual($feed->etag->value, '"213cc1365b96c310e92053c5551f0504"'); $this->assertEqual($feed->modified->value, 0); }
/** * Tests migration of aggregator feeds. */ public function testAggregatorFeedImport() { /** @var \Drupal\aggregator\FeedInterface $feed */ $feed = Feed::load(1); $this->assertIdentical('Know Your Meme', $feed->label()); $this->assertIdentical('en', $feed->language()->getId()); $this->assertIdentical('http://knowyourmeme.com/newsfeed.rss', $feed->getUrl()); $this->assertIdentical('900', $feed->getRefreshRate()); // The feed's last checked time can change as the fixture is updated, so // assert that its format is correct. $checked_time = $feed->getLastCheckedTime(); $this->assertTrue(is_numeric($checked_time)); $this->assertTrue($checked_time > 1000000000); $this->assertIdentical('0', $feed->getQueuedTime()); $this->assertIdentical('http://knowyourmeme.com', $feed->link->value); $this->assertIdentical('New items added to the News Feed', $feed->getDescription()); $this->assertNull($feed->getImage()); // As with getLastCheckedTime(), the etag can change as the fixture is // updated normally, so assert that its format is correct. $this->assertTrue(preg_match('/^"[a-z0-9]{32}"$/', $feed->getEtag())); $this->assertIdentical('0', $feed->getLastModified()); }
/** * Returns a randomly generated feed edit object. * * @param string $feed_url * (optional) If given, feed will be created with this URL, otherwise * /rss.xml will be used. Defaults to NULL. * @param array $values * (optional) Default values to initialize object properties with. * * @return \Drupal\aggregator\FeedInterface * A feed object. */ public function getFeedEditObject($feed_url = NULL, array $values = array()) { $feed_name = $this->randomMachineName(10); if (!$feed_url) { $feed_url = \Drupal::url('view.frontpage.feed_1', array('query' => array('feed' => $feed_name), 'absolute' => TRUE)); } $values += array('title' => $feed_name, 'url' => $feed_url, 'refresh' => '900'); return Feed::create($values); }
<?php use Drupal\aggregator\Entity\Feed; // Create a new feed. $feed = Feed::create(array('title' => 'test', 'url' => 'http://drupal.org/project/issues/rss/drupal?categories=All', 'refresh' => 3600)); $feed->save(); // Let cron call QueueInterface::createItem() for us. aggregator_cron();
/** * {@inheritdoc} */ public function getCacheTag() { return Feed::load($this->getFeedId())->getCacheTag(); }
/** * {@inheritdoc} */ public function getCacheTagsToInvalidate() { return Feed::load($this->getFeedId())->getCacheTags(); }
/** * Tests error handling when an invalid feed is added. */ public function testInvalidFeed() { // Simulate a typo in the URL to force a curl exception. $invalid_url = 'http:/www.drupal.org'; $feed = Feed::create(array('url' => $invalid_url, 'title' => $this->randomMachineName())); $feed->save(); // Update the feed. Use the UI to be able to check the message easily. $this->drupalGet('admin/config/services/aggregator'); $this->clickLink(t('Update items')); $this->assertRaw(t('The feed from %title seems to be broken because of error', array('%title' => $feed->label()))); }