Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -15,12 +15,12 @@ class AggregatorFeedViewsData extends EntityViewsData {
|
|||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
$data['aggregator_feed']['table']['join'] = array(
|
||||
'aggregator_item' => array(
|
||||
$data['aggregator_feed']['table']['join'] = [
|
||||
'aggregator_item' => [
|
||||
'left_field' => 'fid',
|
||||
'field' => 'fid',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$data['aggregator_feed']['fid']['help'] = $this->t('The unique ID of the aggregator feed.');
|
||||
$data['aggregator_feed']['fid']['argument']['id'] = 'aggregator_fid';
|
||||
|
|
|
@ -48,9 +48,9 @@ class AggregatorController extends ControllerBase {
|
|||
*/
|
||||
public function feedAdd() {
|
||||
$feed = $this->entityManager()->getStorage('aggregator_feed')
|
||||
->create(array(
|
||||
->create([
|
||||
'refresh' => 3600,
|
||||
));
|
||||
]);
|
||||
return $this->entityFormBuilder()->getForm($feed);
|
||||
}
|
||||
|
||||
|
@ -67,15 +67,15 @@ class AggregatorController extends ControllerBase {
|
|||
*/
|
||||
protected function buildPageList(array $items, $feed_source = '') {
|
||||
// Assemble output.
|
||||
$build = array(
|
||||
$build = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array('class' => array('aggregator-wrapper')),
|
||||
);
|
||||
$build['feed_source'] = is_array($feed_source) ? $feed_source : array('#markup' => $feed_source);
|
||||
'#attributes' => ['class' => ['aggregator-wrapper']],
|
||||
];
|
||||
$build['feed_source'] = is_array($feed_source) ? $feed_source : ['#markup' => $feed_source];
|
||||
if ($items) {
|
||||
$build['items'] = $this->entityManager()->getViewBuilder('aggregator_item')
|
||||
->viewMultiple($items, 'default');
|
||||
$build['pager'] = array('#type' => 'pager');
|
||||
$build['pager'] = ['#type' => 'pager'];
|
||||
}
|
||||
return $build;
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ class AggregatorController extends ControllerBase {
|
|||
*/
|
||||
public function feedRefresh(FeedInterface $aggregator_feed) {
|
||||
$message = $aggregator_feed->refreshItems()
|
||||
? $this->t('There is new syndicated content from %site.', array('%site' => $aggregator_feed->label()))
|
||||
: $this->t('There is no new syndicated content from %site.', array('%site' => $aggregator_feed->label()));
|
||||
? $this->t('There is new syndicated content from %site.', ['%site' => $aggregator_feed->label()])
|
||||
: $this->t('There is no new syndicated content from %site.', ['%site' => $aggregator_feed->label()]);
|
||||
drupal_set_message($message);
|
||||
return $this->redirect('aggregator.admin_overview');
|
||||
}
|
||||
|
@ -111,22 +111,22 @@ class AggregatorController extends ControllerBase {
|
|||
$feeds = $entity_manager->getStorage('aggregator_feed')
|
||||
->loadMultiple();
|
||||
|
||||
$header = array($this->t('Title'), $this->t('Items'), $this->t('Last update'), $this->t('Next update'), $this->t('Operations'));
|
||||
$rows = array();
|
||||
$header = [$this->t('Title'), $this->t('Items'), $this->t('Last update'), $this->t('Next update'), $this->t('Operations')];
|
||||
$rows = [];
|
||||
/** @var \Drupal\aggregator\FeedInterface[] $feeds */
|
||||
foreach ($feeds as $feed) {
|
||||
$row = array();
|
||||
$row = [];
|
||||
$row[] = $feed->link();
|
||||
$row[] = $this->formatPlural($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
|
||||
$last_checked = $feed->getLastCheckedTime();
|
||||
$refresh_rate = $feed->getRefreshRate();
|
||||
|
||||
$row[] = ($last_checked ? $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked))) : $this->t('never'));
|
||||
$row[] = ($last_checked ? $this->t('@time ago', ['@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked)]) : $this->t('never'));
|
||||
if (!$last_checked && $refresh_rate) {
|
||||
$next_update = $this->t('imminently');
|
||||
}
|
||||
elseif ($last_checked && $refresh_rate) {
|
||||
$next_update = $next = $this->t('%time left', array('%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME)));
|
||||
$next_update = $next = $this->t('%time left', ['%time' => $this->dateFormatter->formatInterval($last_checked + $refresh_rate - REQUEST_TIME)]);
|
||||
}
|
||||
else {
|
||||
$next_update = $this->t('never');
|
||||
|
@ -136,33 +136,33 @@ class AggregatorController extends ControllerBase {
|
|||
'title' => $this->t('Edit'),
|
||||
'url' => Url::fromRoute('entity.aggregator_feed.edit_form', ['aggregator_feed' => $feed->id()]),
|
||||
];
|
||||
$links['delete'] = array(
|
||||
$links['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('entity.aggregator_feed.delete_form', ['aggregator_feed' => $feed->id()]),
|
||||
);
|
||||
$links['delete_items'] = array(
|
||||
];
|
||||
$links['delete_items'] = [
|
||||
'title' => $this->t('Delete items'),
|
||||
'url' => Url::fromRoute('aggregator.feed_items_delete', ['aggregator_feed' => $feed->id()]),
|
||||
);
|
||||
$links['update'] = array(
|
||||
];
|
||||
$links['update'] = [
|
||||
'title' => $this->t('Update items'),
|
||||
'url' => Url::fromRoute('aggregator.feed_refresh', ['aggregator_feed' => $feed->id()]),
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => array(
|
||||
];
|
||||
$row[] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$rows[] = $row;
|
||||
}
|
||||
$build['feeds'] = array(
|
||||
$build['feeds'] = [
|
||||
'#prefix' => '<h3>' . $this->t('Feed overview') . '</h3>',
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => $this->t('No feeds available. <a href=":link">Add feed</a>.', array(':link' => $this->url('aggregator.feed_add'))),
|
||||
);
|
||||
'#empty' => $this->t('No feeds available. <a href=":link">Add feed</a>.', [':link' => $this->url('aggregator.feed_add')]),
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class AggregatorController extends ControllerBase {
|
|||
public function pageLast() {
|
||||
$items = $this->entityManager()->getStorage('aggregator_item')->loadAll(20);
|
||||
$build = $this->buildPageList($items);
|
||||
$build['#attached']['feed'][] = array('aggregator/rss', $this->config('system.site')->get('name') . ' ' . $this->t('aggregator'));
|
||||
$build['#attached']['feed'][] = ['aggregator/rss', $this->config('system.site')->get('name') . ' ' . $this->t('aggregator')];
|
||||
return $build;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,11 +88,11 @@ class Feed extends ContentEntityBase implements FeedInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage, array &$values) {
|
||||
$values += array(
|
||||
$values += [
|
||||
'link' => '',
|
||||
'description' => '',
|
||||
'image' => '',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,10 +143,10 @@ class Feed extends ContentEntityBase implements FeedInterface {
|
|||
->setDescription(t('The name of the feed (or the name of the website providing the feed).'))
|
||||
->setRequired(TRUE)
|
||||
->setSetting('max_length', 255)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -5,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->addConstraint('FeedTitle');
|
||||
|
||||
|
@ -154,15 +154,15 @@ class Feed extends ContentEntityBase implements FeedInterface {
|
|||
->setLabel(t('URL'))
|
||||
->setDescription(t('The fully-qualified URL of the feed.'))
|
||||
->setRequired(TRUE)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'uri',
|
||||
'weight' => -3,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->addConstraint('FeedUrl');
|
||||
|
||||
$intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200);
|
||||
$period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($intervals, $intervals));
|
||||
$intervals = [900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200];
|
||||
$period = array_map([\Drupal::service('date.formatter'), 'formatInterval'], array_combine($intervals, $intervals));
|
||||
$period[AGGREGATOR_CLEAR_NEVER] = t('Never');
|
||||
|
||||
$fields['refresh'] = BaseFieldDefinition::create('list_integer')
|
||||
|
@ -171,21 +171,21 @@ class Feed extends ContentEntityBase implements FeedInterface {
|
|||
->setSetting('unsigned', TRUE)
|
||||
->setRequired(TRUE)
|
||||
->setSetting('allowed_values', $period)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'options_select',
|
||||
'weight' => -2,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['checked'] = BaseFieldDefinition::create('timestamp')
|
||||
->setLabel(t('Checked'))
|
||||
->setDescription(t('Last time feed was checked for new items, as Unix timestamp.'))
|
||||
->setDefaultValue(0)
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'inline',
|
||||
'type' => 'timestamp_ago',
|
||||
'weight' => 1,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
$fields['queued'] = BaseFieldDefinition::create('timestamp')
|
||||
|
@ -196,15 +196,15 @@ class Feed extends ContentEntityBase implements FeedInterface {
|
|||
$fields['link'] = BaseFieldDefinition::create('uri')
|
||||
->setLabel(t('URL'))
|
||||
->setDescription(t('The link of the feed.'))
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'inline',
|
||||
'weight' => 4,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
$fields['description'] = BaseFieldDefinition::create('string_long')
|
||||
->setLabel(t('Description'))
|
||||
->setDescription(t("The parent website's description that comes from the @description element in the feed.", array('@description' => '<description>')));
|
||||
->setDescription(t("The parent website's description that comes from the @description element in the feed.", ['@description' => '<description>']));
|
||||
|
||||
$fields['image'] = BaseFieldDefinition::create('uri')
|
||||
->setLabel(t('Image'))
|
||||
|
|
|
@ -61,11 +61,11 @@ class Item extends ContentEntityBase implements ItemInterface {
|
|||
->setRequired(TRUE)
|
||||
->setDescription(t('The aggregator feed entity associated with this item.'))
|
||||
->setSetting('target_type', 'aggregator_feed')
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'entity_reference_label',
|
||||
'weight' => 0,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['title'] = BaseFieldDefinition::create('string')
|
||||
|
@ -75,18 +75,18 @@ class Item extends ContentEntityBase implements ItemInterface {
|
|||
$fields['link'] = BaseFieldDefinition::create('uri')
|
||||
->setLabel(t('Link'))
|
||||
->setDescription(t('The link of the feed item.'))
|
||||
->setDisplayOptions('view', array(
|
||||
'type' => 'hidden',
|
||||
))
|
||||
->setDisplayOptions('view', [
|
||||
'region' => 'hidden',
|
||||
])
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
$fields['author'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Author'))
|
||||
->setDescription(t('The author of the feed item.'))
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'weight' => 3,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
$fields['description'] = BaseFieldDefinition::create('string_long')
|
||||
|
@ -96,11 +96,11 @@ class Item extends ContentEntityBase implements ItemInterface {
|
|||
$fields['timestamp'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Posted on'))
|
||||
->setDescription(t('Posted date of the feed item, as a Unix timestamp.'))
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'timestamp_ago',
|
||||
'weight' => 1,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
// @todo Convert to a real UUID field in
|
||||
|
|
|
@ -20,12 +20,12 @@ class FeedForm extends ContentEntityForm {
|
|||
$label = $feed->label();
|
||||
$view_link = $feed->link($label, 'canonical');
|
||||
if ($status == SAVED_UPDATED) {
|
||||
drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $view_link)));
|
||||
drupal_set_message($this->t('The feed %feed has been updated.', ['%feed' => $view_link]));
|
||||
$form_state->setRedirectUrl($feed->urlInfo('canonical'));
|
||||
}
|
||||
else {
|
||||
$this->logger('aggregator')->notice('Feed %feed added.', array('%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview'))));
|
||||
drupal_set_message($this->t('The feed %feed has been added.', array('%feed' => $view_link)));
|
||||
$this->logger('aggregator')->notice('Feed %feed added.', ['%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview'))]);
|
||||
drupal_set_message($this->t('The feed %feed has been added.', ['%feed' => $view_link]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@ class FeedStorage extends SqlContentEntityStorage implements FeedStorageInterfac
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFeedIdsToRefresh() {
|
||||
return $this->database->query('SELECT fid FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', array(
|
||||
return $this->database->query('SELECT fid FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', [
|
||||
':time' => REQUEST_TIME,
|
||||
':never' => AGGREGATOR_CLEAR_NEVER,
|
||||
))->fetchCol();
|
||||
])->fetchCol();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,11 @@ use Drupal\Core\Entity\ContentEntityStorageInterface;
|
|||
*/
|
||||
interface FeedStorageInterface extends ContentEntityStorageInterface {
|
||||
|
||||
/**
|
||||
* Denotes that a feed's items should never expire.
|
||||
*/
|
||||
const CLEAR_NEVER = 0;
|
||||
|
||||
/**
|
||||
* Returns the fids of feeds that need to be refreshed.
|
||||
*
|
||||
|
|
|
@ -24,9 +24,6 @@ class FeedStorageSchema extends SqlContentEntityStorageSchema {
|
|||
break;
|
||||
|
||||
case 'queued':
|
||||
$this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
|
||||
break;
|
||||
|
||||
case 'title':
|
||||
$this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
|
||||
break;
|
||||
|
|
|
@ -68,65 +68,65 @@ class FeedViewBuilder extends EntityViewBuilder {
|
|||
|
||||
if ($view_mode == 'full') {
|
||||
// Also add the pager.
|
||||
$build[$id]['pager'] = array('#type' => 'pager');
|
||||
$build[$id]['pager'] = ['#type' => 'pager'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($display->getComponent('description')) {
|
||||
$build[$id]['description'] = array(
|
||||
$build[$id]['description'] = [
|
||||
'#markup' => $entity->getDescription(),
|
||||
'#allowed_tags' => _aggregator_allowed_tags(),
|
||||
'#prefix' => '<div class="feed-description">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
if ($display->getComponent('image')) {
|
||||
$image_link = array();
|
||||
$image_link = [];
|
||||
// Render the image as link if it is available.
|
||||
$image = $entity->getImage();
|
||||
$label = $entity->label();
|
||||
$link_href = $entity->getWebsiteUrl();
|
||||
if ($image && $label && $link_href) {
|
||||
$link_title = array(
|
||||
$link_title = [
|
||||
'#theme' => 'image',
|
||||
'#uri' => $image,
|
||||
'#alt' => $label,
|
||||
);
|
||||
$image_link = array(
|
||||
];
|
||||
$image_link = [
|
||||
'#type' => 'link',
|
||||
'#title' => $link_title,
|
||||
'#url' => Url::fromUri($link_href),
|
||||
'#options' => array(
|
||||
'attributes' => array('class' => array('feed-image')),
|
||||
),
|
||||
);
|
||||
'#options' => [
|
||||
'attributes' => ['class' => ['feed-image']],
|
||||
],
|
||||
];
|
||||
}
|
||||
$build[$id]['image'] = $image_link;
|
||||
}
|
||||
|
||||
if ($display->getComponent('feed_icon')) {
|
||||
$build[$id]['feed_icon'] = array(
|
||||
$build[$id]['feed_icon'] = [
|
||||
'#theme' => 'feed_icon',
|
||||
'#url' => $entity->getUrl(),
|
||||
'#title' => t('@title feed', array('@title' => $entity->label())),
|
||||
);
|
||||
'#title' => t('@title feed', ['@title' => $entity->label()]),
|
||||
];
|
||||
}
|
||||
|
||||
if ($display->getComponent('more_link')) {
|
||||
$title_stripped = strip_tags($entity->label());
|
||||
$build[$id]['more_link'] = array(
|
||||
$build[$id]['more_link'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => t('More<span class="visually-hidden"> posts about @title</span>', array(
|
||||
'#title' => t('More<span class="visually-hidden"> posts about @title</span>', [
|
||||
'@title' => $title_stripped,
|
||||
)),
|
||||
]),
|
||||
'#url' => Url::fromRoute('entity.aggregator_feed.canonical', ['aggregator_feed' => $entity->id()]),
|
||||
'#options' => array(
|
||||
'attributes' => array(
|
||||
'#options' => [
|
||||
'attributes' => [
|
||||
'title' => $title_stripped,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ class FeedDeleteForm extends ContentEntityDeleteForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDeletionMessage() {
|
||||
return $this->t('The feed %label has been deleted.', array(
|
||||
return $this->t('The feed %label has been deleted.', [
|
||||
'%label' => $this->entity->label(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class FeedItemsDeleteForm extends ContentEntityConfirmFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to delete all items from the feed %feed?', array('%feed' => $this->entity->label()));
|
||||
return $this->t('Are you sure you want to delete all items from the feed %feed?', ['%feed' => $this->entity->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,33 +63,33 @@ class OpmlFeedAdd extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200);
|
||||
$period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($intervals, $intervals));
|
||||
$intervals = [900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200];
|
||||
$period = array_map([\Drupal::service('date.formatter'), 'formatInterval'], array_combine($intervals, $intervals));
|
||||
|
||||
$form['upload'] = array(
|
||||
$form['upload'] = [
|
||||
'#type' => 'file',
|
||||
'#title' => $this->t('OPML File'),
|
||||
'#description' => $this->t('Upload an OPML file containing a list of feeds to be imported.'),
|
||||
);
|
||||
$form['remote'] = array(
|
||||
];
|
||||
$form['remote'] = [
|
||||
'#type' => 'url',
|
||||
'#title' => $this->t('OPML Remote URL'),
|
||||
'#maxlength' => 1024,
|
||||
'#description' => $this->t('Enter the URL of an OPML file. This file will be downloaded and processed only once on submission of the form.'),
|
||||
);
|
||||
$form['refresh'] = array(
|
||||
];
|
||||
$form['refresh'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Update interval'),
|
||||
'#default_value' => 3600,
|
||||
'#options' => $period,
|
||||
'#description' => $this->t('The length of time between feed updates. Requires a correctly configured <a href=":cron">cron maintenance task</a>.', array(':cron' => $this->url('system.status'))),
|
||||
);
|
||||
'#description' => $this->t('The length of time between feed updates. Requires a correctly configured <a href=":cron">cron maintenance task</a>.', [':cron' => $this->url('system.status')]),
|
||||
];
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Import'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ class OpmlFeedAdd extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$validators = array('file_validate_extensions' => array('opml xml'));
|
||||
$validators = ['file_validate_extensions' => ['opml xml']];
|
||||
if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
|
||||
$data = file_get_contents($file->getFileUri());
|
||||
}
|
||||
|
@ -120,8 +120,8 @@ class OpmlFeedAdd extends FormBase {
|
|||
$data = (string) $response->getBody();
|
||||
}
|
||||
catch (RequestException $e) {
|
||||
$this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()));
|
||||
drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
|
||||
$this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', ['%error' => $e->getMessage()]);
|
||||
drupal_set_message($this->t('Failed to download OPML file due to "%error".', ['%error' => $e->getMessage()]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ class OpmlFeedAdd extends FormBase {
|
|||
foreach ($feeds as $feed) {
|
||||
// Ensure URL is valid.
|
||||
if (!UrlHelper::isValid($feed['url'], TRUE)) {
|
||||
drupal_set_message($this->t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');
|
||||
drupal_set_message($this->t('The URL %url is invalid.', ['%url' => $feed['url']]), 'warning');
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -151,20 +151,20 @@ class OpmlFeedAdd extends FormBase {
|
|||
$result = $this->feedStorage->loadMultiple($ids);
|
||||
foreach ($result as $old) {
|
||||
if (strcasecmp($old->label(), $feed['title']) == 0) {
|
||||
drupal_set_message($this->t('A feed named %title already exists.', array('%title' => $old->label())), 'warning');
|
||||
drupal_set_message($this->t('A feed named %title already exists.', ['%title' => $old->label()]), 'warning');
|
||||
continue 2;
|
||||
}
|
||||
if (strcasecmp($old->getUrl(), $feed['url']) == 0) {
|
||||
drupal_set_message($this->t('A feed with the URL %url already exists.', array('%url' => $old->getUrl())), 'warning');
|
||||
drupal_set_message($this->t('A feed with the URL %url already exists.', ['%url' => $old->getUrl()]), 'warning');
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$new_feed = $this->feedStorage->create(array(
|
||||
$new_feed = $this->feedStorage->create([
|
||||
'title' => $feed['title'],
|
||||
'url' => $feed['url'],
|
||||
'refresh' => $form_state->getValue('refresh'),
|
||||
));
|
||||
]);
|
||||
$new_feed->save();
|
||||
}
|
||||
|
||||
|
@ -189,14 +189,15 @@ class OpmlFeedAdd extends FormBase {
|
|||
* @todo Move this to a parser in https://www.drupal.org/node/1963540.
|
||||
*/
|
||||
protected function parseOpml($opml) {
|
||||
$feeds = array();
|
||||
$xml_parser = drupal_xml_parser_create($opml);
|
||||
$feeds = [];
|
||||
$xml_parser = xml_parser_create();
|
||||
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'utf-8');
|
||||
if (xml_parse_into_struct($xml_parser, $opml, $values)) {
|
||||
foreach ($values as $entry) {
|
||||
if ($entry['tag'] == 'OUTLINE' && isset($entry['attributes'])) {
|
||||
$item = $entry['attributes'];
|
||||
if (!empty($item['XMLURL']) && !empty($item['TEXT'])) {
|
||||
$feeds[] = array('title' => $item['TEXT'], 'url' => $item['XMLURL']);
|
||||
$feeds[] = ['title' => $item['TEXT'], 'url' => $item['XMLURL']];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,25 +21,25 @@ class SettingsForm extends ConfigFormBase {
|
|||
*
|
||||
* @var \Drupal\aggregator\Plugin\AggregatorPluginManager[]
|
||||
*/
|
||||
protected $managers = array();
|
||||
protected $managers = [];
|
||||
|
||||
/**
|
||||
* The instantiated plugin instances that have configuration forms.
|
||||
*
|
||||
* @var \Drupal\Core\Plugin\PluginFormInterface[]
|
||||
*/
|
||||
protected $configurableInstances = array();
|
||||
protected $configurableInstances = [];
|
||||
|
||||
/**
|
||||
* The aggregator plugin definitions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $definitions = array(
|
||||
'fetcher' => array(),
|
||||
'parser' => array(),
|
||||
'processor' => array(),
|
||||
);
|
||||
protected $definitions = [
|
||||
'fetcher' => [],
|
||||
'parser' => [],
|
||||
'processor' => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructs a \Drupal\aggregator\SettingsForm object.
|
||||
|
@ -58,15 +58,15 @@ class SettingsForm extends ConfigFormBase {
|
|||
public function __construct(ConfigFactoryInterface $config_factory, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager, TranslationInterface $string_translation) {
|
||||
parent::__construct($config_factory);
|
||||
$this->stringTranslation = $string_translation;
|
||||
$this->managers = array(
|
||||
$this->managers = [
|
||||
'fetcher' => $fetcher_manager,
|
||||
'parser' => $parser_manager,
|
||||
'processor' => $processor_manager,
|
||||
);
|
||||
];
|
||||
// Get all available fetcher, parser and processor definitions.
|
||||
foreach (array('fetcher', 'parser', 'processor') as $type) {
|
||||
foreach (['fetcher', 'parser', 'processor'] as $type) {
|
||||
foreach ($this->managers[$type]->getDefinitions() as $id => $definition) {
|
||||
$this->definitions[$type][$id] = SafeMarkup::format('@title <span class="description">@description</span>', array('@title' => $definition['title'], '@description' => $definition['description']));
|
||||
$this->definitions[$type][$id] = SafeMarkup::format('@title <span class="description">@description</span>', ['@title' => $definition['title'], '@description' => $definition['description']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,56 +105,56 @@ class SettingsForm extends ConfigFormBase {
|
|||
$config = $this->config('aggregator.settings');
|
||||
|
||||
// Global aggregator settings.
|
||||
$form['aggregator_allowed_html_tags'] = array(
|
||||
$form['aggregator_allowed_html_tags'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Allowed HTML tags'),
|
||||
'#size' => 80,
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $config->get('items.allowed_html'),
|
||||
'#description' => $this->t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'),
|
||||
);
|
||||
];
|
||||
|
||||
// Only show basic configuration if there are actually options.
|
||||
$basic_conf = array();
|
||||
$basic_conf = [];
|
||||
if (count($this->definitions['fetcher']) > 1) {
|
||||
$basic_conf['aggregator_fetcher'] = array(
|
||||
$basic_conf['aggregator_fetcher'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Fetcher'),
|
||||
'#description' => $this->t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'),
|
||||
'#options' => $this->definitions['fetcher'],
|
||||
'#default_value' => $config->get('fetcher'),
|
||||
);
|
||||
];
|
||||
}
|
||||
if (count($this->definitions['parser']) > 1) {
|
||||
$basic_conf['aggregator_parser'] = array(
|
||||
$basic_conf['aggregator_parser'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Parser'),
|
||||
'#description' => $this->t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'),
|
||||
'#options' => $this->definitions['parser'],
|
||||
'#default_value' => $config->get('parser'),
|
||||
);
|
||||
];
|
||||
}
|
||||
if (count($this->definitions['processor']) > 1) {
|
||||
$basic_conf['aggregator_processors'] = array(
|
||||
$basic_conf['aggregator_processors'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Processors'),
|
||||
'#description' => $this->t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'),
|
||||
'#options' => $this->definitions['processor'],
|
||||
'#default_value' => $config->get('processors'),
|
||||
);
|
||||
];
|
||||
}
|
||||
if (count($basic_conf)) {
|
||||
$form['basic_conf'] = array(
|
||||
$form['basic_conf'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Basic configuration'),
|
||||
'#description' => $this->t('For most aggregation tasks, the default settings are fine.'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
$form['basic_conf'] += $basic_conf;
|
||||
}
|
||||
|
||||
// Call buildConfigurationForm() on the active fetcher and parser.
|
||||
foreach (array('fetcher', 'parser') as $type) {
|
||||
foreach (['fetcher', 'parser'] as $type) {
|
||||
$active = $config->get($type);
|
||||
if (array_key_exists($active, $this->definitions[$type])) {
|
||||
$instance = $this->managers[$type]->createInstance($active);
|
||||
|
@ -169,7 +169,7 @@ class SettingsForm extends ConfigFormBase {
|
|||
}
|
||||
|
||||
// Implementing processor plugins will expect an array at $form['processors'].
|
||||
$form['processors'] = array();
|
||||
$form['processors'] = [];
|
||||
// Call buildConfigurationForm() for each active processor.
|
||||
foreach ($this->definitions['processor'] as $id => $definition) {
|
||||
if (in_array($id, $config->get('processors'))) {
|
||||
|
|
|
@ -20,12 +20,12 @@ class ItemViewBuilder extends EntityViewBuilder {
|
|||
$display = $displays[$bundle];
|
||||
|
||||
if ($display->getComponent('description')) {
|
||||
$build[$id]['description'] = array(
|
||||
$build[$id]['description'] = [
|
||||
'#markup' => $entity->getDescription(),
|
||||
'#allowed_tags' => _aggregator_allowed_tags(),
|
||||
'#prefix' => '<div class="item-description">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ class ItemsImporter implements ItemsImporterInterface {
|
|||
}
|
||||
|
||||
// Store instances in an array so we dont have to instantiate new objects.
|
||||
$processor_instances = array();
|
||||
$processor_instances = [];
|
||||
foreach ($this->config->get('processors') as $processor) {
|
||||
try {
|
||||
$processor_instances[$processor] = $this->processorManager->createInstance($processor);
|
||||
|
@ -124,10 +124,10 @@ class ItemsImporter implements ItemsImporterInterface {
|
|||
|
||||
// Log if feed URL has changed.
|
||||
if ($feed->getUrl() != $feed_url) {
|
||||
$this->logger->notice('Updated URL for feed %title to %url.', array('%title' => $feed->label(), '%url' => $feed->getUrl()));
|
||||
$this->logger->notice('Updated URL for feed %title to %url.', ['%title' => $feed->label(), '%url' => $feed->getUrl()]);
|
||||
}
|
||||
|
||||
$this->logger->notice('There is new syndicated content from %site.', array('%site' => $feed->label()));
|
||||
$this->logger->notice('There is new syndicated content from %site.', ['%site' => $feed->label()]);
|
||||
|
||||
// If there are items on the feed, let enabled processors process them.
|
||||
if (!empty($feed->items)) {
|
||||
|
|
|
@ -34,16 +34,16 @@ class AggregatorPluginManager extends DefaultPluginManager {
|
|||
* The module handler.
|
||||
*/
|
||||
public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
$type_annotations = array(
|
||||
$type_annotations = [
|
||||
'fetcher' => 'Drupal\aggregator\Annotation\AggregatorFetcher',
|
||||
'parser' => 'Drupal\aggregator\Annotation\AggregatorParser',
|
||||
'processor' => 'Drupal\aggregator\Annotation\AggregatorProcessor',
|
||||
);
|
||||
$plugin_interfaces = array(
|
||||
];
|
||||
$plugin_interfaces = [
|
||||
'fetcher' => 'Drupal\aggregator\Plugin\FetcherInterface',
|
||||
'parser' => 'Drupal\aggregator\Plugin\ParserInterface',
|
||||
'processor' => 'Drupal\aggregator\Plugin\ProcessorInterface',
|
||||
);
|
||||
];
|
||||
|
||||
parent::__construct("Plugin/aggregator/$type", $namespaces, $module_handler, $plugin_interfaces[$type], $type_annotations[$type]);
|
||||
$this->setCacheBackend($cache_backend, 'aggregator_' . $type . '_plugins');
|
||||
|
|
|
@ -25,7 +25,7 @@ abstract class AggregatorPluginSettingsBase extends PluginBase implements Plugin
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ abstract class AggregatorPluginSettingsBase extends PluginBase implements Plugin
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ use Drupal\aggregator\ItemStorageInterface;
|
|||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
@ -38,13 +37,6 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
*/
|
||||
protected $itemStorage;
|
||||
|
||||
/**
|
||||
* The entity query object for feed items.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
*/
|
||||
protected $itemQuery;
|
||||
|
||||
/**
|
||||
* Constructs an AggregatorFeedBlock object.
|
||||
*
|
||||
|
@ -58,14 +50,11 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
* The entity storage for feeds.
|
||||
* @param \Drupal\aggregator\ItemStorageInterface $item_storage
|
||||
* The entity storage for feed items.
|
||||
* @param \Drupal\Core\Entity\Query\QueryInterface $item_query
|
||||
* The entity query object for feed items.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, FeedStorageInterface $feed_storage, ItemStorageInterface $item_storage, QueryInterface $item_query) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, FeedStorageInterface $feed_storage, ItemStorageInterface $item_storage) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->feedStorage = $feed_storage;
|
||||
$this->itemStorage = $item_storage;
|
||||
$this->itemQuery = $item_query;
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,9 +66,8 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity.manager')->getStorage('aggregator_feed'),
|
||||
$container->get('entity.manager')->getStorage('aggregator_item'),
|
||||
$container->get('entity.query')->get('aggregator_item')
|
||||
$container->get('entity_type.manager')->getStorage('aggregator_feed'),
|
||||
$container->get('entity_type.manager')->getStorage('aggregator_item')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,10 +77,10 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
*/
|
||||
public function defaultConfiguration() {
|
||||
// By default, the block will contain 10 feed items.
|
||||
return array(
|
||||
return [
|
||||
'block_count' => 10,
|
||||
'feed' => NULL,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,23 +96,23 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
$feeds = $this->feedStorage->loadMultiple();
|
||||
$options = array();
|
||||
$options = [];
|
||||
foreach ($feeds as $feed) {
|
||||
$options[$feed->id()] = $feed->label();
|
||||
}
|
||||
$form['feed'] = array(
|
||||
$form['feed'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Select the feed that should be displayed'),
|
||||
'#default_value' => $this->configuration['feed'],
|
||||
'#options' => $options,
|
||||
);
|
||||
];
|
||||
$range = range(2, 20);
|
||||
$form['block_count'] = array(
|
||||
$form['block_count'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Number of news items in block'),
|
||||
'#default_value' => $this->configuration['block_count'],
|
||||
'#options' => array_combine($range, $range),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -142,7 +130,7 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
|
|||
public function build() {
|
||||
// Load the selected feed.
|
||||
if ($feed = $this->feedStorage->load($this->configuration['feed'])) {
|
||||
$result = $this->itemQuery
|
||||
$result = $this->itemStorage->getQuery()
|
||||
->condition('fid', $feed->id())
|
||||
->range(0, $this->configuration['block_count'])
|
||||
->sort('timestamp', 'DESC')
|
||||
|
|
|
@ -112,8 +112,8 @@ class DefaultFetcher implements FetcherInterface, ContainerFactoryPluginInterfac
|
|||
return TRUE;
|
||||
}
|
||||
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');
|
||||
$this->logger->warning('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]);
|
||||
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]), 'warning');
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class DefaultParser implements ParserInterface {
|
|||
}
|
||||
catch (ExceptionInterface $e) {
|
||||
watchdog_exception('aggregator', $e);
|
||||
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', array('%site' => $feed->label(), '%error' => $e->getMessage())), 'error');
|
||||
drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]), 'error');
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ class DefaultParser implements ParserInterface {
|
|||
$feed->setImage($image['uri']);
|
||||
}
|
||||
// Initialize items array.
|
||||
$feed->items = array();
|
||||
$feed->items = [];
|
||||
foreach ($channel as $item) {
|
||||
// Reset the parsed item.
|
||||
$parsed_item = array();
|
||||
$parsed_item = [];
|
||||
// Move the values to an array as expected by processors.
|
||||
$parsed_item['title'] = $item->getTitle();
|
||||
$parsed_item['guid'] = $item->getId();
|
||||
|
|
|
@ -10,7 +10,6 @@ use Drupal\aggregator\FeedInterface;
|
|||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\Core\Form\ConfigFormBaseTrait;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
|
@ -39,13 +38,6 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* The entity query object for feed items.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
*/
|
||||
protected $itemQuery;
|
||||
|
||||
/**
|
||||
* The entity storage for items.
|
||||
*
|
||||
|
@ -71,17 +63,14 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
|
||||
* The configuration factory object.
|
||||
* @param \Drupal\Core\Entity\Query\QueryInterface $item_query
|
||||
* The entity query object for feed items.
|
||||
* @param \Drupal\aggregator\ItemStorageInterface $item_storage
|
||||
* The entity storage for feed items.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, QueryInterface $item_query, ItemStorageInterface $item_storage, DateFormatterInterface $date_formatter) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, ItemStorageInterface $item_storage, DateFormatterInterface $date_formatter) {
|
||||
$this->configFactory = $config;
|
||||
$this->itemStorage = $item_storage;
|
||||
$this->itemQuery = $item_query;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
// @todo Refactor aggregator plugins to ConfigEntity so merging
|
||||
// the configuration here is not needed.
|
||||
|
@ -97,8 +86,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('config.factory'),
|
||||
$container->get('entity.query')->get('aggregator_item'),
|
||||
$container->get('entity.manager')->getStorage('aggregator_item'),
|
||||
$container->get('entity_type.manager')->getStorage('aggregator_item'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
}
|
||||
|
@ -117,53 +105,53 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
$config = $this->config('aggregator.settings');
|
||||
$processors = $config->get('processors');
|
||||
$info = $this->getPluginDefinition();
|
||||
$counts = array(3, 5, 10, 15, 20, 25);
|
||||
$counts = [3, 5, 10, 15, 20, 25];
|
||||
$items = array_map(function ($count) {
|
||||
return $this->formatPlural($count, '1 item', '@count items');
|
||||
}, array_combine($counts, $counts));
|
||||
$intervals = array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800);
|
||||
$period = array_map(array($this->dateFormatter, 'formatInterval'), array_combine($intervals, $intervals));
|
||||
$intervals = [3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800];
|
||||
$period = array_map([$this->dateFormatter, 'formatInterval'], array_combine($intervals, $intervals));
|
||||
$period[AGGREGATOR_CLEAR_NEVER] = t('Never');
|
||||
|
||||
$form['processors'][$info['id']] = array();
|
||||
$form['processors'][$info['id']] = [];
|
||||
// Only wrap into details if there is a basic configuration.
|
||||
if (isset($form['basic_conf'])) {
|
||||
$form['processors'][$info['id']] = array(
|
||||
$form['processors'][$info['id']] = [
|
||||
'#type' => 'details',
|
||||
'#title' => t('Default processor settings'),
|
||||
'#description' => $info['description'],
|
||||
'#open' => in_array($info['id'], $processors),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['processors'][$info['id']]['aggregator_summary_items'] = array(
|
||||
$form['processors'][$info['id']]['aggregator_summary_items'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Number of items shown in listing pages'),
|
||||
'#default_value' => $config->get('source.list_max'),
|
||||
'#empty_value' => 0,
|
||||
'#options' => $items,
|
||||
);
|
||||
];
|
||||
|
||||
$form['processors'][$info['id']]['aggregator_clear'] = array(
|
||||
$form['processors'][$info['id']]['aggregator_clear'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Discard items older than'),
|
||||
'#default_value' => $config->get('items.expire'),
|
||||
'#options' => $period,
|
||||
'#description' => t('Requires a correctly configured <a href=":cron">cron maintenance task</a>.', array(':cron' => $this->url('system.status'))),
|
||||
);
|
||||
'#description' => t('Requires a correctly configured <a href=":cron">cron maintenance task</a>.', [':cron' => $this->url('system.status')]),
|
||||
];
|
||||
|
||||
$lengths = array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000);
|
||||
$lengths = [0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000];
|
||||
$options = array_map(function($length) {
|
||||
return ($length == 0) ? t('Unlimited') : $this->formatPlural($length, '1 character', '@count characters');
|
||||
}, array_combine($lengths, $lengths));
|
||||
|
||||
$form['processors'][$info['id']]['aggregator_teaser_length'] = array(
|
||||
$form['processors'][$info['id']]['aggregator_teaser_length'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Length of trimmed description'),
|
||||
'#default_value' => $config->get('items.teaser_length'),
|
||||
'#options' => $options,
|
||||
'#description' => t('The maximum number of characters used in the trimmed version of content.'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -197,13 +185,13 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
// we find a duplicate entry, we resolve it and pass along its ID is such
|
||||
// that we can update it if needed.
|
||||
if (!empty($item['guid'])) {
|
||||
$values = array('fid' => $feed->id(), 'guid' => $item['guid']);
|
||||
$values = ['fid' => $feed->id(), 'guid' => $item['guid']];
|
||||
}
|
||||
elseif ($item['link'] && $item['link'] != $feed->link && $item['link'] != $feed->url) {
|
||||
$values = array('fid' => $feed->id(), 'link' => $item['link']);
|
||||
$values = ['fid' => $feed->id(), 'link' => $item['link']];
|
||||
}
|
||||
else {
|
||||
$values = array('fid' => $feed->id(), 'title' => $item['title']);
|
||||
$values = ['fid' => $feed->id(), 'title' => $item['title']];
|
||||
}
|
||||
|
||||
// Try to load an existing entry.
|
||||
|
@ -211,7 +199,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
$entry = reset($entry);
|
||||
}
|
||||
else {
|
||||
$entry = Item::create(array('langcode' => $feed->language()->getId()));
|
||||
$entry = Item::create(['langcode' => $feed->language()->getId()]);
|
||||
}
|
||||
if ($item['timestamp']) {
|
||||
$entry->setPostedTime($item['timestamp']);
|
||||
|
@ -243,7 +231,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
$this->itemStorage->delete($items);
|
||||
}
|
||||
// @todo This should be moved out to caller with a different message maybe.
|
||||
drupal_set_message(t('The news items from %site have been deleted.', array('%site' => $feed->label())));
|
||||
drupal_set_message(t('The news items from %site have been deleted.', ['%site' => $feed->label()]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,7 +245,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {
|
||||
// Delete all items that are older than flush item timer.
|
||||
$age = REQUEST_TIME - $aggregator_clear;
|
||||
$result = $this->itemQuery
|
||||
$result = $this->itemStorage->getQuery()
|
||||
->condition('fid', $feed->id())
|
||||
->condition('timestamp', $age, '<')
|
||||
->execute();
|
||||
|
|
|
@ -26,7 +26,7 @@ class AggregatorFeed extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'fid' => $this->t('The feed ID.'),
|
||||
'title' => $this->t('Title of the feed.'),
|
||||
'url' => $this->t('URL to the feed.'),
|
||||
|
@ -38,7 +38,7 @@ class AggregatorFeed extends DrupalSqlBase {
|
|||
'etag' => $this->t('Entity tag HTTP response header.'),
|
||||
'modified' => $this->t('When the feed was last modified.'),
|
||||
'block' => $this->t("Number of items to display in the feed's block."),
|
||||
);
|
||||
];
|
||||
if ($this->getModuleSchemaVersion('system') >= 7000) {
|
||||
$fields['queued'] = $this->t('Time when this feed was queued for refresh, 0 if not queued.');
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class AggregatorItem extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
return [
|
||||
'iid' => $this->t('Primary Key: Unique ID for feed item.'),
|
||||
'fid' => $this->t('The {aggregator_feed}.fid to which this item belongs.'),
|
||||
'title' => $this->t('Title of the feed item.'),
|
||||
|
@ -36,7 +36,7 @@ class AggregatorItem extends DrupalSqlBase {
|
|||
'description' => $this->t('Body of the feed item.'),
|
||||
'timestamp' => $this->t('Post date of feed item, as a Unix timestamp.'),
|
||||
'guid' => $this->t('Unique identifier for the feed item.'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,7 +50,7 @@ class Fid extends NumericArgument {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function titleQuery() {
|
||||
$titles = array();
|
||||
$titles = [];
|
||||
|
||||
$feeds = $this->entityManager->getStorage('aggregator_feed')->loadMultiple($this->value);
|
||||
foreach ($feeds as $feed) {
|
||||
|
|
|
@ -50,7 +50,7 @@ class Iid extends NumericArgument {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function titleQuery() {
|
||||
$titles = array();
|
||||
$titles = [];
|
||||
|
||||
$items = $this->entityManager->getStorage('aggregator_item')->loadMultiple($this->value);
|
||||
foreach ($items as $feed) {
|
||||
|
|
|
@ -48,31 +48,31 @@ class Rss extends RssPluginBase {
|
|||
$item->{$name} = $field->value;
|
||||
}
|
||||
|
||||
$item->elements = array(
|
||||
array(
|
||||
$item->elements = [
|
||||
[
|
||||
'key' => 'pubDate',
|
||||
// views_view_row_rss takes care about the escaping.
|
||||
'value' => gmdate('r', $entity->timestamp->value),
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'key' => 'dc:creator',
|
||||
// views_view_row_rss takes care about the escaping.
|
||||
'value' => $entity->author->value,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'key' => 'guid',
|
||||
// views_view_row_rss takes care about the escaping.
|
||||
'value' => $entity->guid->value,
|
||||
'attributes' => array('isPermaLink' => 'false'),
|
||||
),
|
||||
);
|
||||
'attributes' => ['isPermaLink' => 'false'],
|
||||
],
|
||||
];
|
||||
|
||||
$build = array(
|
||||
$build = [
|
||||
'#theme' => $this->themeFunctions(),
|
||||
'#view' => $this->view,
|
||||
'#options' => $this->options,
|
||||
'#row' => $item,
|
||||
);
|
||||
];
|
||||
return $build;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ class AddFeedTest extends AggregatorTestBase {
|
|||
'refresh' => '900',
|
||||
];
|
||||
$this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
|
||||
$this->assertRaw(t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
|
||||
$this->assertRaw(t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->getUrl())));
|
||||
$this->assertRaw(t('A feed named %feed already exists. Enter a unique title.', ['%feed' => $feed->label()]));
|
||||
$this->assertRaw(t('A feed with this URL %url already exists. Enter a unique URL.', ['%url' => $feed->getUrl()]));
|
||||
|
||||
// Delete feed.
|
||||
$this->deleteFeed($feed);
|
||||
|
|
|
@ -22,7 +22,7 @@ class AggregatorAdminTest extends AggregatorTestBase {
|
|||
$this->assertText('Test processor');
|
||||
|
||||
// Set new values and enable test plugins.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'aggregator_allowed_html_tags' => '<a>',
|
||||
'aggregator_summary_items' => 10,
|
||||
'aggregator_clear' => 3600,
|
||||
|
@ -30,27 +30,27 @@ class AggregatorAdminTest extends AggregatorTestBase {
|
|||
'aggregator_fetcher' => 'aggregator_test_fetcher',
|
||||
'aggregator_parser' => 'aggregator_test_parser',
|
||||
'aggregator_processors[aggregator_test_processor]' => 'aggregator_test_processor',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/services/aggregator/settings', $edit, t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved.'));
|
||||
|
||||
foreach ($edit as $name => $value) {
|
||||
$this->assertFieldByName($name, $value, format_string('"@name" has correct default value.', array('@name' => $name)));
|
||||
$this->assertFieldByName($name, $value, format_string('"@name" has correct default value.', ['@name' => $name]));
|
||||
}
|
||||
|
||||
// Check for our test processor settings form.
|
||||
$this->assertText(t('Dummy length setting'));
|
||||
// Change its value to ensure that settingsSubmit is called.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'dummy_length' => 100,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/services/aggregator/settings', $edit, t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved.'));
|
||||
$this->assertFieldByName('dummy_length', 100, '"dummy_length" has correct default value.');
|
||||
|
||||
// Make sure settings form is still accessible even after uninstalling a module
|
||||
// that provides the selected plugins.
|
||||
$this->container->get('module_installer')->uninstall(array('aggregator_test'));
|
||||
$this->container->get('module_installer')->uninstall(['aggregator_test']);
|
||||
$this->resetAll();
|
||||
$this->drupalGet('admin/config/services/aggregator/settings');
|
||||
$this->assertResponse(200);
|
||||
|
@ -59,7 +59,7 @@ class AggregatorAdminTest extends AggregatorTestBase {
|
|||
/**
|
||||
* Tests the overview page.
|
||||
*/
|
||||
function testOverviewPage() {
|
||||
public function testOverviewPage() {
|
||||
$feed = $this->createFeed($this->getRSS091Sample());
|
||||
$this->drupalGet('admin/config/services/aggregator');
|
||||
|
||||
|
|
|
@ -16,30 +16,30 @@ class AggregatorCronTest extends AggregatorTestBase {
|
|||
$this->createSampleNodes();
|
||||
$feed = $this->createFeed();
|
||||
$this->cronRun();
|
||||
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
|
||||
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField());
|
||||
$this->deleteFeedItems($feed);
|
||||
$this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
|
||||
$this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField());
|
||||
$this->cronRun();
|
||||
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
|
||||
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField());
|
||||
|
||||
// Test feed locking when queued for update.
|
||||
$this->deleteFeedItems($feed);
|
||||
db_update('aggregator_feed')
|
||||
->condition('fid', $feed->id())
|
||||
->fields(array(
|
||||
->fields([
|
||||
'queued' => REQUEST_TIME,
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
$this->cronRun();
|
||||
$this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
|
||||
$this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField());
|
||||
db_update('aggregator_feed')
|
||||
->condition('fid', $feed->id())
|
||||
->fields(array(
|
||||
->fields([
|
||||
'queued' => 0,
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
$this->cronRun();
|
||||
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
|
||||
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'test_page_test');
|
||||
public static $modules = ['block', 'test_page_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -35,15 +35,15 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
$this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
|
||||
|
||||
// Need admin user to be able to access block admin.
|
||||
$admin_user = $this->drupalCreateUser(array(
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
'access administration pages',
|
||||
'administer news feeds',
|
||||
'access news feeds',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$block = $this->drupalPlaceBlock("aggregator_feed_block", array('label' => 'feed-' . $feed->label()));
|
||||
$block = $this->drupalPlaceBlock("aggregator_feed_block", ['label' => 'feed-' . $feed->label()]);
|
||||
|
||||
// Configure the feed that should be displayed.
|
||||
$block->getPlugin()->setConfigurationValue('feed', $feed->id());
|
||||
|
@ -56,20 +56,20 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
|
||||
// Confirm items appear as links.
|
||||
$items = $this->container->get('entity.manager')->getStorage('aggregator_item')->loadByFeed($feed->id(), 1);
|
||||
$links = $this->xpath('//a[@href = :href]', array(':href' => reset($items)->getLink()));
|
||||
$links = $this->xpath('//a[@href = :href]', [':href' => reset($items)->getLink()]);
|
||||
$this->assert(isset($links[0]), 'Item link found.');
|
||||
|
||||
// Find the expected read_more link.
|
||||
$href = $feed->url();
|
||||
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
|
||||
$this->assert(isset($links[0]), format_string('Link to href %href found.', array('%href' => $href)));
|
||||
$links = $this->xpath('//a[@href = :href]', [':href' => $href]);
|
||||
$this->assert(isset($links[0]), format_string('Link to href %href found.', ['%href' => $href]));
|
||||
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
|
||||
$cache_tags = explode(' ', $cache_tags_header);
|
||||
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
|
||||
|
||||
// Visit that page.
|
||||
$this->drupalGet($feed->urlInfo()->getInternalPath());
|
||||
$correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => $feed->label()));
|
||||
$correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', [':title' => $feed->label()]);
|
||||
$this->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');
|
||||
$cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
|
||||
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
|
||||
|
@ -103,18 +103,18 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
|
||||
// Check for presence of an aggregator pager.
|
||||
$this->drupalGet('aggregator');
|
||||
$elements = $this->xpath("//ul[contains(@class, :class)]", array(':class' => 'pager__items'));
|
||||
$elements = $this->xpath("//ul[contains(@class, :class)]", [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
|
||||
|
||||
// Check for sources page title.
|
||||
$this->drupalGet('aggregator/sources');
|
||||
$titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => 'Sources'));
|
||||
$titles = $this->xpath('//h1[normalize-space(text())=:title]', [':title' => 'Sources']);
|
||||
$this->assertTrue(!empty($titles), 'Source page contains correct title.');
|
||||
|
||||
// Find the expected read_more link on the sources page.
|
||||
$href = $feed->url();
|
||||
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
|
||||
$this->assertTrue(isset($links[0]), SafeMarkup::format('Link to href %href found.', array('%href' => $href)));
|
||||
$links = $this->xpath('//a[@href = :href]', [':href' => $href]);
|
||||
$this->assertTrue(isset($links[0]), SafeMarkup::format('Link to href %href found.', ['%href' => $href]));
|
||||
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
|
||||
$cache_tags = explode(' ', $cache_tags_header);
|
||||
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
|
||||
|
@ -139,7 +139,7 @@ class AggregatorRenderingTest extends AggregatorTestBase {
|
|||
|
||||
// Check for the presence of a pager.
|
||||
$this->drupalGet('aggregator/sources/' . $feed->id());
|
||||
$elements = $this->xpath("//ul[contains(@class, :class)]", array(':class' => 'pager__items'));
|
||||
$elements = $this->xpath("//ul[contains(@class, :class)]", [':class' => 'pager__items']);
|
||||
$this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
|
||||
$cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
|
||||
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
|
||||
|
|
|
@ -9,6 +9,9 @@ use Drupal\aggregator\FeedInterface;
|
|||
|
||||
/**
|
||||
* Defines a base class for testing the Aggregator module.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\aggregator\Functional\AggregatorTestBase instead.
|
||||
*/
|
||||
abstract class AggregatorTestBase extends WebTestBase {
|
||||
|
||||
|
@ -34,10 +37,10 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
|
||||
// Create an Article node type.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'administer news feeds', 'access news feeds', 'create article content'));
|
||||
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer news feeds', 'access news feeds', 'create article content']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
}
|
||||
|
@ -58,16 +61,16 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
*
|
||||
* @see getFeedEditArray()
|
||||
*/
|
||||
public function createFeed($feed_url = NULL, array $edit = array()) {
|
||||
public function createFeed($feed_url = NULL, array $edit = []) {
|
||||
$edit = $this->getFeedEditArray($feed_url, $edit);
|
||||
$this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
|
||||
$this->assertText(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]'])));
|
||||
$this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), format_string('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
|
||||
|
||||
// Verify that the creation message contains a link to a feed.
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'aggregator/sources/'));
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
|
||||
$this->assert(isset($view_link), 'The message area contains a link to a feed');
|
||||
|
||||
$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();
|
||||
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE title = :title AND url = :url", [':title' => $edit['title[0][value]'], ':url' => $edit['url[0][value]']])->fetchField();
|
||||
$this->assertTrue(!empty($fid), 'The feed found in database.');
|
||||
return Feed::load($fid);
|
||||
}
|
||||
|
@ -79,8 +82,8 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
* Feed object representing the 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.');
|
||||
$this->drupalPostForm('aggregator/sources/' . $feed->id() . '/delete', [], t('Delete'));
|
||||
$this->assertRaw(t('The feed %title has been deleted.', ['%title' => $feed->label()]), 'Feed deleted successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,19 +98,19 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
* @return array
|
||||
* A feed array.
|
||||
*/
|
||||
public function getFeedEditArray($feed_url = NULL, array $edit = array()) {
|
||||
public function getFeedEditArray($feed_url = NULL, array $edit = []) {
|
||||
$feed_name = $this->randomMachineName(10);
|
||||
if (!$feed_url) {
|
||||
$feed_url = \Drupal::url('view.frontpage.feed_1', array(), array(
|
||||
'query' => array('feed' => $feed_name),
|
||||
$feed_url = \Drupal::url('view.frontpage.feed_1', [], [
|
||||
'query' => ['feed' => $feed_name],
|
||||
'absolute' => TRUE,
|
||||
));
|
||||
]);
|
||||
}
|
||||
$edit += array(
|
||||
$edit += [
|
||||
'title[0][value]' => $feed_name,
|
||||
'url[0][value]' => $feed_url,
|
||||
'refresh' => '900',
|
||||
);
|
||||
];
|
||||
return $edit;
|
||||
}
|
||||
|
||||
|
@ -123,19 +126,19 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
* @return \Drupal\aggregator\FeedInterface
|
||||
* A feed object.
|
||||
*/
|
||||
public function getFeedEditObject($feed_url = NULL, array $values = array()) {
|
||||
public function getFeedEditObject($feed_url = NULL, array $values = []) {
|
||||
$feed_name = $this->randomMachineName(10);
|
||||
if (!$feed_url) {
|
||||
$feed_url = \Drupal::url('view.frontpage.feed_1', array(
|
||||
'query' => array('feed' => $feed_name),
|
||||
$feed_url = \Drupal::url('view.frontpage.feed_1', [
|
||||
'query' => ['feed' => $feed_name],
|
||||
'absolute' => TRUE,
|
||||
));
|
||||
]);
|
||||
}
|
||||
$values += array(
|
||||
$values += [
|
||||
'title' => $feed_name,
|
||||
'url' => $feed_url,
|
||||
'refresh' => '900',
|
||||
);
|
||||
];
|
||||
return Feed::create($values);
|
||||
}
|
||||
|
||||
|
@ -165,7 +168,7 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
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())));
|
||||
$this->assertResponse(200, format_string(':url is reachable.', [':url' => $feed->getUrl()]));
|
||||
|
||||
// Attempt to access the update link directly without an access token.
|
||||
$this->drupalGet('admin/config/services/aggregator/update/' . $feed->id());
|
||||
|
@ -176,15 +179,15 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
$this->clickLink('Update items');
|
||||
|
||||
// Ensure we have the right number of items.
|
||||
$result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()));
|
||||
$feed->items = array();
|
||||
$result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()]);
|
||||
$feed->items = [];
|
||||
foreach ($result as $item) {
|
||||
$feed->items[] = $item->iid;
|
||||
}
|
||||
|
||||
if ($expected_count !== NULL) {
|
||||
$feed->item_count = count($feed->items);
|
||||
$this->assertEqual($expected_count, $feed->item_count, format_string('Total items in feed equal to the total items in database (@val1 != @val2)', array('@val1' => $expected_count, '@val2' => $feed->item_count)));
|
||||
$this->assertEqual($expected_count, $feed->item_count, format_string('Total items in feed equal to the total items in database (@val1 != @val2)', ['@val1' => $expected_count, '@val2' => $feed->item_count]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,8 +198,8 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
* Feed object representing the 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.');
|
||||
$this->drupalPostForm('admin/config/services/aggregator/delete/' . $feed->id(), [], t('Delete items'));
|
||||
$this->assertRaw(t('The news items from %title have been deleted.', ['%title' => $feed->label()]), 'Feed items deleted.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,10 +212,10 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
*/
|
||||
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();
|
||||
$count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
|
||||
$this->assertTrue($count);
|
||||
$this->deleteFeedItems($feed);
|
||||
$count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField();
|
||||
$count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
|
||||
$this->assertTrue($count == 0);
|
||||
}
|
||||
|
||||
|
@ -228,7 +231,7 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
* TRUE if feed is unique.
|
||||
*/
|
||||
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();
|
||||
$result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", [':title' => $feed_name, ':url' => $feed_url])->fetchField();
|
||||
return (1 == $result);
|
||||
}
|
||||
|
||||
|
@ -271,7 +274,8 @@ abstract class AggregatorTestBase extends WebTestBase {
|
|||
EOF;
|
||||
|
||||
$path = 'public://valid-opml.xml';
|
||||
return file_unmanaged_save_data($opml, $path);
|
||||
// Add the UTF-8 byte order mark.
|
||||
return file_unmanaged_save_data(chr(239) . chr(187) . chr(191) . $opml, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -354,7 +358,7 @@ EOF;
|
|||
public function createSampleNodes($count = 5) {
|
||||
// Post $count article nodes.
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $this->randomMachineName();
|
||||
$edit['body[0][value]'] = $this->randomMachineName();
|
||||
$this->drupalPostForm('node/add/article', $edit, t('Save'));
|
||||
|
@ -368,10 +372,10 @@ EOF;
|
|||
$this->config('aggregator.settings')
|
||||
->set('fetcher', 'aggregator_test_fetcher')
|
||||
->set('parser', 'aggregator_test_parser')
|
||||
->set('processors', array(
|
||||
->set('processors', [
|
||||
'aggregator_test_processor' => 'aggregator_test_processor',
|
||||
'aggregator' => 'aggregator',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
/**
|
||||
* Delete feed items from a feed.
|
||||
*
|
||||
* @group aggregator
|
||||
*/
|
||||
class DeleteFeedItemTest extends AggregatorTestBase {
|
||||
/**
|
||||
* Tests running "delete items" from 'admin/config/services/aggregator' page.
|
||||
*/
|
||||
public function testDeleteFeedItem() {
|
||||
// Create a bunch of test feeds.
|
||||
$feed_urls = array();
|
||||
// No last-modified, no etag.
|
||||
$feed_urls[] = \Drupal::url('aggregator_test.feed', array(), array('absolute' => TRUE));
|
||||
// Last-modified, but no etag.
|
||||
$feed_urls[] = \Drupal::url('aggregator_test.feed', array('use_last_modified' => 1), array('absolute' => TRUE));
|
||||
// No Last-modified, but etag.
|
||||
$feed_urls[] = \Drupal::url('aggregator_test.feed', array('use_last_modified' => 0, 'use_etag' => 1), array('absolute' => TRUE));
|
||||
// Last-modified and etag.
|
||||
$feed_urls[] = \Drupal::url('aggregator_test.feed', array('use_last_modified' => 1, 'use_etag' => 1), array('absolute' => TRUE));
|
||||
|
||||
foreach ($feed_urls as $feed_url) {
|
||||
$feed = $this->createFeed($feed_url);
|
||||
// Update and delete items two times in a row to make sure that removal
|
||||
// resets all 'modified' information (modified, etag, hash) and allows for
|
||||
// immediate update. There's 8 items in the feed, but one has an empty
|
||||
// title and is skipped.
|
||||
$this->updateAndDelete($feed, 7);
|
||||
$this->updateAndDelete($feed, 7);
|
||||
$this->updateAndDelete($feed, 7);
|
||||
// Delete feed.
|
||||
$this->deleteFeed($feed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
/**
|
||||
* Delete feed test.
|
||||
*
|
||||
* @group aggregator
|
||||
*/
|
||||
class DeleteFeedTest extends AggregatorTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
|
||||
/**
|
||||
* Deletes a feed and ensures that all of its services are deleted.
|
||||
*/
|
||||
public function testDeleteFeed() {
|
||||
$feed1 = $this->createFeed();
|
||||
$feed2 = $this->createFeed();
|
||||
|
||||
// Place a block for both feeds.
|
||||
$block = $this->drupalPlaceBlock('aggregator_feed_block');
|
||||
$block->getPlugin()->setConfigurationValue('feed', $feed1->id());
|
||||
$block->save();
|
||||
$block2 = $this->drupalPlaceBlock('aggregator_feed_block');
|
||||
$block2->getPlugin()->setConfigurationValue('feed', $feed2->id());
|
||||
$block2->save();
|
||||
|
||||
// Delete feed.
|
||||
$this->deleteFeed($feed1);
|
||||
$this->assertText($feed2->label());
|
||||
$block_storage = $this->container->get('entity.manager')->getStorage('block');
|
||||
$this->assertNull($block_storage->load($block->id()), 'Block for the deleted feed was deleted.');
|
||||
$this->assertEqual($block2->id(), $block_storage->load($block2->id())->id(), 'Block for not deleted feed still exists.');
|
||||
|
||||
// Check feed source.
|
||||
$this->drupalGet('aggregator/sources/' . $feed1->id());
|
||||
$this->assertResponse(404, 'Deleted feed source does not exists.');
|
||||
|
||||
// Check database for feed.
|
||||
$result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed1->label(), ':url' => $feed1->getUrl()))->fetchField();
|
||||
$this->assertFalse($result, 'Feed not found in database');
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ class FeedAdminDisplayTest extends AggregatorTestBase {
|
|||
*/
|
||||
public function testFeedUpdateFields() {
|
||||
// Create scheduled feed.
|
||||
$scheduled_feed = $this->createFeed(NULL, array('refresh' => '900'));
|
||||
$scheduled_feed = $this->createFeed(NULL, ['refresh' => '900']);
|
||||
|
||||
$this->drupalGet('admin/config/services/aggregator');
|
||||
$this->assertResponse(200, 'Aggregator feed overview page exists.');
|
||||
|
@ -40,7 +40,7 @@ class FeedAdminDisplayTest extends AggregatorTestBase {
|
|||
$this->deleteFeed($scheduled_feed);
|
||||
|
||||
// Create non-scheduled feed.
|
||||
$non_scheduled_feed = $this->createFeed(NULL, array('refresh' => '0'));
|
||||
$non_scheduled_feed = $this->createFeed(NULL, ['refresh' => '0']);
|
||||
|
||||
$this->drupalGet('admin/config/services/aggregator');
|
||||
// The non scheduled feed shows that it has not been updated yet.
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
use Drupal\aggregator\Entity\Feed;
|
||||
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the Feed entity's cache tags.
|
||||
*
|
||||
* @group aggregator
|
||||
*/
|
||||
class FeedCacheTagsTest extends EntityWithUriCacheTagsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('aggregator');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Give anonymous users permission to access feeds, so that we can verify
|
||||
// the cache tags of cached versions of feeds.
|
||||
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
|
||||
$user_role->grantPermission('access news feeds');
|
||||
$user_role->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
$this->enableTestPlugins();
|
||||
// Create some nodes.
|
||||
$this->createSampleNodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fetching functionality.
|
||||
*/
|
||||
public function testfetch() {
|
||||
// Create feed with local url.
|
||||
$feed = $this->createFeed();
|
||||
$this->updateFeedItems($feed);
|
||||
$this->assertFalse(empty($feed->items));
|
||||
|
||||
// Delete items and restore checked property to 0.
|
||||
$this->deleteFeedItems($feed);
|
||||
// Change its name and try again.
|
||||
$feed->setTitle('Do not fetch');
|
||||
$feed->save();
|
||||
$this->updateFeedItems($feed);
|
||||
// Fetch should fail due to feed name.
|
||||
$this->assertTrue(empty($feed->items));
|
||||
}
|
||||
|
||||
}
|
|
@ -16,14 +16,14 @@ class FeedLanguageTest extends AggregatorTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* List of langcodes.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $langcodes = array();
|
||||
protected $langcodes = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -32,12 +32,12 @@ class FeedLanguageTest extends AggregatorTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create test languages.
|
||||
$this->langcodes = array(ConfigurableLanguage::load('en'));
|
||||
$this->langcodes = [ConfigurableLanguage::load('en')];
|
||||
for ($i = 1; $i < 3; ++$i) {
|
||||
$language = ConfigurableLanguage::create(array(
|
||||
$language = ConfigurableLanguage::create([
|
||||
'id' => 'l' . $i,
|
||||
'label' => $this->randomString(),
|
||||
));
|
||||
]);
|
||||
$language->save();
|
||||
$this->langcodes[$i] = $language->id();
|
||||
}
|
||||
|
@ -57,10 +57,10 @@ class FeedLanguageTest extends AggregatorTestBase {
|
|||
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
|
||||
|
||||
/** @var \Drupal\aggregator\FeedInterface[] $feeds */
|
||||
$feeds = array();
|
||||
$feeds = [];
|
||||
// Create feeds.
|
||||
$feeds[1] = $this->createFeed(NULL, array('langcode[0][value]' => $this->langcodes[1]));
|
||||
$feeds[2] = $this->createFeed(NULL, array('langcode[0][value]' => $this->langcodes[2]));
|
||||
$feeds[1] = $this->createFeed(NULL, ['langcode[0][value]' => $this->langcodes[1]]);
|
||||
$feeds[2] = $this->createFeed(NULL, ['langcode[0][value]' => $this->langcodes[2]]);
|
||||
|
||||
// Make sure that the language has been assigned.
|
||||
$this->assertEqual($feeds[1]->language()->getId(), $this->langcodes[1]);
|
||||
|
@ -74,7 +74,7 @@ class FeedLanguageTest extends AggregatorTestBase {
|
|||
// the one from the feed.
|
||||
foreach ($feeds as $feed) {
|
||||
/** @var \Drupal\aggregator\ItemInterface[] $items */
|
||||
$items = entity_load_multiple_by_properties('aggregator_item', array('fid' => $feed->id()));
|
||||
$items = entity_load_multiple_by_properties('aggregator_item', ['fid' => $feed->id()]);
|
||||
$this->assertTrue(count($items) > 0, 'Feed items were created.');
|
||||
foreach ($items as $item) {
|
||||
$this->assertEqual($item->language()->getId(), $feed->language()->getId());
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\aggregator\Entity\Feed;
|
||||
|
||||
/**
|
||||
* Tests the built-in feed parser with valid feed samples.
|
||||
*
|
||||
* @group aggregator
|
||||
*/
|
||||
class FeedParserTest extends AggregatorTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Do not delete old aggregator items during these tests, since our sample
|
||||
// feeds have hardcoded dates in them (which may be expired when this test
|
||||
// is run).
|
||||
$this->config('aggregator.settings')->set('items.expire', AGGREGATOR_CLEAR_NEVER)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a feed that uses the RSS 0.91 format.
|
||||
*/
|
||||
public function testRSS091Sample() {
|
||||
$feed = $this->createFeed($this->getRSS091Sample());
|
||||
$feed->refreshItems();
|
||||
$this->drupalGet('aggregator/sources/' . $feed->id());
|
||||
$this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->label())));
|
||||
$this->assertText('First example feed item title');
|
||||
$this->assertLinkByHref('http://example.com/example-turns-one');
|
||||
$this->assertText('First example feed item description.');
|
||||
$this->assertRaw('<img src="http://example.com/images/druplicon.png"');
|
||||
|
||||
// Several additional items that include elements over 255 characters.
|
||||
$this->assertRaw("Second example feed item title.");
|
||||
$this->assertText('Long link feed item title');
|
||||
$this->assertText('Long link feed item description');
|
||||
$this->assertLinkByHref('http://example.com/tomorrow/and/tomorrow/and/tomorrow/creeps/in/this/petty/pace/from/day/to/day/to/the/last/syllable/of/recorded/time/and/all/our/yesterdays/have/lighted/fools/the/way/to/dusty/death/out/out/brief/candle/life/is/but/a/walking/shadow/a/poor/player/that/struts/and/frets/his/hour/upon/the/stage/and/is/heard/no/more/it/is/a/tale/told/by/an/idiot/full/of/sound/and/fury/signifying/nothing');
|
||||
$this->assertText('Long author feed item title');
|
||||
$this->assertText('Long author feed item description');
|
||||
$this->assertLinkByHref('http://example.com/long/author');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a feed that uses the Atom format.
|
||||
*/
|
||||
public function testAtomSample() {
|
||||
$feed = $this->createFeed($this->getAtomSample());
|
||||
$feed->refreshItems();
|
||||
$this->drupalGet('aggregator/sources/' . $feed->id());
|
||||
$this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->label())));
|
||||
$this->assertText('Atom-Powered Robots Run Amok');
|
||||
$this->assertLinkByHref('http://example.org/2003/12/13/atom03');
|
||||
$this->assertText('Some text.');
|
||||
$this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', db_query('SELECT guid FROM {aggregator_item} WHERE link = :link', array(':link' => 'http://example.org/2003/12/13/atom03'))->fetchField(), 'Atom entry id element is parsed correctly.');
|
||||
|
||||
// Check for second feed entry.
|
||||
$this->assertText('We tried to stop them, but we failed.');
|
||||
$this->assertLinkByHref('http://example.org/2003/12/14/atom03');
|
||||
$this->assertText('Some other text.');
|
||||
$db_guid = db_query('SELECT guid FROM {aggregator_item} WHERE link = :link', array(
|
||||
':link' => 'http://example.org/2003/12/14/atom03',
|
||||
))->fetchField();
|
||||
$this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-bbbb-80da344efa6a', $db_guid, 'Atom entry id element is parsed correctly.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a feed that uses HTML entities in item titles.
|
||||
*/
|
||||
public function testHtmlEntitiesSample() {
|
||||
$feed = $this->createFeed($this->getHtmlEntitiesSample());
|
||||
$feed->refreshItems();
|
||||
$this->drupalGet('aggregator/sources/' . $feed->id());
|
||||
$this->assertResponse(200, format_string('Feed %name exists.', array('%name' => $feed->label())));
|
||||
$this->assertRaw("Quote" Amp&");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a redirected feed is tracked to its target.
|
||||
*/
|
||||
public function testRedirectFeed() {
|
||||
$redirect_url = Url::fromRoute('aggregator_test.redirect')->setAbsolute()->toString();
|
||||
$feed = Feed::create(array('url' => $redirect_url, 'title' => $this->randomMachineName()));
|
||||
$feed->save();
|
||||
$feed->refreshItems();
|
||||
|
||||
// Make sure that the feed URL was updated correctly.
|
||||
$this->assertEqual($feed->getUrl(), \Drupal::url('aggregator_test.feed', array(), array('absolute' => TRUE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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())));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
use Drupal\aggregator\Entity\Feed;
|
||||
use Drupal\aggregator\Entity\Item;
|
||||
|
||||
/**
|
||||
* Tests the processor plugins functionality and discoverability.
|
||||
*
|
||||
* @group aggregator
|
||||
*
|
||||
* @see \Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor.
|
||||
*/
|
||||
class FeedProcessorPluginTest extends AggregatorTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Enable test plugins.
|
||||
$this->enableTestPlugins();
|
||||
// Create some nodes.
|
||||
$this->createSampleNodes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processing functionality.
|
||||
*/
|
||||
public function testProcess() {
|
||||
$feed = $this->createFeed();
|
||||
$this->updateFeedItems($feed);
|
||||
foreach ($feed->items as $iid) {
|
||||
$item = Item::load($iid);
|
||||
$this->assertTrue(strpos($item->label(), 'testProcessor') === 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleting functionality.
|
||||
*/
|
||||
public function testDelete() {
|
||||
$feed = $this->createFeed();
|
||||
$description = $feed->description->value ?: '';
|
||||
$this->updateAndDelete($feed, NULL);
|
||||
// Make sure the feed title is changed.
|
||||
$entities = entity_load_multiple_by_properties('aggregator_feed', array('description' => $description));
|
||||
$this->assertTrue(empty($entities));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
/**
|
||||
* Tests OPML import.
|
||||
*
|
||||
* @group aggregator
|
||||
*/
|
||||
class ImportOpmlTest extends AggregatorTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'help');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer news feeds', 'access news feeds', 'create article content', 'administer blocks'));
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens OPML import form.
|
||||
*/
|
||||
public function openImportForm() {
|
||||
// Enable the help block.
|
||||
$this->drupalPlaceBlock('help_block', array('region' => 'help'));
|
||||
|
||||
$this->drupalGet('admin/config/services/aggregator/add/opml');
|
||||
$this->assertText('A single OPML document may contain many feeds.', 'Found OPML help text.');
|
||||
$this->assertField('files[upload]', 'Found file upload field.');
|
||||
$this->assertField('remote', 'Found Remote URL field.');
|
||||
$this->assertField('refresh', '', 'Found Refresh field.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits form filled with invalid fields.
|
||||
*/
|
||||
public function validateImportFormFields() {
|
||||
$before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
|
||||
|
||||
$edit = array();
|
||||
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
|
||||
$this->assertRaw(t('<em>Either</em> upload a file or enter a URL.'), 'Error if no fields are filled.');
|
||||
|
||||
$path = $this->getEmptyOpml();
|
||||
$edit = array(
|
||||
'files[upload]' => $path,
|
||||
'remote' => file_create_url($path),
|
||||
);
|
||||
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
|
||||
$this->assertRaw(t('<em>Either</em> upload a file or enter a URL.'), 'Error if both fields are filled.');
|
||||
|
||||
$edit = array('remote' => 'invalidUrl://empty');
|
||||
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
|
||||
$this->assertText(t('The URL invalidUrl://empty is not valid.'), 'Error if the URL is invalid.');
|
||||
|
||||
$after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
|
||||
$this->assertEqual($before, $after, 'No feeds were added during the three last form submissions.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits form with invalid, empty, and valid OPML files.
|
||||
*/
|
||||
protected function submitImportForm() {
|
||||
$before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
|
||||
|
||||
$form['files[upload]'] = $this->getInvalidOpml();
|
||||
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $form, t('Import'));
|
||||
$this->assertText(t('No new feed has been added.'), 'Attempting to upload invalid XML.');
|
||||
|
||||
$edit = array('remote' => file_create_url($this->getEmptyOpml()));
|
||||
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
|
||||
$this->assertText(t('No new feed has been added.'), 'Attempting to load empty OPML from remote URL.');
|
||||
|
||||
$after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
|
||||
$this->assertEqual($before, $after, 'No feeds were added during the two last form submissions.');
|
||||
|
||||
db_delete('aggregator_feed')->execute();
|
||||
|
||||
$feeds[0] = $this->getFeedEditArray();
|
||||
$feeds[1] = $this->getFeedEditArray();
|
||||
$feeds[2] = $this->getFeedEditArray();
|
||||
$edit = array(
|
||||
'files[upload]' => $this->getValidOpml($feeds),
|
||||
'refresh' => '900',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
|
||||
$this->assertRaw(t('A feed with the URL %url already exists.', array('%url' => $feeds[0]['url[0][value]'])), 'Verifying that a duplicate URL was identified');
|
||||
$this->assertRaw(t('A feed named %title already exists.', array('%title' => $feeds[1]['title[0][value]'])), 'Verifying that a duplicate title was identified');
|
||||
|
||||
$after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
|
||||
$this->assertEqual($after, 2, 'Verifying that two distinct feeds were added.');
|
||||
|
||||
$feeds_from_db = db_query("SELECT title, url, refresh FROM {aggregator_feed}");
|
||||
$refresh = TRUE;
|
||||
foreach ($feeds_from_db as $feed) {
|
||||
$title[$feed->url] = $feed->title;
|
||||
$url[$feed->title] = $feed->url;
|
||||
$refresh = $refresh && $feed->refresh == 900;
|
||||
}
|
||||
|
||||
$this->assertEqual($title[$feeds[0]['url[0][value]']], $feeds[0]['title[0][value]'], 'First feed was added correctly.');
|
||||
$this->assertEqual($url[$feeds[1]['title[0][value]']], $feeds[1]['url[0][value]'], 'Second feed was added correctly.');
|
||||
$this->assertTrue($refresh, 'Refresh times are correct.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the import of an OPML file.
|
||||
*/
|
||||
public function testOpmlImport() {
|
||||
$this->openImportForm();
|
||||
$this->validateImportFormFields();
|
||||
$this->submitImportForm();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\aggregator\Tests;
|
||||
|
||||
use Drupal\aggregator\Entity\Feed;
|
||||
use Drupal\aggregator\Entity\Item;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the Item entity's cache tags.
|
||||
*
|
||||
* @group aggregator
|
||||
*/
|
||||
class ItemCacheTagsTest extends EntityCacheTagsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('aggregator');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Give anonymous users permission to access feeds, so that we can verify
|
||||
// the cache tags of cached versions of feed items.
|
||||
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
|
||||
$user_role->grantPermission('access news feeds');
|
||||
$user_role->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that when creating a feed item, the feed tag is invalidated.
|
||||
*/
|
||||
public function testEntityCreation() {
|
||||
// Create a cache entry that is tagged with a feed cache tag.
|
||||
\Drupal::cache('render')->set('foo', 'bar', CacheBackendInterface::CACHE_PERMANENT, $this->entity->getCacheTags());
|
||||
|
||||
// Verify a cache hit.
|
||||
$this->verifyRenderCache('foo', array('aggregator_feed:1'));
|
||||
|
||||
// Now create a feed item in that feed.
|
||||
Item::create(array(
|
||||
'fid' => $this->entity->getFeedId(),
|
||||
'title' => t('Llama 2'),
|
||||
'path' => 'https://groups.drupal.org/',
|
||||
))->save();
|
||||
|
||||
// Verify a cache miss.
|
||||
$this->assertFalse(\Drupal::cache('render')->get('foo'), 'Creating a new feed item invalidates the cache tag of the feed.');
|
||||
}
|
||||
|
||||
}
|
|
@ -26,47 +26,47 @@ class UpdateFeedItemTest extends AggregatorTestBase {
|
|||
$this->deleteFeed($feed);
|
||||
|
||||
// Test updating feed items without valid timestamp information.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'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->assertText(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]'])));
|
||||
$this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), format_string('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
|
||||
|
||||
// Verify that the creation message contains a link to a feed.
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'aggregator/sources/'));
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
|
||||
$this->assert(isset($view_link), 'The message area contains a link to a feed');
|
||||
|
||||
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url[0][value]']))->fetchField();
|
||||
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", [':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();
|
||||
$before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
|
||||
|
||||
// Sleep for 3 second.
|
||||
sleep(3);
|
||||
db_update('aggregator_feed')
|
||||
->condition('fid', $feed->id())
|
||||
->fields(array(
|
||||
->fields([
|
||||
'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)));
|
||||
$after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField();
|
||||
$this->assertTrue($before === $after, format_string('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(array('aggregator_test'));
|
||||
$this->container->get('module_installer')->uninstall(['aggregator_test']);
|
||||
$this->updateFeedItems($feed);
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class UpdateFeedTest extends AggregatorTestBase {
|
|||
* Creates a feed and attempts to update it.
|
||||
*/
|
||||
public function testUpdateFeed() {
|
||||
$remaining_fields = array('title[0][value]', 'url[0][value]', '');
|
||||
$remaining_fields = ['title[0][value]', 'url[0][value]', ''];
|
||||
foreach ($remaining_fields as $same_field) {
|
||||
$feed = $this->createFeed();
|
||||
|
||||
|
@ -24,10 +24,10 @@ class UpdateFeedTest extends AggregatorTestBase {
|
|||
$edit[$same_field] = $feed->{$same_field}->value;
|
||||
}
|
||||
$this->drupalPostForm('aggregator/sources/' . $feed->id() . '/configure', $edit, t('Save'));
|
||||
$this->assertText(t('The feed @name has been updated.', array('@name' => $edit['title[0][value]'])), format_string('The feed %name has been updated.', array('%name' => $edit['title[0][value]'])));
|
||||
$this->assertText(t('The feed @name has been updated.', ['@name' => $edit['title[0][value]']]), format_string('The feed %name has been updated.', ['%name' => $edit['title[0][value]']]));
|
||||
|
||||
// Verify that the creation message contains a link to a feed.
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'aggregator/sources/'));
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
|
||||
$this->assert(isset($view_link), 'The message area contains a link to a feed');
|
||||
|
||||
// Check feed data.
|
||||
|
|
Reference in a new issue