Commit 38ea2f11 authored by alexpott's avatar alexpott
Browse files

Issue #2424745 by martin107: aggregator module document tidy

parent bda20663
......@@ -54,4 +54,3 @@ public function getViewsData() {
}
}
......@@ -22,7 +22,6 @@ public function getViewsData() {
$data['aggregator_item']['table']['base']['help'] = $this->t('Aggregator items are imported from external RSS and Atom news feeds.');
$data['aggregator_item']['iid']['help'] = $this->t('The unique ID of the aggregator item.');
$data['aggregator_item']['iid']['argument']['id'] = 'aggregator_iid';
$data['aggregator_item']['iid']['argument']['name field'] = 'title';
......@@ -49,4 +48,3 @@ public function getViewsData() {
}
}
......@@ -143,7 +143,7 @@ public function adminOverview() {
);
$links['update'] = array(
'title' => $this->t('Update items'),
'url' => Url::fromRoute('aggregator.feed_refresh', ['aggregator_feed' => $feed->id()])
'url' => Url::fromRoute('aggregator.feed_refresh', ['aggregator_feed' => $feed->id()]),
);
$row[] = array(
'data' => array(
......
......@@ -147,7 +147,7 @@ public function setTitle($title) {
/**
* {@inheritdoc}
*/
public function getLink() {
public function getLink() {
return $this->get('link')->value;
}
......
......@@ -23,7 +23,7 @@ class FeedStorage extends SqlContentEntityStorage implements FeedStorageInterfac
public function getFeedIdsToRefresh() {
return $this->database->query('SELECT fid FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', array(
':time' => REQUEST_TIME,
':never' => AGGREGATOR_CLEAR_NEVER
':never' => AGGREGATOR_CLEAR_NEVER,
))->fetchCol();
}
......
......@@ -18,8 +18,8 @@ interface FeedStorageInterface extends EntityStorageInterface {
/**
* Returns the fids of feeds that need to be refreshed.
*
* @return array
* A list of feed ids to be refreshed.
* @return array
* A list of feed ids to be refreshed.
*/
public function getFeedIdsToRefresh();
......
......@@ -18,7 +18,7 @@ interface ItemInterface extends ContentEntityInterface {
* Returns the feed id of aggregator item.
*
* @return int
* The feed id.
* The feed id.
*/
public function getFeedId();
......@@ -26,7 +26,7 @@ public function getFeedId();
* Sets the feed id of aggregator item.
*
* @param int $fid
* The feed id
* The feed id.
*
* @return \Drupal\aggregator\ItemInterface
* The called feed item entity.
......@@ -65,6 +65,7 @@ public function getLink();
*
* @param string $link
* The link to the feed item.
*
* @return \Drupal\aggregator\ItemInterface
* The called feed item entity.
*/
......@@ -83,6 +84,7 @@ public function getAuthor();
*
* @param string $author
* The author name of the feed item.
*
* @return \Drupal\aggregator\ItemInterface
* The called feed item entity.
*/
......
......@@ -34,7 +34,7 @@ interface FetcherInterface {
* Download the data at the URL and expose it
* to other modules by attaching it to $feed->source_string.
*
* @return
* @return bool
* TRUE if fetching was successful, FALSE otherwise.
*/
public function fetch(FeedInterface $feed);
......
......@@ -11,6 +11,8 @@
use Drupal\Core\Queue\QueueWorkerBase;
/**
* Updates a feed's items.
*
* @QueueWorker(
* id = "aggregator_feeds",
* title = @Translation("Aggregator refresh"),
......
......@@ -96,7 +96,6 @@ public function fetch(FeedInterface $feed) {
$feed->http_headers = $response->getHeaders();
// Update the feed URL in case of a 301 redirect.
if ($response->getEffectiveUrl() != $feed->getUrl()) {
$feed->setUrl($response->getEffectiveUrl());
}
......@@ -104,7 +103,7 @@ public function fetch(FeedInterface $feed) {
}
catch (RequestException $e) {
$this->logger->warning('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage()));
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())) , 'warning');
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())), 'warning');
return FALSE;
}
}
......
......@@ -22,7 +22,7 @@
class Fid extends Numeric {
/**
* The entity manager service
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
......@@ -55,7 +55,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
function titleQuery() {
public function titleQuery() {
$titles = array();
$feeds = $this->entityManager->getStorage('aggregator_feed')->loadMultiple($this->value);
......
......@@ -22,7 +22,7 @@
class Iid extends Numeric {
/**
* The entity manager service
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
......@@ -55,7 +55,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
function titleQuery() {
public function titleQuery() {
$titles = array();
$items = $this->entityManager->getStorage('aggregator_item')->loadMultiple($this->value);
......
......@@ -15,8 +15,9 @@
use Drupal\views\ViewExecutable;
/**
* Defines a field handler that turns an item's title into a clickable link to
* the original source article.
* Defines a field handler that turns an item's title into a clickable link.
*
* The link refers to the original source article.
*
* @ingroup views_field_handlers
*
......
......@@ -16,7 +16,7 @@ class AddFeedTest extends AggregatorTestBase {
/**
* Creates and ensures that a feed is unique, checks source, and deletes feed.
*/
function testAddFeed() {
public function testAddFeed() {
$feed = $this->createFeed();
$feed->refreshItems();
......@@ -47,7 +47,7 @@ function testAddFeed() {
/**
* Tests feeds with very long URLs.
*/
function testAddLongFeed() {
public function testAddLongFeed() {
// Create a feed with a URL of > 255 characters.
$long_url = "https://www.google.com/search?ix=heb&sourceid=chrome&ie=UTF-8&q=angie+byron#sclient=psy-ab&hl=en&safe=off&source=hp&q=angie+byron&pbx=1&oq=angie+byron&aq=f&aqi=&aql=&gs_sm=3&gs_upl=0l0l0l10534l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=a70b6b1f0abe28d8&biw=1629&bih=889&ix=heb";
$feed = $this->createFeed($long_url);
......
......@@ -16,7 +16,7 @@ class AggregatorConfigurationTest extends AggregatorTestBase {
/**
* Tests the settings form to ensure the correct default values are used.
*/
function testSettingsPage() {
public function testSettingsPage() {
$this->drupalGet('admin/config');
$this->clickLink('Feed aggregator');
$this->clickLink('Settings');
......
......@@ -30,6 +30,9 @@ abstract class AggregatorTestBase extends WebTestBase {
*/
public static $modules = array('node', 'aggregator', 'aggregator_test', 'views');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......@@ -58,7 +61,7 @@ protected function setUp() {
*
* @see getFeedEditArray()
*/
function createFeed($feed_url = NULL, array $edit = array()) {
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]'])));
......@@ -74,7 +77,7 @@ function createFeed($feed_url = NULL, array $edit = array()) {
* @param \Drupal\aggregator\FeedInterface $feed
* Feed object representing the feed.
*/
function deleteFeed(FeedInterface $feed) {
public function deleteFeed(FeedInterface $feed) {
$this->drupalPostForm('aggregator/sources/' . $feed->id() . '/delete', array(), t('Delete'));
$this->assertRaw(t('The feed %title has been deleted.', array('%title' => $feed->label())), 'Feed deleted successfully.');
}
......@@ -91,7 +94,7 @@ function deleteFeed(FeedInterface $feed) {
* @return array
* A feed array.
*/
function getFeedEditArray($feed_url = NULL, array $edit = array()) {
public function getFeedEditArray($feed_url = NULL, array $edit = array()) {
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = \Drupal::url('view.frontpage.feed_1', array(), array(
......@@ -119,7 +122,7 @@ function getFeedEditArray($feed_url = NULL, array $edit = array()) {
* @return \Drupal\aggregator\FeedInterface
* A feed object.
*/
function getFeedEditObject($feed_url = NULL, array $values = array()) {
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(
......@@ -141,7 +144,7 @@ function getFeedEditObject($feed_url = NULL, array $values = array()) {
* @return int
* Number of feed items on default feed created by createFeed().
*/
function getDefaultFeedItemCount() {
public function getDefaultFeedItemCount() {
// Our tests are based off of rss.xml, so let's find out how many elements should be related.
$feed_count = db_query_range('SELECT COUNT(DISTINCT nid) FROM {node_field_data} n WHERE n.promote = 1 AND n.status = 1', 0, $this->config('system.rss')->get('items.limit'))->fetchField();
return $feed_count > 10 ? 10 : $feed_count;
......@@ -158,7 +161,7 @@ function getDefaultFeedItemCount() {
* @param int|null $expected_count
* Expected number of feed items. If omitted no check will happen.
*/
function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
// First, let's ensure we can get to the rss xml.
$this->drupalGet($feed->getUrl());
$this->assertResponse(200, format_string('!url is reachable.', array('!url' => $feed->getUrl())));
......@@ -190,7 +193,7 @@ function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
* @param \Drupal\aggregator\FeedInterface $feed
* Feed object representing the feed.
*/
function deleteFeedItems(FeedInterface $feed) {
public function deleteFeedItems(FeedInterface $feed) {
$this->drupalPostForm('admin/config/services/aggregator/delete/' . $feed->id(), array(), t('Delete items'));
$this->assertRaw(t('The news items from %title have been deleted.', array('%title' => $feed->label())), 'Feed items deleted.');
}
......@@ -203,7 +206,7 @@ function deleteFeedItems(FeedInterface $feed) {
* @param int $expected_count
* Expected number of feed items.
*/
function updateAndDelete(FeedInterface $feed, $expected_count) {
public function updateAndDelete(FeedInterface $feed, $expected_count) {
$this->updateFeedItems($feed, $expected_count);
$count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
$this->assertTrue($count);
......@@ -223,7 +226,7 @@ function updateAndDelete(FeedInterface $feed, $expected_count) {
* @return bool
* TRUE if feed is unique.
*/
function uniqueFeed($feed_name, $feed_url) {
public function uniqueFeed($feed_name, $feed_url) {
$result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed_name, ':url' => $feed_url))->fetchField();
return (1 == $result);
}
......@@ -237,7 +240,7 @@ function uniqueFeed($feed_name, $feed_url) {
* @return string
* Path to valid OPML file.
*/
function getValidOpml($feeds) {
public function getValidOpml(array $feeds) {
// Properly escape URLs so that XML parsers don't choke on them.
foreach ($feeds as &$feed) {
$feed['url[0][value]'] = htmlspecialchars($feed['url[0][value]']);
......@@ -276,7 +279,7 @@ function getValidOpml($feeds) {
* @return string
* Path to invalid OPML file.
*/
function getInvalidOpml() {
public function getInvalidOpml() {
$opml = <<<EOF
<opml>
<invalid>
......@@ -293,7 +296,7 @@ function getInvalidOpml() {
* @return string
* Path to empty OPML file.
*/
function getEmptyOpml() {
public function getEmptyOpml() {
$opml = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<opml version="1.0">
......@@ -309,17 +312,35 @@ function getEmptyOpml() {
return file_unmanaged_save_data($opml, $path);
}
function getRSS091Sample() {
/**
* Returns a example RSS091 feed.
*
* @return string
* Path to the feed.
*/
public function getRSS091Sample() {
return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/modules/aggregator_test/aggregator_test_rss091.xml';
}
function getAtomSample() {
/**
* Returns a example Atom feed.
*
* @return string
* Path to the feed.
*/
public function getAtomSample() {
// The content of this sample ATOM feed is based directly off of the
// example provided in RFC 4287.
return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/modules/aggregator_test/aggregator_test_atom.xml';
}
function getHtmlEntitiesSample() {
/**
* Returns a example feed.
*
* @return string
* Path to the feed.
*/
public function getHtmlEntitiesSample() {
return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/modules/aggregator_test/aggregator_test_title_entities.xml';
}
......@@ -329,7 +350,7 @@ function getHtmlEntitiesSample() {
* @param int $count
* (optional) The number of nodes to generate. Defaults to five.
*/
function createSampleNodes($count = 5) {
public function createSampleNodes($count = 5) {
// Post $count article nodes.
for ($i = 0; $i < $count; $i++) {
$edit = array();
......@@ -342,13 +363,13 @@ function createSampleNodes($count = 5) {
/**
* Enable the plugins coming with aggregator_test module.
*/
function enableTestPlugins() {
public function enableTestPlugins() {
$this->config('aggregator.settings')
->set('fetcher', 'aggregator_test_fetcher')
->set('parser', 'aggregator_test_parser')
->set('processors', array(
'aggregator_test_processor' => 'aggregator_test_processor',
'aggregator' => 'aggregator'
'aggregator' => 'aggregator',
))
->save();
}
......
......@@ -16,7 +16,7 @@ class DeleteFeedItemTest extends AggregatorTestBase {
/**
* Tests running "delete items" from 'admin/config/services/aggregator' page.
*/
function testDeleteFeedItem() {
public function testDeleteFeedItem() {
// Create a bunch of test feeds.
$feed_urls = array();
// No last-modified, no etag.
......
......@@ -24,7 +24,7 @@ class DeleteFeedTest extends AggregatorTestBase {
/**
* Deletes a feed and ensures that all of its services are deleted.
*/
function testDeleteFeed() {
public function testDeleteFeed() {
$feed1 = $this->createFeed();
$feed2 = $this->createFeed();
......
......@@ -11,10 +11,14 @@
* Tests the fetcher plugins functionality and discoverability.
*
* @group aggregator
*
* @see \Drupal\aggregator_test\Plugin\aggregator\fetcher\TestFetcher.
*/
class FeedFetcherPluginTest extends AggregatorTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Enable test plugins.
......
......@@ -30,6 +30,9 @@ class FeedLanguageTest extends AggregatorTestBase {
*/
protected $langcodes = array();
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment