Commit 0339963f authored by Dave Reid's avatar Dave Reid

Fixing merge with 8.x

parents 98fbeaf3 b29fc4b2
......@@ -669,8 +669,10 @@ function drupal_settings_initialize() {
global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url, $config_directory_name;
$conf = array();
if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) {
include_once DRUPAL_ROOT . '/' . conf_path() . '/settings.php';
// Make conf_path() available as local variable in settings.php.
$conf_path = conf_path();
if (file_exists(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) {
include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php';
}
$is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
......
......@@ -830,13 +830,6 @@ function drupal_http_request($url, array $options = array()) {
// clash with the HTTP status codes.
$result->code = -$errno;
$result->error = trim($errstr) ? trim($errstr) : t('Error opening socket @socket', array('@socket' => $socket));
// Mark that this request failed. This will trigger a check of the web
// server's ability to make outgoing HTTP requests the next time that
// requirements checking is performed.
// See system_requirements().
variable_set('drupal_http_request_fails', TRUE);
return $result;
}
......@@ -3976,6 +3969,8 @@ function drupal_region_class($region) {
* which drupal_add_js() happened earlier in the page request.
* - defer: If set to TRUE, the defer attribute is set on the <script>
* tag. Defaults to FALSE.
* - async: If set to TRUE, the async attribute is set on the <script>
* tag. Defaults to FALSE.
* - cache: If set to FALSE, the JavaScript file is loaded anew on every page
* call; in other words, it is not cached. Used only when 'type' references
* a JavaScript file. Defaults to TRUE.
......@@ -4048,6 +4043,7 @@ function drupal_add_js($data = NULL, $options = NULL) {
'preprocess' => TRUE,
'cache' => TRUE,
'defer' => FALSE,
'async' => FALSE,
'browsers' => array(),
),
);
......@@ -4095,6 +4091,7 @@ function drupal_js_defaults($data = NULL) {
'scope' => 'header',
'cache' => TRUE,
'defer' => FALSE,
'async' => FALSE,
'preprocess' => TRUE,
'version' => NULL,
'data' => $data,
......@@ -4289,9 +4286,16 @@ function drupal_pre_render_scripts($elements) {
break;
}
// The defer attribute must not be specified if src is not defined.
if (!empty($item['defer']) && isset($element['#attributes']['src'])) {
$element['#attributes']['defer'] = 'defer';
// The defer and async attributes must not be specified if the src
// attribute is not present.
if (!empty($element['#attributes']['src'])) {
// Both may be specified for legacy browser fallback purposes.
if (!empty($item['async'])) {
$element['#attributes']['async'] = 'async';
}
if (!empty($item['defer'])) {
$element['#attributes']['defer'] = 'defer';
}
}
$elements[] = $element;
......
......@@ -987,6 +987,10 @@ function drupal_prepare_form($form_id, &$form, &$form_state) {
'#value' => $form['#build_id'],
'#id' => $form['#build_id'],
'#name' => 'form_build_id',
// Form processing and validation requires this value, so ensure the
// submitted form value appears literally, regardless of custom #tree
// and #parents being set elsewhere.
'#parents' => array('form_build_id'),
);
// Add a token, based on either #token or form_id, to any form displayed to
......@@ -1010,6 +1014,10 @@ function drupal_prepare_form($form_id, &$form, &$form_state) {
'#id' => drupal_html_id('edit-' . $form_id . '-form-token'),
'#type' => 'token',
'#default_value' => drupal_get_token($form['#token']),
// Form processing and validation requires this value, so ensure the
// submitted form value appears literally, regardless of custom #tree
// and #parents being set elsewhere.
'#parents' => array('form_token'),
);
}
}
......@@ -1019,6 +1027,10 @@ function drupal_prepare_form($form_id, &$form, &$form_state) {
'#type' => 'hidden',
'#value' => $form_id,
'#id' => drupal_html_id("edit-$form_id"),
// Form processing and validation requires this value, so ensure the
// submitted form value appears literally, regardless of custom #tree
// and #parents being set elsewhere.
'#parents' => array('form_id'),
);
}
if (!isset($form['#id'])) {
......
......@@ -323,6 +323,9 @@ function aggregator_form_opml_submit($form, &$form_state) {
if (!isset($response->error)) {
$data = $response->data;
}
else {
watchdog('aggregator', 'HTTP request to @url failed with error: @error', array('@url' => $form_state['values']['remote'], '@error' => $response->error));
}
}
$feeds = _aggregator_parse_opml($data);
......
......@@ -3,6 +3,5 @@ description = "Aggregates syndicated content (RSS, RDF, and Atom feeds) from ext
package = Core
version = VERSION
core = 8.x
files[] = aggregator.test
configure = admin/config/services/aggregator/settings
stylesheets[all][] = aggregator.theme.css
This diff is collapsed.
<?php
/**
* @file
* Definition of Drupal\aggregator\Tests\AddFeedTest.
*/
namespace Drupal\aggregator\Tests;
/**
* Tests aggregator feed adding.
*/
class AddFeedTest extends AggregatorTestBase {
public static function getInfo() {
return array(
'name' => 'Add feed functionality',
'description' => 'Add feed test.',
'group' => 'Aggregator'
);
}
/**
* Create a feed, ensure that it is unique, check the source, and delete the feed.
*/
function testAddFeed() {
$feed = $this->createFeed();
// Check feed data.
$this->assertEqual($this->getUrl(), url('admin/config/services/aggregator/add/feed', array('absolute' => TRUE)), t('Directed to correct url.'));
$this->assertTrue($this->uniqueFeed($feed->title, $feed->url), t('The feed is unique.'));
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed->fid);
$this->assertResponse(200, t('Feed source exists.'));
$this->assertText($feed->title, t('Page title'));
$this->drupalGet('aggregator/sources/' . $feed->fid . '/categorize');
$this->assertResponse(200, t('Feed categorization page exists.'));
// Delete feed.
$this->deleteFeed($feed);
}
/**
* Tests feeds with very long URLs.
*/
function testAddLongFeed() {
// Create a feed with a URL of > 255 characters.
$long_url = "https://www.google.com/search?ix=heb&sourceid=chrome&ie=UTF-8&q=angie+byron#sclient=psy-ab&hl=en&safe=off&source=hp&q=angie+byron&pbx=1&oq=angie+byron&aq=f&aqi=&aql=&gs_sm=3&gs_upl=0l0l0l10534l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=a70b6b1f0abe28d8&biw=1629&bih=889&ix=heb";
$feed = $this->createFeed($long_url);
// Create a second feed of > 255 characters, where the only difference is
// after the 255th character.
$long_url_2 = "https://www.google.com/search?ix=heb&sourceid=chrome&ie=UTF-8&q=angie+byron#sclient=psy-ab&hl=en&safe=off&source=hp&q=angie+byron&pbx=1&oq=angie+byron&aq=f&aqi=&aql=&gs_sm=3&gs_upl=0l0l0l10534l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=a70b6b1f0abe28d8&biw=1629&bih=889";
$feed_2 = $this->createFeed($long_url_2);
// Check feed data.
$this->assertTrue($this->uniqueFeed($feed->title, $feed->url), 'The first long URL feed is unique.');
$this->assertTrue($this->uniqueFeed($feed_2->title, $feed_2->url), 'The second long URL feed is unique.');
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed->fid);
$this->assertResponse(200, 'Long URL feed source exists.');
$this->assertText($feed->title, 'Page title');
$this->drupalGet('aggregator/sources/' . $feed->fid . '/categorize');
$this->assertResponse(200, 'Long URL feed categorization page exists.');
// Delete feeds.
$this->deleteFeed($feed);
$this->deleteFeed($feed_2);
}
}
<?php
/**
* @file
* Definition of Drupal\aggregator\Tests\AggregatorConfigurationTest.
*/
namespace Drupal\aggregator\Tests;
/**
* Tests aggregator configuration settings.
*/
class AggregatorConfigurationTest extends AggregatorTestBase {
public static function getInfo() {
return array(
'name' => 'Aggregator configuration',
'description' => 'Test aggregator settings page.',
'group' => 'Aggregator',
);
}
/**
* Tests the settings form to ensure the correct default values are used.
*/
function testSettingsPage() {
$edit = array(
'aggregator_allowed_html_tags' => '<a>',
'aggregator_summary_items' => 10,
'aggregator_clear' => 3600,
'aggregator_category_selector' => 'select',
'aggregator_teaser_length' => 200,
);
$this->drupalPost('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, t('"@name" has correct default value.', array('@name' => $name)));
}
}
}
<?php
/**
* @file
* Definition of Drupal\aggregator\Tests\AggregatorCronTest.
*/
namespace Drupal\aggregator\Tests;
class AggregatorCronTest extends AggregatorTestBase {
public static function getInfo() {
return array(
'name' => 'Update on cron functionality',
'description' => 'Update feeds on cron.',
'group' => 'Aggregator'
);
}
/**
* Add feeds update them on cron.
*/
public function testCron() {
// Create feed and test basic updating on cron.
global $base_url;
$key = config('system.cron')->get('cron_key');
$this->createSampleNodes();
$feed = $this->createFeed();
$this->cronRun();
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
$this->removeFeedItems($feed);
$this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
$this->cronRun();
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
// Test feed locking when queued for update.
$this->removeFeedItems($feed);
db_update('aggregator_feed')
->condition('fid', $feed->fid)
->fields(array(
'queued' => REQUEST_TIME,
))
->execute();
$this->cronRun();
$this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
db_update('aggregator_feed')
->condition('fid', $feed->fid)
->fields(array(
'queued' => 0,
))
->execute();
$this->cronRun();
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
}
}
<?php
/**
* @file
* Definition of Drupal\aggregator\Tests\AggregatorRenderingTest.
*/
namespace Drupal\aggregator\Tests;
class AggregatorRenderingTest extends AggregatorTestBase {
public static function getInfo() {
return array(
'name' => 'Checks display of aggregator items',
'description' => 'Checks display of aggregator items on the page.',
'group' => 'Aggregator'
);
}
/**
* Add a feed block to the page and checks its links.
*
* TODO: Test the category block as well.
*/
public function testBlockLinks() {
// Create feed.
$this->createSampleNodes();
$feed = $this->createFeed();
$this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
// Place block on page (@see block.test:moveBlockToRegion())
// Need admin user to be able to access block admin.
$this->admin_user = $this->drupalCreateUser(array(
'administer blocks',
'access administration pages',
'administer news feeds',
'access news feeds',
));
$this->drupalLogin($this->admin_user);
// Prepare to use the block admin form.
$block = array(
'module' => 'aggregator',
'delta' => 'feed-' . $feed->fid,
'title' => $feed->title,
);
$region = 'footer';
$edit = array();
$edit['blocks[' . $block['module'] . '_' . $block['delta'] . '][region]'] = $region;
// Check the feed block is available in the block list form.
$this->drupalGet('admin/structure/block');
$this->assertFieldByName('blocks[' . $block['module'] . '_' . $block['delta'] . '][region]', '', 'Aggregator feed block is available for positioning.');
// Position it.
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully moved to %region_name region.', array( '%region_name' => $region)));
// Confirm that the block is now being displayed on pages.
$this->drupalGet('node');
$this->assertText(t($block['title']), t('Feed block is displayed on the page.'));
// Find the expected read_more link.
$href = 'aggregator/sources/' . $feed->fid;
$links = $this->xpath('//a[@href = :href]', array(':href' => url($href)));
$this->assert(isset($links[0]), t('Link to href %href found.', array('%href' => $href)));
// Visit that page.
$this->drupalGet($href);
$correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => $feed->title));
$this->assertFalse(empty($correct_titles), t('Aggregator feed page is available and has the correct title.'));
// Set the number of news items to 0 to test that the block does not show
// up.
$feed->block = 0;
aggregator_save_feed((array) $feed);
// It is nescessary to flush the cache after saving the number of items.
$this->resetAll();
// Check that the block is no longer displayed.
$this->drupalGet('node');
$this->assertNoText(t($block['title']), 'Feed block is not displayed on the page when number of items is set to 0.');
}
/**
* Create a feed and check that feed's page.
*/
public function testFeedPage() {
// Increase the number of items published in the rss.xml feed so we have
// enough articles to test paging.
$config = config('system.rss-publishing');
$config->set('feed_default_items', 30);
$config->save();
// Create a feed with 30 items.
$this->createSampleNodes(30);
$feed = $this->createFeed();
$this->updateFeedItems($feed, 30);
// Check for the presence of a pager.
$this->drupalGet('aggregator/sources/' . $feed->fid);
$elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager'));
$this->assertTrue(!empty($elements), t('Individual source page contains a pager.'));
// Reset the number of items in rss.xml to the default value.
$config->set('feed_default_items', 10);
$config->save();
}
}
<?php
/**
* @file
* Definition of Drupal\aggregator\Tests\AggregatorTestBase.
*/
namespace Drupal\aggregator\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Defines a base class for testing aggregator.module.
*/
class AggregatorTestBase extends WebTestBase {
function setUp() {
parent::setUp(array('node', 'block', 'aggregator', 'aggregator_test'));
// Create an Article node type.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
}
$web_user = $this->drupalCreateUser(array('administer news feeds', 'access news feeds', 'create article content'));
$this->drupalLogin($web_user);
}
/**
* Create an aggregator feed (simulate form submission on admin/config/services/aggregator/add/feed).
*
* @param $feed_url
* If given, feed will be created with this URL, otherwise /rss.xml will be used.
* @return $feed
* Full feed object if possible.
*
* @see getFeedEditArray()
*/
function createFeed($feed_url = NULL) {
$edit = $this->getFeedEditArray($feed_url);
$this->drupalPost('admin/config/services/aggregator/add/feed', $edit, t('Save'));
$this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title'])), t('The feed !name has been added.', array('!name' => $edit['title'])));
$feed = db_query("SELECT * FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $edit['title'], ':url' => $edit['url']))->fetch();
$this->assertTrue(!empty($feed), t('The feed found in database.'));
return $feed;
}
/**
* Delete an aggregator feed.
*
* @param $feed
* Feed object representing the feed.
*/
function deleteFeed($feed) {
$this->drupalPost('admin/config/services/aggregator/edit/feed/' . $feed->fid, array(), t('Delete'));
$this->assertRaw(t('The feed %title has been deleted.', array('%title' => $feed->title)), t('Feed deleted successfully.'));
}
/**
* Return a randomly generated feed edit array.
*
* @param $feed_url
* If given, feed will be created with this URL, otherwise /rss.xml will be used.
* @return
* A feed array.
*/
function getFeedEditArray($feed_url = NULL) {
$feed_name = $this->randomName(10);
if (!$feed_url) {
$feed_url = url('rss.xml', array(
'query' => array('feed' => $feed_name),
'absolute' => TRUE,
));
}
$edit = array(
'title' => $feed_name,
'url' => $feed_url,
'refresh' => '900',
);
return $edit;
}
/**
* Return the count of the randomly created feed array.
*
* @return
* Number of feed items on default feed created by createFeed().
*/
function getDefaultFeedItemCount() {
// Our tests are based off of rss.xml, so let's find out how many elements should be related.
$feed_count = db_query_range('SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1', 0, config('system.rss-publishing')->get('feed_default_items'))->fetchField();
return $feed_count > 10 ? 10 : $feed_count;
}
/**
* Update feed items (simulate click to admin/config/services/aggregator/update/$fid).
*
* @param $feed
* Feed object representing the feed.
* @param $expected_count
* Expected number of feed items.
*/
function updateFeedItems(&$feed, $expected_count) {
// First, let's ensure we can get to the rss xml.
$this->drupalGet($feed->url);
$this->assertResponse(200, t('!url is reachable.', array('!url' => $feed->url)));
// Attempt to access the update link directly without an access token.
$this->drupalGet('admin/config/services/aggregator/update/' . $feed->fid);
$this->assertResponse(403);
// Refresh the feed (simulated link click).
$this->drupalGet('admin/config/services/aggregator');
$this->clickLink('update items');