security update core+modules

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-26 18:38:56 +02:00
parent 2f45ea820a
commit 7c96373038
1022 changed files with 30319 additions and 11259 deletions

View File

@@ -143,15 +143,7 @@ abstract class DrupalTestCase {
);
// Store assertion for display after the test has completed.
try {
$connection = Database::getConnection('default', 'simpletest_original_default');
}
catch (DatabaseConnectionNotDefinedException $e) {
// If the test was not set up, the simpletest_original_default
// connection does not exist.
$connection = Database::getConnection('default', 'default');
}
$connection
self::getDatabaseConnection()
->insert('simpletest')
->fields($assertion)
->execute();
@@ -166,6 +158,25 @@ abstract class DrupalTestCase {
}
}
/**
* Returns the database connection to the site running Simpletest.
*
* @return DatabaseConnection
* The database connection to use for inserting assertions.
*/
public static function getDatabaseConnection() {
try {
$connection = Database::getConnection('default', 'simpletest_original_default');
}
catch (DatabaseConnectionNotDefinedException $e) {
// If the test was not set up, the simpletest_original_default
// connection does not exist.
$connection = Database::getConnection('default', 'default');
}
return $connection;
}
/**
* Store an assertion from outside the testing context.
*
@@ -205,7 +216,8 @@ abstract class DrupalTestCase {
'file' => $caller['file'],
);
return db_insert('simpletest')
return self::getDatabaseConnection()
->insert('simpletest')
->fields($assertion)
->execute();
}
@@ -221,7 +233,8 @@ abstract class DrupalTestCase {
* @see DrupalTestCase::insertAssert()
*/
public static function deleteAssert($message_id) {
return (bool) db_delete('simpletest')
return (bool) self::getDatabaseConnection()
->delete('simpletest')
->condition('message_id', $message_id)
->execute();
}
@@ -435,10 +448,10 @@ abstract class DrupalTestCase {
}
/**
* Logs verbose message in a text file.
* Logs a verbose message in a text file.
*
* The a link to the vebose message will be placed in the test results via
* as a passing assertion with the text '[verbose message]'.
* The link to the verbose message will be placed in the test results as a
* passing assertion with the text '[verbose message]'.
*
* @param $message
* The verbose message to be stored.
@@ -447,7 +460,8 @@ abstract class DrupalTestCase {
*/
protected function verbose($message) {
if ($id = simpletest_verbose($message)) {
$url = file_create_url($this->originalFileDirectory . '/simpletest/verbose/' . get_class($this) . '-' . $id . '.html');
$class_safe = str_replace('\\', '_', get_class($this));
$url = file_create_url($this->originalFileDirectory . '/simpletest/verbose/' . $class_safe . '-' . $id . '.html');
$this->error(l(t('Verbose message'), $url, array('attributes' => array('target' => '_blank'))), 'User notice');
}
}
@@ -466,7 +480,8 @@ abstract class DrupalTestCase {
*/
public function run(array $methods = array()) {
// Initialize verbose debugging.
simpletest_verbose(NULL, variable_get('file_public_path', conf_path() . '/files'), get_class($this));
$class = get_class($this);
simpletest_verbose(NULL, variable_get('file_public_path', conf_path() . '/files'), str_replace('\\', '_', $class));
// HTTP auth settings (<username>:<password>) for the simpletest browser
// when sending requests to the test site.
@@ -478,7 +493,6 @@ abstract class DrupalTestCase {
}
set_error_handler(array($this, 'errorHandler'));
$class = get_class($this);
// Iterate through all the methods in this class, unless a specific list of
// methods to run was passed.
$class_methods = get_class_methods($class);
@@ -540,6 +554,15 @@ abstract class DrupalTestCase {
E_RECOVERABLE_ERROR => 'Recoverable error',
);
// PHP 5.3 adds new error logging constants. Add these conditionally for
// backwards compatibility with PHP 5.2.
if (defined('E_DEPRECATED')) {
$error_map += array(
E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User deprecated',
);
}
$backtrace = debug_backtrace();
$this->error($message, $error_map[$severity], _drupal_get_last_caller($backtrace));
}
@@ -729,6 +752,10 @@ class DrupalUnitTestCase extends DrupalTestCase {
// subsequently will fail as the database is not accessible.
$module_list = module_list();
if (isset($module_list['locale'])) {
// Transform the list into the format expected as input to module_list().
foreach ($module_list as &$module) {
$module = array('filename' => drupal_get_filename('module', $module));
}
$this->originalModuleList = $module_list;
unset($module_list['locale']);
module_list(TRUE, FALSE, FALSE, $module_list);
@@ -1131,7 +1158,7 @@ class DrupalWebTestCase extends DrupalTestCase {
}
/**
* Internal helper function; Create a role with specified permissions.
* Creates a role with specified permissions.
*
* @param $permissions
* Array of permission names to assign to role.
@@ -1217,28 +1244,28 @@ class DrupalWebTestCase extends DrupalTestCase {
* $account->pass_raw = $pass_raw;
* @endcode
*
* @param $user
* @param $account
* User object representing the user to log in.
*
* @see drupalCreateUser()
*/
protected function drupalLogin(stdClass $user) {
protected function drupalLogin(stdClass $account) {
if ($this->loggedInUser) {
$this->drupalLogout();
}
$edit = array(
'name' => $user->name,
'pass' => $user->pass_raw
'name' => $account->name,
'pass' => $account->pass_raw
);
$this->drupalPost('user', $edit, t('Log in'));
// If a "log out" link appears on the page, it is almost certainly because
// the login was successful.
$pass = $this->assertLink(t('Log out'), 0, t('User %name successfully logged in.', array('%name' => $user->name)), t('User login'));
$pass = $this->assertLink(t('Log out'), 0, t('User %name successfully logged in.', array('%name' => $account->name)), t('User login'));
if ($pass) {
$this->loggedInUser = $user;
$this->loggedInUser = $account;
}
}
@@ -1742,14 +1769,24 @@ class DrupalWebTestCase extends DrupalTestCase {
protected function curlExec($curl_options, $redirect = FALSE) {
$this->curlInitialize();
// cURL incorrectly handles URLs with a fragment by including the
// fragment in the request to the server, causing some web servers
// to reject the request citing "400 - Bad Request". To prevent
// this, we strip the fragment from the request.
// TODO: Remove this for Drupal 8, since fixed in curl 7.20.0.
if (!empty($curl_options[CURLOPT_URL]) && strpos($curl_options[CURLOPT_URL], '#')) {
$original_url = $curl_options[CURLOPT_URL];
$curl_options[CURLOPT_URL] = strtok($curl_options[CURLOPT_URL], '#');
if (!empty($curl_options[CURLOPT_URL])) {
// Forward XDebug activation if present.
if (isset($_COOKIE['XDEBUG_SESSION'])) {
$options = drupal_parse_url($curl_options[CURLOPT_URL]);
$options += array('query' => array());
$options['query'] += array('XDEBUG_SESSION_START' => $_COOKIE['XDEBUG_SESSION']);
$curl_options[CURLOPT_URL] = url($options['path'], $options);
}
// cURL incorrectly handles URLs with a fragment by including the
// fragment in the request to the server, causing some web servers
// to reject the request citing "400 - Bad Request". To prevent
// this, we strip the fragment from the request.
// TODO: Remove this for Drupal 8, since fixed in curl 7.20.0.
if (strpos($curl_options[CURLOPT_URL], '#')) {
$original_url = $curl_options[CURLOPT_URL];
$curl_options[CURLOPT_URL] = strtok($curl_options[CURLOPT_URL], '#');
}
}
$url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
@@ -2041,7 +2078,14 @@ class DrupalWebTestCase extends DrupalTestCase {
foreach ($upload as $key => $file) {
$file = drupal_realpath($file);
if ($file && is_file($file)) {
$post[$key] = '@' . $file;
// Use the new CurlFile class for file uploads when using PHP
// 5.5 or higher.
if (class_exists('CurlFile')) {
$post[$key] = curl_file_create($file);
}
else {
$post[$key] = '@' . $file;
}
}
}
}
@@ -2248,6 +2292,13 @@ class DrupalWebTestCase extends DrupalTestCase {
}
break;
case 'updateBuildId':
$buildId = $xpath->query('//input[@name="form_build_id" and @value="' . $command['old'] . '"]')->item(0);
if ($buildId) {
$buildId->setAttribute('value', $command['new']);
}
break;
// @todo Add suitable implementations for these commands in order to
// have full test coverage of what ajax.js can do.
case 'remove':
@@ -2260,12 +2311,22 @@ class DrupalWebTestCase extends DrupalTestCase {
break;
case 'restripe':
break;
case 'add_css':
break;
}
}
$content = $dom->saveHTML();
}
$this->drupalSetContent($content);
$this->drupalSetSettings($drupal_settings);
$verbose = 'AJAX POST request to: ' . $path;
$verbose .= '<br />AJAX callback path: ' . $ajax_path;
$verbose .= '<hr />Ending URL: ' . $this->getUrl();
$verbose .= '<hr />' . $this->content;
$this->verbose($verbose);
return $return;
}
@@ -2588,8 +2649,6 @@ class DrupalWebTestCase extends DrupalTestCase {
*
* @param $label
* Text between the anchor tags.
* @param $index
* Link position counting from zero.
* @param $message
* Message to display.
* @param $group
@@ -2646,31 +2705,28 @@ class DrupalWebTestCase extends DrupalTestCase {
/**
* Follows a link by name.
*
* Will click the first link found with this link text by default, or a
* later one if an index is given. Match is case insensitive with
* normalized space. The label is translated label. There is an assert
* for successful click.
* Will click the first link found with this link text by default, or a later
* one if an index is given. Match is case sensitive with normalized space.
* The label is translated label.
*
* If the link is discovered and clicked, the test passes. Fail otherwise.
*
* @param $label
* Text between the anchor tags.
* @param $index
* Link position counting from zero.
* @return
* Page on success, or FALSE on failure.
* Page contents on success, or FALSE on failure.
*/
protected function clickLink($label, $index = 0) {
$url_before = $this->getUrl();
$urls = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
if (isset($urls[$index])) {
$url_target = $this->getAbsoluteUrl($urls[$index]['href']);
}
$this->assertTrue(isset($urls[$index]), t('Clicked link %label (@url_target) from @url_before', array('%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before)), t('Browser'));
if (isset($url_target)) {
$this->pass(t('Clicked link %label (@url_target) from @url_before', array('%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before)), 'Browser');
return $this->drupalGet($url_target);
}
$this->fail(t('Link %label does not exist on @url_before', array('%label' => $label, '@url_before' => $url_before)), 'Browser');
return FALSE;
}
@@ -3148,13 +3204,51 @@ class DrupalWebTestCase extends DrupalTestCase {
return $this->assertNotEqual($actual, $title, $message, $group);
}
/**
* Asserts themed output.
*
* @param $callback
* The name of the theme function to invoke; e.g. 'links' for theme_links().
* @param $variables
* (optional) An array of variables to pass to the theme function.
* @param $expected
* The expected themed output string.
* @param $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* @param $group
* (optional) The group this message is in, which is displayed in a column
* in test output. Use 'Debug' to indicate this is debugging output. Do not
* translate this string. Defaults to 'Other'; most tests do not override
* this default.
*
* @return
* TRUE on pass, FALSE on fail.
*/
protected function assertThemeOutput($callback, array $variables = array(), $expected, $message = '', $group = 'Other') {
$output = theme($callback, $variables);
$this->verbose('Variables:' . '<pre>' . check_plain(var_export($variables, TRUE)) . '</pre>'
. '<hr />' . 'Result:' . '<pre>' . check_plain(var_export($output, TRUE)) . '</pre>'
. '<hr />' . 'Expected:' . '<pre>' . check_plain(var_export($expected, TRUE)) . '</pre>'
. '<hr />' . $output
);
if (!$message) {
$message = '%callback rendered correctly.';
}
$message = format_string($message, array('%callback' => 'theme_' . $callback . '()'));
return $this->assertIdentical($output, $expected, $message, $group);
}
/**
* Asserts that a field exists in the current page by the given XPath.
*
* @param $xpath
* XPath used to find the field.
* @param $value
* (optional) Value of the field to assert.
* (optional) Value of the field to assert. You may pass in NULL (default)
* to skip checking the actual value, while still checking that the field
* exists.
* @param $message
* (optional) Message to display.
* @param $group
@@ -3222,12 +3316,14 @@ class DrupalWebTestCase extends DrupalTestCase {
}
/**
* Asserts that a field does not exist in the current page by the given XPath.
* Asserts that a field doesn't exist or its value doesn't match, by XPath.
*
* @param $xpath
* XPath used to find the field.
* @param $value
* (optional) Value of the field to assert.
* (optional) Value for the field, to assert that the field's value on the
* page doesn't match it. You may pass in NULL to skip checking the
* value, while still checking that the field doesn't exist.
* @param $message
* (optional) Message to display.
* @param $group
@@ -3260,7 +3356,9 @@ class DrupalWebTestCase extends DrupalTestCase {
* @param $name
* Name of field to assert.
* @param $value
* Value of the field to assert.
* (optional) Value of the field to assert. You may pass in NULL (default)
* to skip checking the actual value, while still checking that the field
* exists.
* @param $message
* Message to display.
* @param $group
@@ -3291,9 +3389,12 @@ class DrupalWebTestCase extends DrupalTestCase {
* @param $name
* Name of field to assert.
* @param $value
* Value of the field to assert.
* (optional) Value for the field, to assert that the field's value on the
* page doesn't match it. You may pass in NULL to skip checking the
* value, while still checking that the field doesn't exist. However, the
* default value ('') asserts that the field value is not an empty string.
* @param $message
* Message to display.
* (optional) Message to display.
* @param $group
* The group this message belongs to.
* @return
@@ -3304,14 +3405,17 @@ class DrupalWebTestCase extends DrupalTestCase {
}
/**
* Asserts that a field exists in the current page with the given id and value.
* Asserts that a field exists in the current page with the given ID and value.
*
* @param $id
* Id of field to assert.
* ID of field to assert.
* @param $value
* Value of the field to assert.
* (optional) Value for the field to assert. You may pass in NULL to skip
* checking the value, while still checking that the field exists.
* However, the default value ('') asserts that the field value is an empty
* string.
* @param $message
* Message to display.
* (optional) Message to display.
* @param $group
* The group this message belongs to.
* @return
@@ -3322,14 +3426,17 @@ class DrupalWebTestCase extends DrupalTestCase {
}
/**
* Asserts that a field does not exist with the given id and value.
* Asserts that a field does not exist with the given ID and value.
*
* @param $id
* Id of field to assert.
* ID of field to assert.
* @param $value
* Value of the field to assert.
* (optional) Value for the field, to assert that the field's value on the
* page doesn't match it. You may pass in NULL to skip checking the value,
* while still checking that the field doesn't exist. However, the default
* value ('') asserts that the field value is not an empty string.
* @param $message
* Message to display.
* (optional) Message to display.
* @param $group
* The group this message belongs to.
* @return
@@ -3343,9 +3450,9 @@ class DrupalWebTestCase extends DrupalTestCase {
* Asserts that a checkbox field in the current page is checked.
*
* @param $id
* Id of field to assert.
* ID of field to assert.
* @param $message
* Message to display.
* (optional) Message to display.
* @return
* TRUE on pass, FALSE on fail.
*/
@@ -3358,9 +3465,9 @@ class DrupalWebTestCase extends DrupalTestCase {
* Asserts that a checkbox field in the current page is not checked.
*
* @param $id
* Id of field to assert.
* ID of field to assert.
* @param $message
* Message to display.
* (optional) Message to display.
* @return
* TRUE on pass, FALSE on fail.
*/
@@ -3373,11 +3480,11 @@ class DrupalWebTestCase extends DrupalTestCase {
* Asserts that a select option in the current page is checked.
*
* @param $id
* Id of select field to assert.
* ID of select field to assert.
* @param $option
* Option to assert.
* @param $message
* Message to display.
* (optional) Message to display.
* @return
* TRUE on pass, FALSE on fail.
*
@@ -3392,11 +3499,11 @@ class DrupalWebTestCase extends DrupalTestCase {
* Asserts that a select option in the current page is not checked.
*
* @param $id
* Id of select field to assert.
* ID of select field to assert.
* @param $option
* Option to assert.
* @param $message
* Message to display.
* (optional) Message to display.
* @return
* TRUE on pass, FALSE on fail.
*/
@@ -3406,12 +3513,12 @@ class DrupalWebTestCase extends DrupalTestCase {
}
/**
* Asserts that a field exists with the given name or id.
* Asserts that a field exists with the given name or ID.
*
* @param $field
* Name or id of field to assert.
* Name or ID of field to assert.
* @param $message
* Message to display.
* (optional) Message to display.
* @param $group
* The group this message belongs to.
* @return
@@ -3422,12 +3529,12 @@ class DrupalWebTestCase extends DrupalTestCase {
}
/**
* Asserts that a field does not exist with the given name or id.
* Asserts that a field does not exist with the given name or ID.
*
* @param $field
* Name or id of field to assert.
* Name or ID of field to assert.
* @param $message
* Message to display.
* (optional) Message to display.
* @param $group
* The group this message belongs to.
* @return