Skip to content
......@@ -350,7 +350,7 @@ Drupal.overlay.setFocusBefore = function ($element, document) {
* TRUE if the URL represents an administrative link, FALSE otherwise.
*/
Drupal.overlay.isAdminLink = function (url) {
if (Drupal.overlay.isExternalLink(url)) {
if (!Drupal.urlIsLocal(url)) {
return false;
}
......@@ -378,6 +378,8 @@ Drupal.overlay.isAdminLink = function (url) {
/**
* Determine whether a link is external to the site.
*
* Deprecated. Use Drupal.urlIsLocal() instead.
*
* @param url
* The URL to be tested.
*
......@@ -385,8 +387,7 @@ Drupal.overlay.isAdminLink = function (url) {
* TRUE if the URL is external to the site, FALSE otherwise.
*/
Drupal.overlay.isExternalLink = function (url) {
var re = RegExp('^((f|ht)tps?:)?//(?!' + window.location.host + ')');
return re.test(url);
return !Drupal.urlIsLocal(url);
};
/**
......@@ -405,7 +406,7 @@ Drupal.overlay.isExternalLink = function (url) {
*/
Drupal.overlay.getInternalUrl = function (path) {
var url = Drupal.settings.basePath + path;
if (!this.isExternalLink(url)) {
if (Drupal.urlIsLocal(url)) {
return url;
}
};
......
......@@ -78,6 +78,20 @@ function overlay_theme() {
);
}
/**
* Implements hook_form_alter().
*/
function overlay_form_alter(&$form, &$form_state) {
// Add a hidden element to prevent dropping out of the overlay when a form is
// submitted inside the overlay using a GET method.
if (isset($form['#method']) && $form['#method'] == 'get' && isset($_REQUEST['render']) && $_REQUEST['render'] == 'overlay' && !isset($form['render'])) {
$form['render'] = array(
'#type' => 'hidden',
'#value' => 'overlay',
);
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
......
......@@ -185,7 +185,7 @@ function path_form_element_validate($element, &$form_state, $complete_form) {
* Implements hook_node_insert().
*/
function path_node_insert($node) {
if (isset($node->path)) {
if (isset($node->path) && isset($node->path['alias'])) {
$path = $node->path;
$path['alias'] = trim($path['alias']);
// Only save a non-empty alias.
......@@ -205,9 +205,9 @@ function path_node_insert($node) {
function path_node_update($node) {
if (isset($node->path)) {
$path = $node->path;
$path['alias'] = trim($path['alias']);
$path['alias'] = isset($path['alias']) ? trim($path['alias']) : '';
// Delete old alias if user erased it.
if (!empty($path['pid']) && empty($path['alias'])) {
if (!empty($path['pid']) && !$path['alias']) {
path_delete($path['pid']);
}
path_node_insert($node);
......
......@@ -631,9 +631,6 @@ function poll_delete($node) {
* The node object to load.
*/
function poll_block_latest_poll_view($node) {
global $user;
$output = '';
// This is necessary for shared objects because PHP doesn't copy objects, but
// passes them by reference. So when the objects are cached it can result in
// the wrong output being displayed on subsequent calls. The cloning and
......@@ -674,9 +671,6 @@ function poll_block_latest_poll_view($node) {
* Implements hook_view().
*/
function poll_view($node, $view_mode) {
global $user;
$output = '';
if (!empty($node->allowvotes) && empty($node->show_results)) {
$node->content['poll_view_voting'] = drupal_get_form('poll_view_voting', $node);
}
......@@ -694,7 +688,7 @@ function poll_view($node, $view_mode) {
function poll_teaser($node) {
$teaser = NULL;
if (is_array($node->choice)) {
foreach ($node->choice as $k => $choice) {
foreach ($node->choice as $choice) {
if ($choice['chtext'] != '') {
$teaser .= '* ' . check_plain($choice['chtext']) . "\n";
}
......
......@@ -342,7 +342,7 @@ class ProfileTestAutocomplete extends ProfileTestCase {
// Autocomplete always uses non-clean URLs.
$current_clean_url = isset($GLOBALS['conf']['clean_url']) ? $GLOBALS['conf']['clean_url'] : NULL;
$GLOBALS['conf']['clean_url'] = 0;
$autocomplete_url = url('profile/autocomplete/' . $field['fid'], array('absolute' => TRUE));
$autocomplete_url = url('profile/autocomplete/' . $field['fid'], array('absolute' => TRUE, 'script' => 'index.php'));
$GLOBALS['conf']['clean_url'] = $current_clean_url;
$autocomplete_id = drupal_html_id('edit-' . $field['form_name'] . '-autocomplete');
$autocomplete_html = '<input type="hidden" id="' . $autocomplete_id . '" value="' . $autocomplete_url . '" disabled="disabled" class="autocomplete" />';
......
......@@ -4,3 +4,4 @@ package = Testing
version = VERSION
core = 7.x
hidden = TRUE
dependencies[] = blog
......@@ -30,8 +30,9 @@
*
* @return
* Array with optional keys:
* - title: Title for the tab on the search page for this module. Defaults
* to the module name if not given.
* - title: Title for the tab on the search page for this module. Title must
* be untranslated. Outside of this return array, pass the title through the
* t() function to register it as a translatable string.
* - path: Path component after 'search/' for searching with this module.
* Defaults to the module name if not given.
* - conditions_callback: An implementation of callback_search_conditions().
......@@ -39,6 +40,9 @@
* @ingroup search
*/
function hook_search_info() {
// Make the title translatable.
t('Content');
return array(
'title' => 'Content',
'path' => 'node',
......
......@@ -409,10 +409,10 @@ public function executeFirstPass() {
* used. However, if at least one call to addScore() has taken place, the
* keyword relevance score is not automatically added.
*
* Also note that if you call orderBy() directly on the query, search scores
* will not automatically be used to order search results. Your orderBy()
* expression can reference 'calculated_score', which will be the total
* calculated score value.
* Note that you must use this method to add ordering to your searches, and
* not call orderBy() directly, when using the SearchQuery extender. This is
* because of the two-pass system the SearchQuery class uses to normalize
* scores.
*
* @param $score
* The score expression, which should evaluate to a number between 0 and 1.
......
......@@ -49,7 +49,7 @@ function search_view($module = NULL, $keys = '') {
// which will get us back to this page callback. In other words, the search
// form submits with POST but redirects to GET. This way we can keep
// the search query URL clean as a whistle.
if (empty($_POST['form_id']) || $_POST['form_id'] != 'search_form') {
if (empty($_POST['form_id']) || ($_POST['form_id'] != 'search_form' && $_POST['form_id'] != 'search_block_form')) {
$conditions = NULL;
if (isset($info['conditions_callback']) && function_exists($info['conditions_callback'])) {
// Build an optional array of more search conditions.
......
......@@ -666,6 +666,24 @@ class SearchBlockTestCase extends DrupalWebTestCase {
url('search/node/', array('absolute' => TRUE)),
'Redirected to correct url.'
);
// Test that after entering a too-short keyword in the form, you can then
// search again with a longer keyword. First test using the block form.
$terms = array('search_block_form' => 'a');
$this->drupalPost('node', $terms, t('Search'));
$this->assertText('You must include at least one positive keyword with 3 characters or more');
$terms = array('search_block_form' => 'foo');
$this->drupalPost(NULL, $terms, t('Search'));
$this->assertNoText('You must include at least one positive keyword with 3 characters or more');
$this->assertText('Your search yielded no results');
// Same test again, using the search page form for the second search this time.
$terms = array('search_block_form' => 'a');
$this->drupalPost('node', $terms, t('Search'));
$terms = array('keys' => 'foo');
$this->drupalPost(NULL, $terms, t('Search'));
$this->assertNoText('You must include at least one positive keyword with 3 characters or more');
$this->assertText('Your search yielded no results');
}
}
......
......@@ -853,6 +853,13 @@ class DrupalWebTestCase extends DrupalTestCase {
*/
protected $cookieFile = NULL;
/**
* The cookies of the page currently loaded in the internal browser.
*
* @var array
*/
protected $cookies = array();
/**
* Additional cURL options.
*
......@@ -942,7 +949,6 @@ function drupalGetNodeByTitle($title, $reset = FALSE) {
protected function drupalCreateNode($settings = array()) {
// Populate defaults array.
$settings += array(
'body' => array(LANGUAGE_NONE => array(array())),
'title' => $this->randomName(8),
'comment' => 2,
'changed' => REQUEST_TIME,
......@@ -957,6 +963,12 @@ protected function drupalCreateNode($settings = array()) {
'language' => LANGUAGE_NONE,
);
// Add the body after the language is defined so that it may be set
// properly.
$settings += array(
'body' => array($settings['language'] => array(array())),
);
// Use the original node's created time for existing nodes.
if (isset($settings['created']) && !isset($settings['date'])) {
$settings['date'] = format_date($settings['created'], 'custom', 'Y-m-d H:i:s O');
......@@ -1065,7 +1077,7 @@ protected function drupalGetTestFiles($type, $size = NULL) {
$lines = array(16, 256, 1024, 2048, 20480);
$count = 0;
foreach ($lines as $line) {
simpletest_generate_file('text-' . $count++, 64, $line);
simpletest_generate_file('text-' . $count++, 64, $line, 'text');
}
// Copy other test files from simpletest.
......@@ -1693,8 +1705,10 @@ protected function tearDown() {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
// Close the CURL handler.
// Close the CURL handler and reset the cookies array so test classes
// containing multiple tests are not polluted.
$this->curlClose();
$this->cookies = array();
}
/**
......@@ -2584,6 +2598,11 @@ protected function buildXPathQuery($xpath, array $args = array()) {
*
* @param $xpath
* The xpath string to use in the search.
* @param array $arguments
* An array of arguments with keys in the form ':name' matching the
* placeholders in the query. The values may be either strings or numeric
* values.
*
* @return
* The return value of the xpath search. For details on the xpath string
* format and return values see the SimpleXML documentation,
......@@ -2755,7 +2774,7 @@ protected function getAbsoluteUrl($path) {
$path = substr($path, $length);
}
// Ensure that we have an absolute path.
if ($path[0] !== '/') {
if (empty($path) || $path[0] !== '/') {
$path = '/' . $path;
}
// Finally, prepend the $base_url.
......
......@@ -154,7 +154,7 @@ function simpletest_run_tests($test_list, $reporter = 'drupal') {
}
/**
* Batch operation callback.
* Implements callback_batch_operation().
*/
function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
simpletest_classloader_register();
......@@ -205,6 +205,9 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
$context['finished'] = 1 - $size / $max;
}
/**
* Implements callback_batch_finished().
*/
function _simpletest_batch_finished($success, $results, $operations, $elapsed) {
if ($success) {
drupal_set_message(t('The test run finished in @elapsed.', array('@elapsed' => $elapsed)));
......@@ -371,7 +374,10 @@ function simpletest_test_get_all() {
// If this test class requires a non-existing module, skip it.
if (!empty($info['dependencies'])) {
foreach ($info['dependencies'] as $module) {
if (!drupal_get_filename('module', $module)) {
// Pass FALSE as fourth argument so no error gets created for
// the missing file.
$found_module = drupal_get_filename('module', $module, NULL, FALSE);
if (!$found_module) {
continue 2;
}
}
......@@ -509,25 +515,25 @@ function simpletest_registry_files_alter(&$files, $modules) {
* Generate test file.
*/
function simpletest_generate_file($filename, $width, $lines, $type = 'binary-text') {
$size = $width * $lines - $lines;
// Generate random text
$text = '';
for ($i = 0; $i < $size; $i++) {
switch ($type) {
case 'text':
$text .= chr(rand(32, 126));
break;
case 'binary':
$text .= chr(rand(0, 31));
break;
case 'binary-text':
default:
$text .= rand(0, 1);
break;
for ($i = 0; $i < $lines; $i++) {
// Generate $width - 1 characters to leave space for the "\n" character.
for ($j = 0; $j < $width - 1; $j++) {
switch ($type) {
case 'text':
$text .= chr(rand(32, 126));
break;
case 'binary':
$text .= chr(rand(0, 31));
break;
case 'binary-text':
default:
$text .= rand(0, 1);
break;
}
}
$text .= "\n";
}
$text = wordwrap($text, $width - 1, "\n", TRUE) . "\n"; // Add \n for symmetrical file.
// Create filename.
file_put_contents('public://' . $filename . '.txt', $text);
......
......@@ -322,6 +322,14 @@ class SimpleTestFunctionalTest extends DrupalWebTestCase {
* Test internal testing framework browser.
*/
class SimpleTestBrowserTestCase extends DrupalWebTestCase {
/**
* A flag indicating whether a cookie has been set in a test.
*
* @var bool
*/
protected static $cookieSet = FALSE;
public static function getInfo() {
return array(
'name' => 'SimpleTest browser',
......@@ -380,6 +388,46 @@ EOF;
$urls = $this->xpath('//a[text()=:text]', array(':text' => 'A second "even more weird" link, in memory of George O\'Malley'));
$this->assertEqual($urls[0]['href'], 'link2', 'Match with mixed single and double quotes.');
}
/**
* Tests that cookies set during a request are available for testing.
*/
public function testCookies() {
// Check that the $this->cookies property is populated when a user logs in.
$user = $this->drupalCreateUser();
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
$this->drupalPost('<front>', $edit, t('Log in'));
$this->assertEqual(count($this->cookies), 1, 'A cookie is set when the user logs in.');
// Check that the name and value of the cookie match the request data.
$cookie_header = $this->drupalGetHeader('set-cookie', TRUE);
// The name and value are located at the start of the string, separated by
// an equals sign and ending in a semicolon.
preg_match('/^([^=]+)=([^;]+)/', $cookie_header, $matches);
$name = $matches[1];
$value = $matches[2];
$this->assertTrue(array_key_exists($name, $this->cookies), 'The cookie name is correct.');
$this->assertEqual($value, $this->cookies[$name]['value'], 'The cookie value is correct.');
// Set a flag indicating that a cookie has been set in this test.
// @see SimpleTestBrowserTestCase::testCookieDoesNotBleed().
self::$cookieSet = TRUE;
}
/**
* Tests that the cookies from a previous test do not bleed into a new test.
*
* @see SimpleTestBrowserTestCase::testCookies().
*/
public function testCookieDoesNotBleed() {
// In order for this test to be effective it should always run after the
// testCookies() test.
$this->assertTrue(self::$cookieSet, 'Tests have been executed in the expected order.');
$this->assertEqual(count($this->cookies), 0, 'No cookies are present at the start of a new test.');
}
}
class SimpleTestMailCaptureTestCase extends DrupalWebTestCase {
......
......@@ -7,6 +7,8 @@
*/
/**
* Implements callback_batch_operation().
*
* Simple batch operation.
*/
function _batch_test_callback_1($id, $sleep, &$context) {
......@@ -20,6 +22,8 @@ function _batch_test_callback_1($id, $sleep, &$context) {
}
/**
* Implements callback_batch_operation().
*
* Multistep batch operation.
*/
function _batch_test_callback_2($start, $total, $sleep, &$context) {
......@@ -53,6 +57,8 @@ function _batch_test_callback_2($start, $total, $sleep, &$context) {
}
/**
* Implements callback_batch_operation().
*
* Simple batch operation.
*/
function _batch_test_callback_5($id, $sleep, &$context) {
......@@ -68,6 +74,8 @@ function _batch_test_callback_5($id, $sleep, &$context) {
}
/**
* Implements callback_batch_operation().
*
* Batch operation setting up its own batch.
*/
function _batch_test_nested_batch_callback() {
......@@ -76,6 +84,8 @@ function _batch_test_nested_batch_callback() {
}
/**
* Implements callback_batch_finished().
*
* Common 'finished' callbacks for batches 1 to 4.
*/
function _batch_test_finished_helper($batch_id, $success, $results, $operations) {
......@@ -99,6 +109,8 @@ function _batch_test_finished_helper($batch_id, $success, $results, $operations)
}
/**
* Implements callback_batch_finished().
*
* 'finished' callback for batch 0.
*/
function _batch_test_finished_0($success, $results, $operations) {
......@@ -106,6 +118,8 @@ function _batch_test_finished_0($success, $results, $operations) {
}
/**
* Implements callback_batch_finished().
*
* 'finished' callback for batch 1.
*/
function _batch_test_finished_1($success, $results, $operations) {
......@@ -113,6 +127,8 @@ function _batch_test_finished_1($success, $results, $operations) {
}
/**
* Implements callback_batch_finished().
*
* 'finished' callback for batch 2.
*/
function _batch_test_finished_2($success, $results, $operations) {
......@@ -120,6 +136,8 @@ function _batch_test_finished_2($success, $results, $operations) {
}
/**
* Implements callback_batch_finished().
*
* 'finished' callback for batch 3.
*/
function _batch_test_finished_3($success, $results, $operations) {
......@@ -127,6 +145,8 @@ function _batch_test_finished_3($success, $results, $operations) {
}
/**
* Implements callback_batch_finished().
*
* 'finished' callback for batch 4.
*/
function _batch_test_finished_4($success, $results, $operations) {
......@@ -134,6 +154,8 @@ function _batch_test_finished_4($success, $results, $operations) {
}
/**
* Implements callback_batch_finished().
*
* 'finished' callback for batch 5.
*/
function _batch_test_finished_5($success, $results, $operations) {
......
This diff is collapsed.
......@@ -372,6 +372,65 @@ class CommonURLUnitTest extends DrupalWebTestCase {
}
}
/**
* Tests url_is_external().
*/
class UrlIsExternalUnitTest extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'External URL checking',
'description' => 'Performs tests on url_is_external().',
'group' => 'System',
);
}
/**
* Tests if each URL is external or not.
*/
function testUrlIsExternal() {
foreach ($this->examples() as $path => $expected) {
$this->assertIdentical(url_is_external($path), $expected, $path);
}
}
/**
* Provides data for testUrlIsExternal().
*
* @return array
* An array of test data, keyed by a path, with the expected value where
* TRUE is external, and FALSE is not external.
*/
protected function examples() {
return array(
// Simple external URLs.
'http://example.com' => TRUE,
'https://example.com' => TRUE,
'http://drupal.org/foo/bar?foo=bar&bar=baz&baz#foo' => TRUE,
'//drupal.org' => TRUE,
// Some browsers ignore or strip leading control characters.
"\x00//www.example.com" => TRUE,
"\x08//www.example.com" => TRUE,
"\x1F//www.example.com" => TRUE,
"\n//www.example.com" => TRUE,
// JSON supports decoding directly from UTF-8 code points.
json_decode('"\u00AD"') . "//www.example.com" => TRUE,
json_decode('"\u200E"') . "//www.example.com" => TRUE,
json_decode('"\uE0020"') . "//www.example.com" => TRUE,
json_decode('"\uE000"') . "//www.example.com" => TRUE,
// Backslashes should be normalized to forward.
'\\\\example.com' => TRUE,
// Local URLs.
'node' => FALSE,
'/system/ajax' => FALSE,
'?q=foo:bar' => FALSE,
'node/edit:me' => FALSE,
'/drupal.org' => FALSE,
'<front>' => FALSE,
);
}
}
/**
* Tests for check_plain(), filter_xss(), format_string(), and check_url().
*/
......@@ -888,6 +947,31 @@ class DrupalHTMLIdentifierTestCase extends DrupalUnitTestCase {
// Verify that invalid characters (including non-breaking space) are stripped from the identifier.
$this->assertIdentical(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()), 'invalididentifier', 'Strip invalid characters.');
// Verify that double underscores are replaced in the identifier by default.
$identifier = 'css__identifier__with__double__underscores';
$expected = 'css--identifier--with--double--underscores';
$this->assertIdentical(drupal_clean_css_identifier($identifier), $expected, 'Verify double underscores are replaced with double hyphens by default.');
// Verify that double underscores are preserved in the identifier if the
// variable allow_css_double_underscores is set to TRUE.
$this->setAllowCSSDoubleUnderscores(TRUE);
$this->assertIdentical(drupal_clean_css_identifier($identifier), $identifier, 'Verify double underscores are preserved if the allow_css_double_underscores set to TRUE.');
// To avoid affecting other test cases, set the variable
// allow_css_double_underscores to FALSE which is the default value.
$this->setAllowCSSDoubleUnderscores(FALSE);
}
/**
* Set the variable allow_css_double_underscores and reset the cache.
*
* @param $value bool
* A new value to be set to allow_css_double_underscores.
*/
function setAllowCSSDoubleUnderscores($value) {
$GLOBALS['conf']['allow_css_double_underscores'] = $value;
drupal_static_reset('drupal_clean_css_identifier:allow_css_double_underscores');
}
/**
......@@ -1195,7 +1279,7 @@ class DrupalSetContentTestCase extends DrupalWebTestCase {
function testRegions() {
global $theme_key;
$block_regions = array_keys(system_region_list($theme_key));
$block_regions = system_region_list($theme_key, REGIONS_ALL, FALSE);
$delimiter = $this->randomName(32);
$values = array();
// Set some random content for each region available.
......@@ -1256,6 +1340,15 @@ class DrupalGotoTest extends DrupalWebTestCase {
$this->assertText('drupal_goto', 'Drupal goto redirect succeeded.');
$this->assertEqual($this->getUrl(), url('common-test/drupal_goto', array('query' => array('foo' => '123'), 'absolute' => TRUE)), 'Drupal goto redirected to expected URL.');
// Test that calling drupal_goto() on the current path is not dangerous.
variable_set('common_test_redirect_current_path', TRUE);
$this->drupalGet('', array('query' => array('q' => 'http://www.example.com/')));
$headers = $this->drupalGetHeaders(TRUE);
list(, $status) = explode(' ', $headers[0][':status'], 3);
$this->assertEqual($status, 302, 'Expected response code was sent.');
$this->assertNotEqual($this->getUrl(), 'http://www.example.com/', 'Drupal goto did not redirect to external URL.');
$this->assertTrue(strpos($this->getUrl(), url('<front>', array('absolute' => TRUE))) === 0, 'Drupal redirected to itself.');
variable_del('common_test_redirect_current_path');
// Test that drupal_goto() respects ?destination=xxx. Use an complicated URL
// to test that the path is encoded and decoded properly.
$destination = 'common-test/drupal_goto/destination?foo=%2525&bar=123';
......
......@@ -92,6 +92,15 @@ function common_test_drupal_goto_alter(&$path, &$options, &$http_response_code)
}
}
/**
* Implements hook_init().
*/
function common_test_init() {
if (variable_get('common_test_redirect_current_path', FALSE)) {
drupal_goto(current_path());
}
}
/**
* Print destination query parameter.
*/
......
......@@ -4,3 +4,19 @@
* @file
* Test module to check code registry.
*/
/**
* Implements hook_registry_files_alter().
*/
function drupal_autoload_test_registry_files_alter(&$files, $modules) {
foreach ($modules as $module) {
// Add the drupal_autoload_test_trait.sh file to the registry when PHP 5.4+
// is being used.
if ($module->name == 'drupal_autoload_test' && version_compare(PHP_VERSION, '5.4') >= 0) {
$files["$module->dir/drupal_autoload_test_trait.sh"] = array(
'module' => $module->name,
'weight' => $module->weight,
);
}
}
}
<?php
/**
* @file
* Test traits for code registry testing.
*
* This file has a non-standard extension to prevent PHP < 5.4 testbots from
* trying to run a syntax check on it.
* @todo Use a standard extension once the testbots allow it. See
* https://www.drupal.org/node/2589649.
*/
/**
* This trait is empty because we only care if Drupal can find it.
*/
trait DrupalAutoloadTestTrait {}