updated core to 7.73

This commit is contained in:
2020-09-24 17:04:08 +02:00
parent 084d28842a
commit 7d87153100
524 changed files with 25194 additions and 7745 deletions
+201 -81
View File
@@ -39,6 +39,13 @@ abstract class DrupalTestCase {
*/
protected $originalFileDirectory = NULL;
/**
* URL to the verbose output file directory.
*
* @var string
*/
protected $verboseDirectoryUrl;
/**
* Time limit for the test.
*/
@@ -143,15 +150,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 +165,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 +223,8 @@ abstract class DrupalTestCase {
'file' => $caller['file'],
);
return db_insert('simpletest')
return self::getDatabaseConnection()
->insert('simpletest')
->fields($assertion)
->execute();
}
@@ -221,7 +240,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 +455,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.
@@ -448,8 +468,11 @@ abstract class DrupalTestCase {
protected function verbose($message) {
if ($id = simpletest_verbose($message)) {
$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');
$url = $this->verboseDirectoryUrl . '/' . $class_safe . '-' . $id . '.html';
// Not using l() to avoid invoking the theme system, so that unit tests
// can use verbose() as well.
$link = '<a href="' . $url . '" target="_blank">' . t('Verbose message') . '</a>';
$this->error($link, 'User notice');
}
}
@@ -541,6 +564,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));
}
@@ -697,10 +729,17 @@ class DrupalUnitTestCase extends DrupalTestCase {
* method.
*/
protected function setUp() {
global $conf;
global $conf, $language;
// Store necessary current values before switching to the test environment.
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->verboseDirectoryUrl = file_create_url($this->originalFileDirectory . '/simpletest/verbose');
// Set up English language.
$this->originalLanguage = $language;
$this->originalLanguageDefault = variable_get('language_default');
unset($conf['language_default']);
$language = language_default();
// Reset all statics so that test is performed with a clean environment.
drupal_static_reset();
@@ -730,6 +769,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);
@@ -738,7 +781,7 @@ class DrupalUnitTestCase extends DrupalTestCase {
}
protected function tearDown() {
global $conf;
global $conf, $language;
// Get back to the original connection.
Database::removeConnection('default');
@@ -749,6 +792,12 @@ class DrupalUnitTestCase extends DrupalTestCase {
if (isset($this->originalModuleList)) {
module_list(TRUE, FALSE, FALSE, $this->originalModuleList);
}
// Reset language.
$language = $this->originalLanguage;
if ($this->originalLanguageDefault) {
$GLOBALS['conf']['language_default'] = $this->originalLanguageDefault;
}
}
}
@@ -827,6 +876,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.
*
@@ -916,7 +972,6 @@ class DrupalWebTestCase extends DrupalTestCase {
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,
@@ -931,6 +986,12 @@ class DrupalWebTestCase extends DrupalTestCase {
'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');
@@ -989,9 +1050,7 @@ class DrupalWebTestCase extends DrupalTestCase {
'description' => '',
'help' => '',
'title_label' => 'Title',
'body_label' => 'Body',
'has_title' => 1,
'has_body' => 1,
);
// Imposed values for a custom type.
$forced = array(
@@ -1041,7 +1100,7 @@ class DrupalWebTestCase extends DrupalTestCase {
$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.
@@ -1132,7 +1191,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.
@@ -1338,12 +1397,14 @@ class DrupalWebTestCase extends DrupalTestCase {
* @see DrupalWebTestCase::tearDown()
*/
protected function prepareEnvironment() {
global $user, $language, $conf;
global $user, $language, $language_url, $conf;
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageUrl = $language_url;
$this->originalLanguageDefault = variable_get('language_default');
$this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
$this->verboseDirectoryUrl = file_create_url($this->originalFileDirectory . '/simpletest/verbose');
$this->originalProfile = drupal_get_profile();
$this->originalCleanUrl = variable_get('clean_url', 0);
$this->originalUser = $user;
@@ -1351,7 +1412,7 @@ class DrupalWebTestCase extends DrupalTestCase {
// Set to English to prevent exceptions from utf8_truncate() from t()
// during install if the current language is not 'en'.
// The following array/object conversion is copied from language_default().
$language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => '');
$language_url = $language = (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => '');
// Save and clean the shutdown callbacks array because it is static cached
// and will be changed by the test run. Otherwise it will contain callbacks
@@ -1409,7 +1470,7 @@ class DrupalWebTestCase extends DrupalTestCase {
* @see DrupalWebTestCase::prepareEnvironment()
*/
protected function setUp() {
global $user, $language, $conf;
global $user, $language, $language_url, $conf;
// Create the database prefix for this test.
$this->prepareDatabasePrefix();
@@ -1506,7 +1567,7 @@ class DrupalWebTestCase extends DrupalTestCase {
// Set up English language.
unset($conf['language_default']);
$language = language_default();
$language_url = $language = language_default();
// Use the test mail class instead of the default mail handler class.
variable_set('mail_system', array('default-system' => 'TestingMailSystem'));
@@ -1600,7 +1661,7 @@ class DrupalWebTestCase extends DrupalTestCase {
* and reset the database prefix.
*/
protected function tearDown() {
global $user, $language;
global $user, $language, $language_url;
// In case a fatal error occurred that was not in the test process read the
// log to pick up any fatal errors.
@@ -1665,12 +1726,15 @@ class DrupalWebTestCase extends DrupalTestCase {
// Reset language.
$language = $this->originalLanguage;
$language_url = $this->originalLanguageUrl;
if ($this->originalLanguageDefault) {
$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();
}
/**
@@ -1743,14 +1807,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];
@@ -2042,7 +2116,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;
}
}
}
}
@@ -2178,6 +2259,7 @@ class DrupalWebTestCase extends DrupalTestCase {
// Submit the POST request.
$return = drupal_json_decode($this->drupalPost(NULL, $edit, array('path' => $ajax_path, 'triggering_element' => $triggering_element), $options, $headers, $form_html_id, $extra_post));
$this->assertIdentical($this->drupalGetHeader('X-Drupal-Ajax-Token'), '1', 'Ajax response header found.');
// Change the page content by applying the returned commands.
if (!empty($ajax_settings) && !empty($return)) {
@@ -2214,8 +2296,13 @@ class DrupalWebTestCase extends DrupalTestCase {
if ($wrapperNode) {
// ajax.js adds an enclosing DIV to work around a Safari bug.
$newDom = new DOMDocument();
// DOM can load HTML soup. But, HTML soup can throw warnings,
// suppress them.
$newDom->loadHTML('<div>' . $command['data'] . '</div>');
$newNode = $dom->importNode($newDom->documentElement->firstChild->firstChild, TRUE);
// Suppress warnings thrown when duplicate HTML IDs are
// encountered. This probably means we are replacing an element
// with the same ID.
$newNode = @$dom->importNode($newDom->documentElement->firstChild->firstChild, TRUE);
$method = isset($command['method']) ? $command['method'] : $ajax_settings['method'];
// The "method" is a jQuery DOM manipulation function. Emulate
// each one using PHP's DOMNode API.
@@ -2249,6 +2336,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':
@@ -2261,12 +2355,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;
}
@@ -2520,6 +2624,11 @@ class DrupalWebTestCase extends DrupalTestCase {
*
* @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,
@@ -2589,8 +2698,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
@@ -2649,28 +2756,26 @@ class DrupalWebTestCase extends DrupalTestCase {
*
* 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. There is an assert for successful click.
* 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;
}
@@ -2695,7 +2800,7 @@ class DrupalWebTestCase extends DrupalTestCase {
$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.
@@ -2907,7 +3012,7 @@ class DrupalWebTestCase extends DrupalTestCase {
if (!$message) {
$message = t('Raw "@raw" found', array('@raw' => $raw));
}
return $this->assert(strpos($this->drupalGetContent(), $raw) !== FALSE, $message, $group);
return $this->assert(strpos($this->drupalGetContent(), (string) $raw) !== FALSE, $message, $group);
}
/**
@@ -2927,7 +3032,7 @@ class DrupalWebTestCase extends DrupalTestCase {
if (!$message) {
$message = t('Raw "@raw" not found', array('@raw' => $raw));
}
return $this->assert(strpos($this->drupalGetContent(), $raw) === FALSE, $message, $group);
return $this->assert(strpos($this->drupalGetContent(), (string) $raw) === FALSE, $message, $group);
}
/**
@@ -3154,7 +3259,7 @@ class DrupalWebTestCase extends DrupalTestCase {
* @param $callback
* The name of the theme function to invoke; e.g. 'links' for theme_links().
* @param $variables
* An array of variables to pass to the theme function.
* (optional) An array of variables to pass to the theme function.
* @param $expected
* The expected themed output string.
* @param $message
@@ -3190,7 +3295,9 @@ class DrupalWebTestCase extends DrupalTestCase {
* @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
@@ -3258,12 +3365,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
@@ -3296,7 +3405,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
@@ -3327,9 +3438,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
@@ -3340,14 +3454,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
@@ -3358,14 +3475,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
@@ -3379,9 +3499,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.
*/
@@ -3394,9 +3514,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.
*/
@@ -3409,11 +3529,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.
*
@@ -3428,11 +3548,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.
*/
@@ -3442,12 +3562,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
@@ -3458,12 +3578,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
@@ -1,5 +1,7 @@
@import url("http://example.com/style.css");
@import url("//example.com/style.css");
@import "import1.css";
@import "import2.css";
@@ -1,4 +1,4 @@
ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(images/icon.png);}
@import url("http://example.com/style.css");@import url("//example.com/style.css");ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(images/icon.png);}.data .double-quote{background-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");}.data .single-quote{background-image:url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKAAH//Z');}.data .no-quote{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAEAQAAAAAo/mtHAAAAIElEQVQIHWMRnWHwcRNLN8NZ7QYWwT8PlBlYsgqVBRsAankIMw5MtnoAAAAASUVORK5CYII=);}
p,select{font:1em/160% Verdana,sans-serif;color:#494949;}
body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}.this
.is
@@ -1,6 +1,33 @@
@import url("http://example.com/style.css");
@import url("//example.com/style.css");
ul, select {
font: 1em/160% Verdana, sans-serif;
color: #494949;
}
.ui-icon{background-image: url(images/icon.png);}
/* Test data URI images with different quote styles. */
.data .double-quote {
/* http://stackoverflow.com/a/13139830/11023 */
background-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
}
.data .single-quote {
background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKAAH//Z');
}
.data .no-quote {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAEAQAAAAAo/mtHAAAAIElEQVQIHWMRnWHwcRNLN8NZ7QYWwT8PlBlYsgqVBRsAankIMw5MtnoAAAAASUVORK5CYII=);
}
p, select {
font: 1em/160% Verdana, sans-serif;
color: #494949;
}
body {
@@ -0,0 +1,29 @@
@import "../import1.css";
@import "../import2.css";
body {
margin: 0;
padding: 0;
background: #edf5fa;
font: 76%/170% Verdana, sans-serif;
color: #494949;
}
.this .is .a .test {
font: 1em/100% Verdana, sans-serif;
color: #494949;
}
.this
.is
.a
.test {
font: 1em/100% Verdana, sans-serif;
color: #494949;
}
textarea, select {
font: 1em/160% Verdana, sans-serif;
color: #494949;
}
@@ -0,0 +1,6 @@
ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(../images/icon.png);}.data .double-quote{background-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");}.data .single-quote{background-image:url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKAAH//Z');}.data .no-quote{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAEAQAAAAAo/mtHAAAAIElEQVQIHWMRnWHwcRNLN8NZ7QYWwT8PlBlYsgqVBRsAankIMw5MtnoAAAAASUVORK5CYII=);}
p,select{font:1em/160% Verdana,sans-serif;color:#494949;}
body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}.this
.is
.a
.test{font:1em/100% Verdana,sans-serif;color:#494949;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;}
@@ -0,0 +1,54 @@
ul, select {
font: 1em/160% Verdana, sans-serif;
color: #494949;
}
.ui-icon{background-image: url(../images/icon.png);}
/* Test data URI images with different quote styles. */
.data .double-quote {
/* http://stackoverflow.com/a/13139830/11023 */
background-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
}
.data .single-quote {
background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKAAH//Z');
}
.data .no-quote {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAEAQAAAAAo/mtHAAAAIElEQVQIHWMRnWHwcRNLN8NZ7QYWwT8PlBlYsgqVBRsAankIMw5MtnoAAAAASUVORK5CYII=);
}
p, select {
font: 1em/160% Verdana, sans-serif;
color: #494949;
}
body {
margin: 0;
padding: 0;
background: #edf5fa;
font: 76%/170% Verdana, sans-serif;
color: #494949;
}
.this .is .a .test {
font: 1em/100% Verdana, sans-serif;
color: #494949;
}
.this
.is
.a
.test {
font: 1em/100% Verdana, sans-serif;
color: #494949;
}
textarea, select {
font: 1em/160% Verdana, sans-serif;
color: #494949;
}
@@ -3,4 +3,18 @@ ul, select {
font: 1em/160% Verdana, sans-serif;
color: #494949;
}
.ui-icon{background-image: url(images/icon.png);}
.ui-icon{background-image: url(images/icon.png);}
/* Test data URI images with different quote styles. */
.data .double-quote {
/* http://stackoverflow.com/a/13139830/11023 */
background-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
}
.data .single-quote {
background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AKAAH//Z');
}
.data .no-quote {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAEAQAAAAAo/mtHAAAAIElEQVQIHWMRnWHwcRNLN8NZ7QYWwT8PlBlYsgqVBRsAankIMw5MtnoAAAAASUVORK5CYII=);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 964 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.
+6 -4
View File
@@ -11,10 +11,12 @@ configure = admin/config/development/testing/settings
files[] = tests/actions.test
files[] = tests/ajax.test
files[] = tests/batch.test
files[] = tests/boot.test
files[] = tests/bootstrap.test
files[] = tests/cache.test
files[] = tests/common.test
files[] = tests/database_test.test
files[] = tests/entity_crud.test
files[] = tests/entity_crud_hook_test.test
files[] = tests/entity_query.test
files[] = tests/error.test
@@ -31,6 +33,7 @@ files[] = tests/pager.test
files[] = tests/password.test
files[] = tests/path.test
files[] = tests/registry.test
files[] = tests/request_sanitizer.test
files[] = tests/schema.test
files[] = tests/session.test
files[] = tests/tablesort.test
@@ -55,8 +58,7 @@ files[] = tests/upgrade/update.trigger.test
files[] = tests/upgrade/update.field.test
files[] = tests/upgrade/update.user.test
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+1 -1
View File
@@ -63,7 +63,7 @@ function simpletest_requirements($phase) {
// Check the current memory limit. If it is set too low, SimpleTest will fail
// to load all tests and throw a fatal error.
$memory_limit = ini_get('memory_limit');
if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT)) {
if (!drupal_check_memory_limit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
$requirements['php_memory_limit']['severity'] = REQUIREMENT_ERROR;
$requirements['php_memory_limit']['description'] = $t('The testing framework requires the PHP memory limit to be at least %memory_minimum_limit. The current value is %memory_limit. <a href="@url">Follow these steps to continue</a>.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, '@url' => 'http://drupal.org/node/207036'));
}
+70 -42
View File
@@ -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)));
@@ -328,25 +331,32 @@ function simpletest_test_get_all() {
// Also discover PSR-0 test classes, if the PHP version allows it.
if (version_compare(PHP_VERSION, '5.3') > 0) {
// Select all PSR-0 classes in the Tests namespace of all modules.
// Select all PSR-0 and PSR-4 classes in the Tests namespace of all
// modules.
$system_list = db_query("SELECT name, filename FROM {system}")->fetchAllKeyed();
foreach ($system_list as $name => $filename) {
// Build directory in which the test files would reside.
$tests_dir = DRUPAL_ROOT . '/' . dirname($filename) . '/lib/Drupal/' . $name . '/Tests';
// Scan it for test files if it exists.
if (is_dir($tests_dir)) {
$files = file_scan_directory($tests_dir, '/.*\.php/');
if (!empty($files)) {
$basedir = DRUPAL_ROOT . '/' . dirname($filename) . '/lib/';
foreach ($files as $file) {
// Convert the file name into the namespaced class name.
$replacements = array(
'/' => '\\',
$basedir => '',
'.php' => '',
);
$classes[] = strtr($file->uri, $replacements);
$module_dir = DRUPAL_ROOT . '/' . dirname($filename);
// Search both the 'lib/Drupal/mymodule' directory (for PSR-0 classes)
// and the 'src' directory (for PSR-4 classes).
foreach(array('lib/Drupal/' . $name, 'src') as $subdir) {
// Build directory in which the test files would reside.
$tests_dir = $module_dir . '/' . $subdir . '/Tests';
// Scan it for test files if it exists.
if (is_dir($tests_dir)) {
$files = file_scan_directory($tests_dir, '/.*\.php/');
if (!empty($files)) {
foreach ($files as $file) {
// Convert the file name into the namespaced class name.
$replacements = array(
'/' => '\\',
$module_dir . '/' => '',
'lib/' => '',
'src/' => 'Drupal\\' . $name . '\\',
'.php' => '',
);
$classes[] = strtr($file->uri, $replacements);
}
}
}
}
@@ -364,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;
}
}
@@ -406,17 +419,20 @@ function simpletest_classloader_register() {
// Only register PSR-0 class loading if we are on PHP 5.3 or higher.
if (version_compare(PHP_VERSION, '5.3') > 0) {
spl_autoload_register('_simpletest_autoload_psr0');
spl_autoload_register('_simpletest_autoload_psr4_psr0');
}
}
/**
* Autoload callback to find PSR-0 test classes.
* Autoload callback to find PSR-4 and PSR-0 test classes.
*
* Looks in the 'src/Tests' and in the 'lib/Drupal/mymodule/Tests' directory of
* modules for the class.
*
* This will only work on classes where the namespace is of the pattern
* "Drupal\$extension\Tests\.."
*/
function _simpletest_autoload_psr0($class) {
function _simpletest_autoload_psr4_psr0($class) {
// Static cache for extension paths.
// This cache is lazily filled as soon as it is needed.
@@ -446,14 +462,26 @@ function _simpletest_autoload_psr0($class) {
$namespace = substr($class, 0, $nspos);
$classname = substr($class, $nspos + 1);
// Build the filepath where we expect the class to be defined.
$path = dirname($extensions[$extension]) . '/lib/' .
str_replace('\\', '/', $namespace) . '/' .
// Try the PSR-4 location first, and the PSR-0 location as a fallback.
// Build the PSR-4 filepath where we expect the class to be defined.
$psr4_path = dirname($extensions[$extension]) . '/src/' .
str_replace('\\', '/', substr($namespace, strlen('Drupal\\' . $extension . '\\'))) . '/' .
str_replace('_', '/', $classname) . '.php';
// Include the file, if it does exist.
if (file_exists($path)) {
include $path;
if (file_exists($psr4_path)) {
include $psr4_path;
}
else {
// Build the PSR-0 filepath where we expect the class to be defined.
$psr0_path = dirname($extensions[$extension]) . '/lib/' .
str_replace('\\', '/', $namespace) . '/' .
str_replace('_', '/', $classname) . '.php';
// Include the file, if it does exist.
if (file_exists($psr0_path)) {
include $psr0_path;
}
}
}
}
@@ -487,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);
+56 -1
View File
@@ -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 {
@@ -703,7 +751,9 @@ class SimpleTestDiscoveryTestCase extends DrupalWebTestCase {
$classes_all = simpletest_test_get_all();
foreach (array(
'Drupal\\simpletest\\Tests\\PSR0WebTest',
'Drupal\\simpletest\\Tests\\PSR4WebTest',
'Drupal\\psr_0_test\\Tests\\ExampleTest',
'Drupal\\psr_4_test\\Tests\\ExampleTest',
) as $class) {
$this->assert(!empty($classes_all['SimpleTest'][$class]), t('Class @class must be discovered by simpletest_test_get_all().', array('@class' => $class)));
}
@@ -726,15 +776,20 @@ class SimpleTestDiscoveryTestCase extends DrupalWebTestCase {
// Don't expect PSR-0 tests to be discovered on older PHP versions.
return;
}
// This one is provided by simpletest itself via PSR-0.
// These are provided by simpletest itself via PSR-0 and PSR-4.
$this->assertText('PSR0 web test');
$this->assertText('PSR4 web test');
$this->assertText('PSR0 example test: PSR-0 in disabled modules.');
$this->assertText('PSR4 example test: PSR-4 in disabled modules.');
$this->assertText('PSR0 example test: PSR-0 in nested subfolders.');
$this->assertText('PSR4 example test: PSR-4 in nested subfolders.');
// Test each test individually.
foreach (array(
'Drupal\\psr_0_test\\Tests\\ExampleTest',
'Drupal\\psr_0_test\\Tests\\Nested\\NestedExampleTest',
'Drupal\\psr_4_test\\Tests\\ExampleTest',
'Drupal\\psr_4_test\\Tests\\Nested\\NestedExampleTest',
) as $class) {
$this->drupalGet('admin/config/development/testing');
$edit = array($class => TRUE);
@@ -0,0 +1,18 @@
<?php
namespace Drupal\simpletest\Tests;
class PSR4WebTest extends \DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'PSR4 web test',
'description' => 'We want to assert that this PSR-4 test case is being discovered.',
'group' => 'SimpleTest',
);
}
function testArithmetics() {
$this->assert(1 + 1 == 2, '1 + 1 == 2');
}
}
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+90 -3
View File
@@ -293,7 +293,7 @@ class AJAXCommandsTestCase extends AJAXTestCase {
$this->assertCommand($commands, $expected, "'changed' AJAX command (with asterisk) issued with correct selector");
// Tests the 'css' command.
$commands = $this->drupalPostAJAX($form_path, $edit, array('op' => t("Set the the '#box' div to be blue.")));
$commands = $this->drupalPostAJAX($form_path, $edit, array('op' => t("Set the '#box' div to be blue.")));
$expected = array(
'command' => 'css',
'selector' => '#css_div',
@@ -368,6 +368,14 @@ class AJAXCommandsTestCase extends AJAXTestCase {
'settings' => array('ajax_forms_test' => array('foo' => 42)),
);
$this->assertCommand($commands, $expected, "'settings' AJAX command issued with correct data");
// Tests the 'add_css' command.
$commands = $this->drupalPostAJAX($form_path, $edit, array('op' => t("AJAX 'add_css' command")));
$expected = array(
'command' => 'add_css',
'data' => 'my/file.css',
);
$this->assertCommand($commands, $expected, "'add_css' AJAX command issued with correct data");
}
}
@@ -497,6 +505,85 @@ class AJAXMultiFormTestCase extends AJAXTestCase {
}
}
/**
* Test Ajax forms when page caching for anonymous users is turned on.
*/
class AJAXFormPageCacheTestCase extends AJAXTestCase {
protected $profile = 'testing';
public static function getInfo() {
return array(
'name' => 'AJAX forms on cached pages',
'description' => 'Tests that AJAX forms work properly for anonymous users on cached pages.',
'group' => 'AJAX',
);
}
public function setUp() {
parent::setUp();
variable_set('cache', TRUE);
}
/**
* Return the build id of the current form.
*/
protected function getFormBuildId() {
$build_id_fields = $this->xpath('//input[@name="form_build_id"]');
$this->assertEqual(count($build_id_fields), 1, 'One form build id field on the page');
return (string) $build_id_fields[0]['value'];
}
/**
* Create a simple form, then POST to system/ajax to change to it.
*/
public function testSimpleAJAXFormValue() {
$this->drupalGet('ajax_forms_test_get_form');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
$build_id_initial = $this->getFormBuildId();
$edit = array('select' => 'green');
$commands = $this->drupalPostAJAX(NULL, $edit, 'select');
$build_id_first_ajax = $this->getFormBuildId();
$this->assertNotEqual($build_id_initial, $build_id_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission');
$expected = array(
'command' => 'updateBuildId',
'old' => $build_id_initial,
'new' => $build_id_first_ajax,
);
$this->assertCommand($commands, $expected, 'Build id change command issued on first AJAX submission');
$edit = array('select' => 'red');
$commands = $this->drupalPostAJAX(NULL, $edit, 'select');
$build_id_second_ajax = $this->getFormBuildId();
$this->assertEqual($build_id_first_ajax, $build_id_second_ajax, 'Build id remains the same on subsequent AJAX submissions');
// Repeat the test sequence but this time with a page loaded from the cache.
$this->drupalGet('ajax_forms_test_get_form');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$build_id_from_cache_initial = $this->getFormBuildId();
$this->assertEqual($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request');
$edit = array('select' => 'green');
$commands = $this->drupalPostAJAX(NULL, $edit, 'select');
$build_id_from_cache_first_ajax = $this->getFormBuildId();
$this->assertNotEqual($build_id_from_cache_initial, $build_id_from_cache_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission');
$this->assertNotEqual($build_id_first_ajax, $build_id_from_cache_first_ajax, 'Build id from first user is not reused');
$expected = array(
'command' => 'updateBuildId',
'old' => $build_id_from_cache_initial,
'new' => $build_id_from_cache_first_ajax,
);
$this->assertCommand($commands, $expected, 'Build id change command issued on first AJAX submission');
$edit = array('select' => 'red');
$commands = $this->drupalPostAJAX(NULL, $edit, 'select');
$build_id_from_cache_second_ajax = $this->getFormBuildId();
$this->assertEqual($build_id_from_cache_first_ajax, $build_id_from_cache_second_ajax, 'Build id remains the same on subsequent AJAX submissions');
}
}
/**
* Miscellaneous Ajax tests using ajax_test module.
*/
@@ -524,7 +611,7 @@ class AJAXElementValidation extends AJAXTestCase {
// Post with 'drivertext' as the triggering element.
$post_result = $this->drupalPostAJAX('ajax_validation_test', $edit, 'drivertext');
// Look for a validation failure in the resultant JSON.
$this->assertNoText(t('Error message'), t("No error message in resultant JSON"));
$this->assertText('ajax_forms_test_validation_form_callback invoked', t('The correct callback was invoked'));
$this->assertNoText(t('Error message'), "No error message in resultant JSON");
$this->assertText('ajax_forms_test_validation_form_callback invoked', 'The correct callback was invoked');
}
}
@@ -5,8 +5,7 @@ package = Testing
version = VERSION
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -157,7 +157,7 @@ function ajax_forms_test_ajax_commands_form($form, &$form_state) {
// Shows the Ajax 'css' command.
$form['css_command_example'] = array(
'#value' => t("Set the the '#box' div to be blue."),
'#value' => t("Set the '#box' div to be blue."),
'#type' => 'submit',
'#ajax' => array(
'callback' => 'ajax_forms_test_advanced_commands_css_callback',
@@ -254,6 +254,15 @@ function ajax_forms_test_ajax_commands_form($form, &$form_state) {
),
);
// Shows the Ajax 'add_css' command.
$form['add_css_command_example'] = array(
'#type' => 'submit',
'#value' => t("AJAX 'add_css' command"),
'#ajax' => array(
'callback' => 'ajax_forms_test_advanced_commands_add_css_callback',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
@@ -406,6 +415,15 @@ function ajax_forms_test_advanced_commands_settings_callback($form, $form_state)
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* Ajax callback for 'add_css'.
*/
function ajax_forms_test_advanced_commands_add_css_callback($form, $form_state) {
$commands = array();
$commands[] = ajax_command_add_css('my/file.css');
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* This form and its related submit and callback functions demonstrate
* not validating another form element when a single Ajax element is triggered.
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -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) {
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+38
View File
@@ -0,0 +1,38 @@
<?php
/**
* Perform early bootstrap tests.
*/
class EarlyBootstrapTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Early bootstrap test',
'description' => 'Confirm that calling module_implements() during early bootstrap does not pollute the module_implements() cache.',
'group' => 'System',
);
}
function setUp() {
parent::setUp('boot_test_1', 'boot_test_2');
}
/**
* Test hook_boot() on both regular and "early exit" pages.
*/
public function testHookBoot() {
$paths = array('', 'early_exit');
foreach ($paths as $path) {
// Empty the module_implements() caches.
module_implements(NULL, FALSE, TRUE);
// Do a request to the front page, which will call module_implements()
// during hook_boot().
$this->drupalGet($path);
// Reset the static cache so we get implementation data from the persistent
// cache.
drupal_static_reset();
// Make sure we get a full list of all modules implementing hook_help().
$modules = module_implements('help');
$this->assertTrue(in_array('boot_test_2', $modules));
}
}
}
+11
View File
@@ -0,0 +1,11 @@
name = Early bootstrap tests
description = A support module for hook_boot testing.
core = 7.x
package = Testing
version = VERSION
hidden = TRUE
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1600272641"
@@ -0,0 +1,21 @@
<?php
/**
* @file
* Tests calling module_implements() during hook_boot() invocation.
*/
/**
* Implements hook_boot().
*/
function boot_test_1_boot() {
// Calling module_implements during hook_boot() will return "vital" modules
// only, and this list of modules will be statically cached.
module_implements('help');
// Define a special path to test that the static cache isn't written away
// if we exit before having completed the bootstrap.
if ($_GET['q'] == 'early_exit') {
module_implements_write_cache();
exit();
}
}
+11
View File
@@ -0,0 +1,11 @@
name = Early bootstrap tests
description = A support module for hook_boot hook testing.
core = 7.x
package = Testing
version = VERSION
hidden = TRUE
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1600272641"
@@ -0,0 +1,13 @@
<?php
/**
* @file
* Defines a hook_help() implementation in a non-"bootstrap" module.
*/
/**
* Implements hook_help().
*/
function boot_test_2_help($path, $arg) {
// Empty hook.
}
+431 -66
View File
@@ -42,14 +42,14 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
// Test the normal IP address.
$this->assertTrue(
ip_address() == $this->remote_ip,
t('Got remote IP address.')
'Got remote IP address.'
);
// Proxy forwarding on but no proxy addresses defined.
variable_set('reverse_proxy', 1);
$this->assertTrue(
ip_address() == $this->remote_ip,
t('Proxy forwarding without trusted proxies got remote IP address.')
'Proxy forwarding without trusted proxies got remote IP address.'
);
// Proxy forwarding on and proxy address not trusted.
@@ -58,7 +58,7 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
$_SERVER['REMOTE_ADDR'] = $this->untrusted_ip;
$this->assertTrue(
ip_address() == $this->untrusted_ip,
t('Proxy forwarding with untrusted proxy got remote IP address.')
'Proxy forwarding with untrusted proxy got remote IP address.'
);
// Proxy forwarding on and proxy address trusted.
@@ -67,7 +67,16 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
drupal_static_reset('ip_address');
$this->assertTrue(
ip_address() == $this->forwarded_ip,
t('Proxy forwarding with trusted proxy got forwarded IP address.')
'Proxy forwarding with trusted proxy got forwarded IP address.'
);
// Proxy forwarding on and proxy address trusted and visiting from proxy.
$_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
$_SERVER['HTTP_X_FORWARDED_FOR'] = $this->proxy_ip;
drupal_static_reset('ip_address');
$this->assertTrue(
ip_address() == $this->proxy_ip,
'Visiting from trusted proxy got proxy IP address.'
);
// Multi-tier architecture with comma separated values in header.
@@ -76,7 +85,7 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
drupal_static_reset('ip_address');
$this->assertTrue(
ip_address() == $this->forwarded_ip,
t('Proxy forwarding with trusted 2-tier proxy got forwarded IP address.')
'Proxy forwarding with trusted 2-tier proxy got forwarded IP address.'
);
// Custom client-IP header.
@@ -85,16 +94,21 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
drupal_static_reset('ip_address');
$this->assertTrue(
ip_address() == $this->cluster_ip,
t('Cluster environment got cluster client IP.')
'Cluster environment got cluster client IP.'
);
// Verifies that drupal_valid_http_host() prevents invalid characters.
$this->assertFalse(drupal_valid_http_host('security/.drupal.org:80'), t('HTTP_HOST with / is invalid'));
$this->assertFalse(drupal_valid_http_host('security\\.drupal.org:80'), t('HTTP_HOST with \\ is invalid'));
$this->assertFalse(drupal_valid_http_host('security<.drupal.org:80'), t('HTTP_HOST with &lt; is invalid'));
$this->assertFalse(drupal_valid_http_host('security..drupal.org:80'), t('HTTP_HOST with .. is invalid'));
$this->assertFalse(drupal_valid_http_host('security/.drupal.org:80'), 'HTTP_HOST with / is invalid');
$this->assertFalse(drupal_valid_http_host('security\\.drupal.org:80'), 'HTTP_HOST with \\ is invalid');
$this->assertFalse(drupal_valid_http_host('security<.drupal.org:80'), 'HTTP_HOST with &lt; is invalid');
$this->assertFalse(drupal_valid_http_host('security..drupal.org:80'), 'HTTP_HOST with .. is invalid');
// Verifies that host names are shorter than 1000 characters.
$this->assertFalse(drupal_valid_http_host(str_repeat('x', 1001)), 'HTTP_HOST with more than 1000 characters is invalid.');
$this->assertFalse(drupal_valid_http_host(str_repeat('.', 101)), 'HTTP_HOST with more than 100 subdomains is invalid.');
$this->assertFalse(drupal_valid_http_host(str_repeat(':', 101)), 'HTTP_HOST with more than 100 portseparators is invalid.');
// IPv6 loopback address
$this->assertTrue(drupal_valid_http_host('[::1]:80'), t('HTTP_HOST containing IPv6 loopback is valid'));
$this->assertTrue(drupal_valid_http_host('[::1]:80'), 'HTTP_HOST containing IPv6 loopback is valid');
}
}
@@ -122,32 +136,34 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
$this->drupalGet('');
$this->drupalHead('');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$etag = $this->drupalGetHeader('ETag');
$last_modified = $this->drupalGetHeader('Last-Modified');
$this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag));
$this->assertResponse(304, t('Conditional request returned 304 Not Modified.'));
$this->assertResponse(304, 'Conditional request returned 304 Not Modified.');
$this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC822, strtotime($last_modified)), 'If-None-Match: ' . $etag));
$this->assertResponse(304, t('Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'));
$this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.');
$this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC850, strtotime($last_modified)), 'If-None-Match: ' . $etag));
$this->assertResponse(304, t('Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'));
$this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.');
$this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified));
$this->assertResponse(200, t('Conditional request without If-None-Match returned 200 OK.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this->assertResponse(200, 'Conditional request without If-None-Match returned 200 OK.');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC1123, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag));
$this->assertResponse(200, t('Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC7231, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag));
$this->assertResponse(200, 'Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$user = $this->drupalCreateUser();
$this->drupalLogin($user);
$this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag));
$this->assertResponse(200, t('Conditional request returned 200 OK for authenticated user.'));
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Absense of Page was not cached.'));
$this->assertResponse(200, 'Conditional request returned 200 OK for authenticated user.');
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Absence of Page was not cached.');
$this->assertFalse($this->drupalGetHeader('ETag'), 'ETag HTTP headers are not present for logged in users.');
$this->assertFalse($this->drupalGetHeader('Last-Modified'), 'Last-Modified HTTP headers are not present for logged in users.');
}
/**
@@ -158,35 +174,35 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
// Fill the cache.
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar')));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.'));
$this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', t('Vary header was sent.'));
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', t('Cache-Control header was sent.'));
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.'));
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
$this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', 'Vary header was sent.');
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', 'Cache-Control header was sent.');
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.');
// Check cache.
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar')));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', t('Vary: Cookie header was sent.'));
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', t('Cache-Control header was sent.'));
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.'));
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', 'Vary: Cookie header was sent.');
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', 'Cache-Control header was sent.');
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.');
// Check replacing default headers.
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Expires', 'value' => 'Fri, 19 Nov 2008 05:00:00 GMT')));
$this->assertEqual($this->drupalGetHeader('Expires'), 'Fri, 19 Nov 2008 05:00:00 GMT', t('Default header was replaced.'));
$this->assertEqual($this->drupalGetHeader('Expires'), 'Fri, 19 Nov 2008 05:00:00 GMT', 'Default header was replaced.');
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Vary', 'value' => 'User-Agent')));
$this->assertEqual($this->drupalGetHeader('Vary'), 'User-Agent,Accept-Encoding', t('Default header was replaced.'));
$this->assertEqual($this->drupalGetHeader('Vary'), 'User-Agent,Accept-Encoding', 'Default header was replaced.');
// Check that authenticated users bypass the cache.
$user = $this->drupalCreateUser();
$this->drupalLogin($user);
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar')));
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Caching was bypassed.'));
$this->assertTrue(strpos($this->drupalGetHeader('Vary'), 'Cookie') === FALSE, t('Vary: Cookie header was not sent.'));
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', t('Cache-Control header was sent.'));
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.'));
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.'));
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Caching was bypassed.');
$this->assertTrue(strpos($this->drupalGetHeader('Vary'), 'Cookie') === FALSE, 'Vary: Cookie header was not sent.');
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate', 'Cache-Control header was sent.');
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.');
}
@@ -202,23 +218,35 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
// Fill the cache and verify that output is compressed.
$this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
$this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8)));
$this->assertRaw('</html>', t('Page was gzip compressed.'));
$this->assertRaw('</html>', 'Page was gzip compressed.');
// Verify that cached output is compressed.
$this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this->assertEqual($this->drupalGetHeader('Content-Encoding'), 'gzip', t('A Content-Encoding header was sent.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$this->assertEqual($this->drupalGetHeader('Content-Encoding'), 'gzip', 'A Content-Encoding header was sent.');
$this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8)));
$this->assertRaw('</html>', t('Page was gzip compressed.'));
$this->assertRaw('</html>', 'Page was gzip compressed.');
// Verify that a client without compression support gets an uncompressed page.
$this->drupalGet('');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this->assertFalse($this->drupalGetHeader('Content-Encoding'), t('A Content-Encoding header was not sent.'));
$this->assertTitle(t('Welcome to @site-name | @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), t('Site title matches.'));
$this->assertRaw('</html>', t('Page was not compressed.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$this->assertFalse($this->drupalGetHeader('Content-Encoding'), 'A Content-Encoding header was not sent.');
$this->assertTitle(t('Welcome to @site-name | @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), 'Site title matches.');
$this->assertRaw('</html>', 'Page was not compressed.');
// Disable compression mode.
variable_set('page_compression', FALSE);
// Verify if cached page is still available for a client with compression support.
$this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate'));
$this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8)));
$this->assertRaw('</html>', 'Page was delivered after compression mode is changed (compression support enabled).');
// Verify if cached page is still available for a client without compression support.
$this->drupalGet('');
$this->assertRaw('</html>', 'Page was delivered after compression mode is changed (compression support disabled).');
}
}
@@ -243,17 +271,17 @@ class BootstrapVariableTestCase extends DrupalWebTestCase {
// Setting and retrieving values.
$variable = $this->randomName();
variable_set('simpletest_bootstrap_variable_test', $variable);
$this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test'), t('Setting and retrieving values'));
$this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test'), 'Setting and retrieving values');
// Make sure the variable persists across multiple requests.
$this->drupalGet('system-test/variable-get');
$this->assertText($variable, t('Variable persists across multiple requests'));
$this->assertText($variable, 'Variable persists across multiple requests');
// Deleting variables.
$default_value = $this->randomName();
variable_del('simpletest_bootstrap_variable_test');
$variable = variable_get('simpletest_bootstrap_variable_test', $default_value);
$this->assertIdentical($variable, $default_value, t('Deleting variables'));
$this->assertIdentical($variable, $default_value, 'Deleting variables');
}
/**
@@ -261,10 +289,43 @@ class BootstrapVariableTestCase extends DrupalWebTestCase {
*/
function testVariableDefaults() {
// Tests passing nothing through to the default.
$this->assertIdentical(NULL, variable_get('simpletest_bootstrap_variable_test'), t('Variables are correctly defaulting to NULL.'));
$this->assertIdentical(NULL, variable_get('simpletest_bootstrap_variable_test'), 'Variables are correctly defaulting to NULL.');
// Tests passing 5 to the default parameter.
$this->assertIdentical(5, variable_get('simpletest_bootstrap_variable_test', 5), t('The default variable parameter is passed through correctly.'));
$this->assertIdentical(5, variable_get('simpletest_bootstrap_variable_test', 5), 'The default variable parameter is passed through correctly.');
}
}
/**
* Tests the auto-loading behavior of the code registry.
*/
class BootstrapAutoloadTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Code registry',
'description' => 'Test that the code registry functions correctly.',
'group' => 'Bootstrap',
);
}
function setUp() {
parent::setUp('drupal_autoload_test');
}
/**
* Tests that autoloader name matching is not case sensitive.
*/
function testAutoloadCase() {
// Test interface autoloader.
$this->assertTrue(drupal_autoload_interface('drupalautoloadtestinterface'), 'drupal_autoload_interface() recognizes <em>DrupalAutoloadTestInterface</em> in lower case.');
// Test class autoloader.
$this->assertTrue(drupal_autoload_class('drupalautoloadtestclass'), 'drupal_autoload_class() recognizes <em>DrupalAutoloadTestClass</em> in lower case.');
// Test trait autoloader.
if (version_compare(PHP_VERSION, '5.4') >= 0) {
$this->assertTrue(drupal_autoload_trait('drupalautoloadtesttrait'), 'drupal_autoload_trait() recognizes <em>DrupalAutoloadTestTrait</em> in lower case.');
}
}
}
@@ -327,12 +388,19 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Get filename test',
'description' => 'Test that drupal_get_filename() works correctly when the file is not found in the database.',
'name' => 'Get filename test (without the system table)',
'description' => 'Test that drupal_get_filename() works correctly when the database is not available.',
'group' => 'Bootstrap',
);
}
/**
* The last file-related error message triggered by the filename test.
*
* Used by BootstrapGetFilenameTestCase::testDrupalGetFilename().
*/
protected $getFilenameTestTriggeredError;
/**
* Test that drupal_get_filename() works correctly when the file is not found in the database.
*/
@@ -362,6 +430,203 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase {
// automatically check there for 'script' files, just as it does for (e.g.)
// 'module' files in modules.
$this->assertIdentical(drupal_get_filename('script', 'test'), 'scripts/test.script', t('Retrieve test script location.'));
// When searching for a module that does not exist, drupal_get_filename()
// should return NULL and trigger an appropriate error message.
$this->getFilenameTestTriggeredError = NULL;
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
$non_existing_module = $this->randomName();
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL.');
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for an item that does not exist triggers the correct error.');
restore_error_handler();
// Check that the result is stored in the file system scan cache.
$file_scans = _drupal_file_scan_cache();
$this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files static variable.');
// Performing the search again in the same request still should not find
// the file, but the error message should not be repeated (therefore we do
// not override the error handler here).
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL during the second search.');
}
/**
* Skips handling of "file not found" errors.
*/
public function fileNotFoundErrorHandler($error_level, $message, $filename, $line, $context) {
// Skip error handling if this is a "file not found" error.
if (strpos($message, 'is missing from the file system:') !== FALSE || strpos($message, 'has moved within the file system:') !== FALSE) {
$this->getFilenameTestTriggeredError = $message;
return;
}
_drupal_error_handler($error_level, $message, $filename, $line, $context);
}
}
/**
* Test drupal_get_filename() in the context of a full Drupal installation.
*/
class BootstrapGetFilenameWebTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Get filename test (full installation)',
'description' => 'Test that drupal_get_filename() works correctly in the context of a full Drupal installation.',
'group' => 'Bootstrap',
);
}
function setUp() {
parent::setUp('system_test');
}
/**
* The last file-related error message triggered by the filename test.
*
* Used by BootstrapGetFilenameWebTestCase::testDrupalGetFilename().
*/
protected $getFilenameTestTriggeredError;
/**
* Test that drupal_get_filename() works correctly with a full Drupal site.
*/
function testDrupalGetFilename() {
// Search for a module that exists in the file system and the {system}
// table and make sure that it is found.
$this->assertIdentical(drupal_get_filename('module', 'node'), 'modules/node/node.module', 'Module found at expected location.');
// Search for a module that does not exist in either the file system or the
// {system} table. Make sure that an appropriate error is triggered and
// that the module winds up in the static and persistent cache.
$this->getFilenameTestTriggeredError = NULL;
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
$non_existing_module = $this->randomName();
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that does not exist returns NULL.');
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for a module that does not exist triggers the correct error.');
restore_error_handler();
$file_scans = _drupal_file_scan_cache();
$this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files static variable.');
drupal_file_scan_write_cache();
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
$this->assertIdentical($cache->data['module'][$non_existing_module], FALSE, 'Searching for a module that does not exist creates a record in the missing and moved files persistent cache.');
// Simulate moving a module to a location that does not match the location
// in the {system} table and perform similar tests as above.
db_update('system')
->fields(array('filename' => 'modules/simpletest/tests/fake_location/module_test.module'))
->condition('name', 'module_test')
->condition('type', 'module')
->execute();
$this->getFilenameTestTriggeredError = NULL;
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
$this->assertIdentical(drupal_get_filename('module', 'module_test'), 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved finds the module at its new location.');
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module has moved within the file system: %name', array('%name' => 'module_test'))) === 0, 'Searching for a module that has moved triggers the correct error.');
restore_error_handler();
$file_scans = _drupal_file_scan_cache();
$this->assertIdentical($file_scans['module']['module_test'], 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved creates a record in the missing and moved files static variable.');
drupal_file_scan_write_cache();
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
$this->assertIdentical($cache->data['module']['module_test'], 'modules/simpletest/tests/module_test.module', 'Searching for a module that has moved creates a record in the missing and moved files persistent cache.');
// Simulate a module that exists in the {system} table but does not exist
// in the file system and perform similar tests as above.
$non_existing_module = $this->randomName();
db_update('system')
->fields(array('name' => $non_existing_module))
->condition('name', 'module_test')
->condition('type', 'module')
->execute();
$this->getFilenameTestTriggeredError = NULL;
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
$this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for a module that exists in the system table but not in the file system returns NULL.');
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) === 0, 'Searching for a module that exists in the system table but not in the file system triggers the correct error.');
restore_error_handler();
$file_scans = _drupal_file_scan_cache();
$this->assertIdentical($file_scans['module'][$non_existing_module], FALSE, 'Searching for a module that exists in the system table but not in the file system creates a record in the missing and moved files static variable.');
drupal_file_scan_write_cache();
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
$this->assertIdentical($cache->data['module'][$non_existing_module], FALSE, 'Searching for a module that exists in the system table but not in the file system creates a record in the missing and moved files persistent cache.');
// Simulate a module that exists in the file system but not in the {system}
// table and perform similar tests as above.
db_delete('system')
->condition('name', 'common_test')
->condition('type', 'module')
->execute();
system_list_reset();
$this->getFilenameTestTriggeredError = NULL;
set_error_handler(array($this, 'fileNotFoundErrorHandler'));
$this->assertIdentical(drupal_get_filename('module', 'common_test'), 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table finds the module at its actual location.');
$this->assertTrue(strpos($this->getFilenameTestTriggeredError, format_string('The following module has moved within the file system: %name', array('%name' => 'common_test'))) === 0, 'Searching for a module that does not exist in the system table triggers the correct error.');
restore_error_handler();
$file_scans = _drupal_file_scan_cache();
$this->assertIdentical($file_scans['module']['common_test'], 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table creates a record in the missing and moved files static variable.');
drupal_file_scan_write_cache();
$cache = cache_get('_drupal_file_scan_cache', 'cache_bootstrap');
$this->assertIdentical($cache->data['module']['common_test'], 'modules/simpletest/tests/common_test.module', 'Searching for a module that does not exist in the system table creates a record in the missing and moved files persistent cache.');
}
/**
* Skips handling of "file not found" errors.
*/
public function fileNotFoundErrorHandler($error_level, $message, $filename, $line, $context) {
// Skip error handling if this is a "file not found" error.
if (strpos($message, 'is missing from the file system:') !== FALSE || strpos($message, 'has moved within the file system:') !== FALSE) {
$this->getFilenameTestTriggeredError = $message;
return;
}
_drupal_error_handler($error_level, $message, $filename, $line, $context);
}
/**
* Test that watchdog messages about missing files are correctly recorded.
*/
public function testWatchdog() {
// Search for a module that does not exist in either the file system or the
// {system} table. Make sure that an appropriate warning is recorded in the
// logs.
$non_existing_module = $this->randomName();
$query_parameters = array(
':type' => 'php',
':severity' => WATCHDOG_WARNING,
);
$this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND severity = :severity', $query_parameters)->fetchField(), 0, 'No warning message appears in the logs before searching for a module that does not exist.');
// Trigger the drupal_get_filename() call. This must be done via a request
// to a separate URL since the watchdog() will happen in a shutdown
// function, and so that SimpleTest can be told to ignore (and not fail as
// a result of) the expected PHP warnings generated during this process.
variable_set('system_test_drupal_get_filename_test_module_name', $non_existing_module);
$this->drupalGet('system-test/drupal-get-filename');
$message_variables = db_query('SELECT variables FROM {watchdog} WHERE type = :type AND severity = :severity', $query_parameters)->fetchCol();
$this->assertEqual(count($message_variables), 1, 'A single warning message appears in the logs after searching for a module that does not exist.');
$variables = reset($message_variables);
$variables = unserialize($variables);
$this->assertTrue(isset($variables['!message']) && strpos($variables['!message'], format_string('The following module is missing from the file system: %name', array('%name' => $non_existing_module))) !== FALSE, 'The warning message that appears in the logs after searching for a module that does not exist contains the expected text.');
}
/**
* Test that drupal_get_filename() does not break recursive rebuilds.
*/
public function testRecursiveRebuilds() {
// Ensure that the drupal_get_filename() call due to a missing module does
// not break the data returned by an attempted recursive rebuild. The code
// path which is tested is as follows:
// - Call drupal_get_schema().
// - Within a hook_schema() implementation, trigger a drupal_get_filename()
// search for a nonexistent module.
// - In the watchdog() call that results from that, trigger
// drupal_get_schema() again.
// Without some kind of recursion protection, this could cause the second
// drupal_get_schema() call to return incomplete results. This test ensures
// that does not happen.
$non_existing_module = $this->randomName();
variable_set('system_test_drupal_get_filename_test_module_name', $non_existing_module);
$this->drupalGet('system-test/drupal-get-filename-with-schema-rebuild');
$original_drupal_get_schema_tables = variable_get('system_test_drupal_get_filename_with_schema_rebuild_original_tables');
$final_drupal_get_schema_tables = variable_get('system_test_drupal_get_filename_with_schema_rebuild_final_tables');
$this->assertTrue(!empty($original_drupal_get_schema_tables));
$this->assertTrue(!empty($final_drupal_get_schema_tables));
$this->assertEqual($original_drupal_get_schema_tables, $final_drupal_get_schema_tables);
}
}
@@ -383,17 +648,17 @@ class BootstrapTimerTestCase extends DrupalUnitTestCase {
function testTimer() {
timer_start('test');
sleep(1);
$this->assertTrue(timer_read('test') >= 1000, t('Timer measured 1 second of sleeping while running.'));
$this->assertTrue(timer_read('test') >= 1000, 'Timer measured 1 second of sleeping while running.');
sleep(1);
timer_stop('test');
$this->assertTrue(timer_read('test') >= 2000, t('Timer measured 2 seconds of sleeping after being stopped.'));
$this->assertTrue(timer_read('test') >= 2000, 'Timer measured 2 seconds of sleeping after being stopped.');
timer_start('test');
sleep(1);
$this->assertTrue(timer_read('test') >= 3000, t('Timer measured 3 seconds of sleeping after being restarted.'));
$this->assertTrue(timer_read('test') >= 3000, 'Timer measured 3 seconds of sleeping after being restarted.');
sleep(1);
$timer = timer_stop('test');
$this->assertTrue(timer_read('test') >= 4000, t('Timer measured 4 seconds of sleeping after being stopped for a second time.'));
$this->assertEqual($timer['count'], 2, t('Timer counted 2 instances of being started.'));
$this->assertTrue(timer_read('test') >= 4000, 'Timer measured 4 seconds of sleeping after being stopped for a second time.');
$this->assertEqual($timer['count'], 2, 'Timer counted 2 instances of being started.');
}
}
@@ -417,22 +682,22 @@ class BootstrapResettableStaticTestCase extends DrupalUnitTestCase {
function testDrupalStatic() {
$name = __CLASS__ . '_' . __METHOD__;
$var = &drupal_static($name, 'foo');
$this->assertEqual($var, 'foo', t('Variable returned by drupal_static() was set to its default.'));
$this->assertEqual($var, 'foo', 'Variable returned by drupal_static() was set to its default.');
// Call the specific reset and the global reset each twice to ensure that
// multiple resets can be issued without odd side effects.
$var = 'bar';
drupal_static_reset($name);
$this->assertEqual($var, 'foo', t('Variable was reset after first invocation of name-specific reset.'));
$this->assertEqual($var, 'foo', 'Variable was reset after first invocation of name-specific reset.');
$var = 'bar';
drupal_static_reset($name);
$this->assertEqual($var, 'foo', t('Variable was reset after second invocation of name-specific reset.'));
$this->assertEqual($var, 'foo', 'Variable was reset after second invocation of name-specific reset.');
$var = 'bar';
drupal_static_reset();
$this->assertEqual($var, 'foo', t('Variable was reset after first invocation of global reset.'));
$this->assertEqual($var, 'foo', 'Variable was reset after first invocation of global reset.');
$var = 'bar';
drupal_static_reset();
$this->assertEqual($var, 'foo', t('Variable was reset after second invocation of global reset.'));
$this->assertEqual($var, 'foo', 'Variable was reset after second invocation of global reset.');
}
}
@@ -457,7 +722,26 @@ class BootstrapMiscTestCase extends DrupalUnitTestCase {
$link_options_1 = array('fragment' => 'x', 'attributes' => array('title' => 'X', 'class' => array('a', 'b')), 'language' => 'en');
$link_options_2 = array('fragment' => 'y', 'attributes' => array('title' => 'Y', 'class' => array('c', 'd')), 'html' => TRUE);
$expected = array('fragment' => 'y', 'attributes' => array('title' => 'Y', 'class' => array('a', 'b', 'c', 'd')), 'language' => 'en', 'html' => TRUE);
$this->assertIdentical(drupal_array_merge_deep($link_options_1, $link_options_2), $expected, t('drupal_array_merge_deep() returned a properly merged array.'));
$this->assertIdentical(drupal_array_merge_deep($link_options_1, $link_options_2), $expected, 'drupal_array_merge_deep() returned a properly merged array.');
}
/**
* Tests that the drupal_check_memory_limit() function works as expected.
*/
function testCheckMemoryLimit() {
// Test that a very reasonable amount of memory is available.
$this->assertTrue(drupal_check_memory_limit('30MB'), '30MB of memory tested available.');
// Test an unlimited memory limit.
// The function should always return true if the memory limit is set to -1.
$this->assertTrue(drupal_check_memory_limit('9999999999YB', -1), 'drupal_check_memory_limit() returns TRUE when a limit of -1 (none) is supplied');
// Test that even though we have 30MB of memory available - the function
// returns FALSE when given an upper limit for how much memory can be used.
$this->assertFalse(drupal_check_memory_limit('30MB', '16MB'), 'drupal_check_memory_limit() returns FALSE with a 16MB upper limit on a 30MB requirement.');
// Test that an equal amount of memory to the amount requested returns TRUE.
$this->assertTrue(drupal_check_memory_limit('30MB', '30MB'), 'drupal_check_memory_limit() returns TRUE when requesting 30MB on a 30MB requirement.');
}
}
@@ -507,3 +791,84 @@ class BootstrapOverrideServerVariablesTestCase extends DrupalUnitTestCase {
}
}
/**
* Tests for $_GET['destination'] and $_REQUEST['destination'] validation.
*/
class BootstrapDestinationTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'URL destination validation',
'description' => 'Test that $_GET[\'destination\'] and $_REQUEST[\'destination\'] cannot contain external URLs.',
'group' => 'Bootstrap',
);
}
function setUp() {
parent::setUp('system_test');
}
/**
* Tests that $_GET/$_REQUEST['destination'] only contain internal URLs.
*
* @see _drupal_bootstrap_variables()
* @see system_test_get_destination()
* @see system_test_request_destination()
*/
public function testDestination() {
$test_cases = array(
array(
'input' => 'node',
'output' => 'node',
'message' => "Standard internal example node path is present in the 'destination' parameter.",
),
array(
'input' => '/example.com',
'output' => '/example.com',
'message' => 'Internal path with one leading slash is allowed.',
),
array(
'input' => '//example.com/test',
'output' => '',
'message' => 'External URL without scheme is not allowed.',
),
array(
'input' => 'example:test',
'output' => 'example:test',
'message' => 'Internal URL using a colon is allowed.',
),
array(
'input' => 'http://example.com',
'output' => '',
'message' => 'External URL is not allowed.',
),
array(
'input' => 'javascript:alert(0)',
'output' => 'javascript:alert(0)',
'message' => 'Javascript URL is allowed because it is treated as an internal URL.',
),
);
foreach ($test_cases as $test_case) {
// Test $_GET['destination'].
$this->drupalGet('system-test/get-destination', array('query' => array('destination' => $test_case['input'])));
$this->assertIdentical($test_case['output'], $this->drupalGetContent(), $test_case['message']);
// Test $_REQUEST['destination']. There's no form to submit to, so
// drupalPost() won't work here; this just tests a direct $_POST request
// instead.
$curl_parameters = array(
CURLOPT_URL => $this->getAbsoluteUrl('system-test/request-destination'),
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => 'destination=' . urlencode($test_case['input']),
CURLOPT_HTTPHEADER => array(),
);
$post_output = $this->curlExec($curl_parameters);
$this->assertIdentical($test_case['output'], $post_output, $test_case['message']);
}
// Make sure that 404 pages do not populate $_GET['destination'] with
// external URLs.
variable_set('site_404', 'system-test/get-destination');
$this->drupalGet('http://example.com', array('external' => FALSE));
$this->assertIdentical('', $this->drupalGetContent(), 'External URL is not allowed on 404 pages.');
}
}
+49 -25
View File
@@ -148,7 +148,7 @@ class CacheSavingCase extends CacheTestCase {
cache_set('test_object', $test_object, 'cache');
$cache = cache_get('test_object', 'cache');
$this->assertTrue(isset($cache->data) && $cache->data == $test_object, t('Object is saved and restored properly.'));
$this->assertTrue(isset($cache->data) && $cache->data == $test_object, 'Object is saved and restored properly.');
}
/**
@@ -157,7 +157,7 @@ class CacheSavingCase extends CacheTestCase {
function checkVariable($var) {
cache_set('test_var', $var, 'cache');
$cache = cache_get('test_var', 'cache');
$this->assertTrue(isset($cache->data) && $cache->data === $var, t('@type is saved and restored properly.', array('@type' => ucfirst(gettype($var)))));
$this->assertTrue(isset($cache->data) && $cache->data === $var, format_string('@type is saved and restored properly.', array('@type' => ucfirst(gettype($var)))));
}
/**
@@ -165,7 +165,7 @@ class CacheSavingCase extends CacheTestCase {
*/
function testNoEmptyCids() {
$this->drupalGet('user/register');
$this->assertFalse(cache_get(''), t('No cache entry is written with an empty cid.'));
$this->assertFalse(cache_get(''), 'No cache entry is written with an empty cid.');
}
}
@@ -195,14 +195,14 @@ class CacheGetMultipleUnitTest extends CacheTestCase {
$item2 = $this->randomName(10);
cache_set('item1', $item1, $this->default_bin);
cache_set('item2', $item2, $this->default_bin);
$this->assertTrue($this->checkCacheExists('item1', $item1), t('Item 1 is cached.'));
$this->assertTrue($this->checkCacheExists('item2', $item2), t('Item 2 is cached.'));
$this->assertTrue($this->checkCacheExists('item1', $item1), 'Item 1 is cached.');
$this->assertTrue($this->checkCacheExists('item2', $item2), 'Item 2 is cached.');
// Fetch both records from the database with cache_get_multiple().
$item_ids = array('item1', 'item2');
$items = cache_get_multiple($item_ids, $this->default_bin);
$this->assertEqual($items['item1']->data, $item1, t('Item was returned from cache successfully.'));
$this->assertEqual($items['item2']->data, $item2, t('Item was returned from cache successfully.'));
$this->assertEqual($items['item1']->data, $item1, 'Item was returned from cache successfully.');
$this->assertEqual($items['item2']->data, $item2, 'Item was returned from cache successfully.');
// Remove one item from the cache.
cache_clear_all('item2', $this->default_bin);
@@ -210,9 +210,9 @@ class CacheGetMultipleUnitTest extends CacheTestCase {
// Confirm that only one item is returned by cache_get_multiple().
$item_ids = array('item1', 'item2');
$items = cache_get_multiple($item_ids, $this->default_bin);
$this->assertEqual($items['item1']->data, $item1, t('Item was returned from cache successfully.'));
$this->assertFalse(isset($items['item2']), t('Item was not returned from the cache.'));
$this->assertTrue(count($items) == 1, t('Only valid cache entries returned.'));
$this->assertEqual($items['item1']->data, $item1, 'Item was returned from cache successfully.');
$this->assertFalse(isset($items['item2']), 'Item was not returned from the cache.');
$this->assertTrue(count($items) == 1, 'Only valid cache entries returned.');
}
}
@@ -250,11 +250,11 @@ class CacheClearCase extends CacheTestCase {
cache_set('test_cid_clear2', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two caches were created for checking cid "*" with wildcard false.'));
'Two caches were created for checking cid "*" with wildcard false.');
cache_clear_all('*', $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two caches still exists after clearing cid "*" with wildcard false.'));
'Two caches still exists after clearing cid "*" with wildcard false.');
}
/**
@@ -265,21 +265,21 @@ class CacheClearCase extends CacheTestCase {
cache_set('test_cid_clear2', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two caches were created for checking cid "*" with wildcard true.'));
'Two caches were created for checking cid "*" with wildcard true.');
cache_clear_all('*', $this->default_bin, TRUE);
$this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value)
|| $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two caches removed after clearing cid "*" with wildcard true.'));
'Two caches removed after clearing cid "*" with wildcard true.');
cache_set('test_cid_clear1', $this->default_value, $this->default_bin);
cache_set('test_cid_clear2', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two caches were created for checking cid substring with wildcard true.'));
'Two caches were created for checking cid substring with wildcard true.');
cache_clear_all('test_', $this->default_bin, TRUE);
$this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value)
|| $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two caches removed after clearing cid substring with wildcard true.'));
'Two caches removed after clearing cid substring with wildcard true.');
}
/**
@@ -293,16 +293,16 @@ class CacheClearCase extends CacheTestCase {
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear2', $this->default_value)
&& $this->checkCacheExists('test_cid_clear3', $this->default_value),
t('Three cache entries were created.'));
'Three cache entries were created.');
// Clear two entries using an array.
cache_clear_all(array('test_cid_clear1', 'test_cid_clear2'), $this->default_bin);
$this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value)
|| $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two cache entries removed after clearing with an array.'));
'Two cache entries removed after clearing with an array.');
$this->assertTrue($this->checkCacheExists('test_cid_clear3', $this->default_value),
t('Entry was not cleared from the cache'));
'Entry was not cleared from the cache');
// Set the cache clear threshold to 2 to confirm that the full bin is cleared
// when the threshold is exceeded.
@@ -311,12 +311,12 @@ class CacheClearCase extends CacheTestCase {
cache_set('test_cid_clear2', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear2', $this->default_value),
t('Two cache entries were created.'));
'Two cache entries were created.');
cache_clear_all(array('test_cid_clear1', 'test_cid_clear2', 'test_cid_clear3'), $this->default_bin);
$this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value)
|| $this->checkCacheExists('test_cid_clear2', $this->default_value)
|| $this->checkCacheExists('test_cid_clear3', $this->default_value),
t('All cache entries removed when the array exceeded the cache clear threshold.'));
'All cache entries removed when the array exceeded the cache clear threshold.');
}
/**
@@ -336,7 +336,31 @@ class CacheClearCase extends CacheTestCase {
foreach ($bins as $id => $bin) {
$id = 'test_cid_clear' . $id;
$this->assertFalse($this->checkCacheExists($id, $this->default_value, $bin), t('All cache entries removed from @bin.', array('@bin' => $bin)));
$this->assertFalse($this->checkCacheExists($id, $this->default_value, $bin), format_string('All cache entries removed from @bin.', array('@bin' => $bin)));
}
}
/**
* Test DrupalDatabaseCache::isValidBin().
*/
function testIsValidBin() {
// Retrieve existing cache bins.
$valid_bins = array('cache', 'cache_filter', 'cache_page', 'cache_boostrap', 'cache_path');
$valid_bins = array_merge(module_invoke_all('flush_caches'), $valid_bins);
foreach ($valid_bins as $id => $bin) {
$cache = _cache_get_object($bin);
if ($cache instanceof DrupalDatabaseCache) {
$this->assertTrue($cache->isValidBin(), format_string('Cache bin @bin is valid.', array('@bin' => $bin)));
}
}
// Check for non-cache tables and invalid bins.
$invalid_bins = array('block', 'filter', 'missing_table', $this->randomName());
foreach ($invalid_bins as $id => $bin) {
$cache = _cache_get_object($bin);
if ($cache instanceof DrupalDatabaseCache) {
$this->assertFalse($cache->isValidBin(), format_string('Cache bin @bin is not valid.', array('@bin' => $bin)));
}
}
}
@@ -400,14 +424,14 @@ class CacheIsEmptyCase extends CacheTestCase {
function testIsEmpty() {
// Clear the cache bin.
cache_clear_all('*', $this->default_bin);
$this->assertTrue(cache_is_empty($this->default_bin), t('The cache bin is empty'));
$this->assertTrue(cache_is_empty($this->default_bin), 'The cache bin is empty');
// Add some data to the cache bin.
cache_set($this->default_cid, $this->default_value, $this->default_bin);
$this->assertCacheExists(t('Cache was set.'), $this->default_value, $this->default_cid);
$this->assertFalse(cache_is_empty($this->default_bin), t('The cache bin is not empty'));
$this->assertFalse(cache_is_empty($this->default_bin), 'The cache bin is not empty');
// Remove the cached data.
cache_clear_all($this->default_cid, $this->default_bin);
$this->assertCacheRemoved(t('Cache was removed.'), $this->default_cid);
$this->assertTrue(cache_is_empty($this->default_bin), t('The cache bin is empty'));
$this->assertTrue(cache_is_empty($this->default_bin), 'The cache bin is empty');
}
}
File diff suppressed because it is too large Load Diff
+3 -4
View File
@@ -7,8 +7,7 @@ stylesheets[all][] = common_test.css
stylesheets[print][] = common_test.print.css
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -92,6 +92,18 @@ 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());
}
if (variable_get('common_test_link_to_current_path', FALSE)) {
drupal_set_message(l('link which should point to the current path', current_path()));
}
}
/**
* Print destination query parameter.
*/
@@ -100,6 +112,14 @@ function common_test_destination() {
print "The destination: " . check_plain($destination['destination']);
}
/**
* Applies #printed to an element to help test #pre_render.
*/
function common_test_drupal_render_printing_pre_render($elements) {
$elements['#printed'] = TRUE;
return $elements;
}
/**
* Implements hook_TYPE_alter().
*/
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+3 -4
View File
@@ -5,8 +5,7 @@ package = Testing
version = VERSION
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -87,6 +87,9 @@ function database_test_schema() {
),
);
$schema['test_people_copy'] = $schema['test_people'];
$schema['test_people_copy']['description'] = 'A duplicate version of the test_people table, used for additional tests.';
$schema['test_one_blob'] = array(
'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
'fields' => array(
+163 -10
View File
@@ -23,6 +23,7 @@ class DatabaseTestCase extends DrupalWebTestCase {
$schema['test'] = drupal_get_schema('test');
$schema['test_people'] = drupal_get_schema('test_people');
$schema['test_people_copy'] = drupal_get_schema('test_people_copy');
$schema['test_one_blob'] = drupal_get_schema('test_one_blob');
$schema['test_two_blobs'] = drupal_get_schema('test_two_blobs');
$schema['test_task'] = drupal_get_schema('test_task');
@@ -237,7 +238,7 @@ class DatabaseConnectionTestCase extends DatabaseTestCase {
// Open the default target so we have an object to compare.
$db1 = Database::getConnection('default', 'default');
// Try to close the the default connection, then open a new one.
// Try to close the default connection, then open a new one.
Database::closeConnection('default', 'default');
$db2 = Database::getConnection('default', 'default');
@@ -603,9 +604,9 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
}
/**
* Test that the INSERT INTO ... SELECT ... syntax works.
* Test that the INSERT INTO ... SELECT (fields) ... syntax works.
*/
function testInsertSelect() {
function testInsertSelectFields() {
$query = db_select('test_people', 'tp');
// The query builder will always append expressions after fields.
// Add the expression first to test that the insert fields are correctly
@@ -627,6 +628,27 @@ class DatabaseInsertTestCase extends DatabaseTestCase {
$saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Meredith'))->fetchField();
$this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
}
/**
* Tests that the INSERT INTO ... SELECT * ... syntax works.
*/
function testInsertSelectAll() {
$query = db_select('test_people', 'tp')
->fields('tp')
->condition('tp.name', 'Meredith');
// The resulting query should be equivalent to:
// INSERT INTO test_people_copy
// SELECT *
// FROM test_people tp
// WHERE tp.name = 'Meredith'
db_insert('test_people_copy')
->from($query)
->execute();
$saved_age = db_query('SELECT age FROM {test_people_copy} WHERE name = :name', array(':name' => 'Meredith'))->fetchField();
$this->assertIdentical($saved_age, '30', 'Can retrieve after inserting.');
}
}
/**
@@ -1392,10 +1414,47 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
}
$query = (string)$query;
$expected = "/* Testing query comments SELECT nid FROM {node}; -- */ SELECT test.name AS name, test.age AS age\nFROM \n{test} test";
$expected = "/* Testing query comments * / SELECT nid FROM {node}; -- */ SELECT test.name AS name, test.age AS age\nFROM \n{test} test";
$this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
$this->assertEqual($query, $expected, 'The flattened query contains the sanitised comment string.');
$connection = Database::getConnection();
foreach ($this->makeCommentsProvider() as $test_set) {
list($expected, $comments) = $test_set;
$this->assertEqual($expected, $connection->makeComment($comments));
}
}
/**
* Provides expected and input values for testVulnerableComment().
*/
function makeCommentsProvider() {
return array(
array(
'/* */ ',
array(''),
),
// Try and close the comment early.
array(
'/* Exploit * / DROP TABLE node; -- */ ',
array('Exploit */ DROP TABLE node; --'),
),
// Variations on comment closing.
array(
'/* Exploit * / * / DROP TABLE node; -- */ ',
array('Exploit */*/ DROP TABLE node; --'),
),
array(
'/* Exploit * * // DROP TABLE node; -- */ ',
array('Exploit **// DROP TABLE node; --'),
),
// Try closing the comment in the second string which is appended.
array(
'/* Exploit * / DROP TABLE node; --; Another try * / DROP TABLE node; -- */ ',
array('Exploit */ DROP TABLE node; --', 'Another try */ DROP TABLE node; --'),
),
);
}
/**
@@ -1925,6 +1984,15 @@ class DatabaseSelectOrderedTestCase extends DatabaseTestCase {
$this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
}
/**
* Tests that the sort direction is sanitized properly.
*/
function testOrderByEscaping() {
$query = db_select('test')->orderBy('name', 'invalid direction');
$order_bys = $query->getOrderBy();
$this->assertEqual($order_bys['name'], 'ASC', 'Invalid order by direction is converted to ASC.');
}
}
/**
@@ -2599,6 +2667,52 @@ class DatabaseTaggingTestCase extends DatabaseTestCase {
$this->assertFalse($query->hasAnyTag('other', 'stuff'), 'hasAnyTag() returned false.');
}
/**
* Confirm that an extended query has a "tag" added to it.
*/
function testExtenderHasTag() {
$query = db_select('test')
->extend('SelectQueryExtender');
$query->addField('test', 'name');
$query->addField('test', 'age', 'age');
$query->addTag('test');
$this->assertTrue($query->hasTag('test'), 'hasTag() returned true.');
$this->assertFalse($query->hasTag('other'), 'hasTag() returned false.');
}
/**
* Test extended query tagging "has all of these tags" functionality.
*/
function testExtenderHasAllTags() {
$query = db_select('test')
->extend('SelectQueryExtender');
$query->addField('test', 'name');
$query->addField('test', 'age', 'age');
$query->addTag('test');
$query->addTag('other');
$this->assertTrue($query->hasAllTags('test', 'other'), 'hasAllTags() returned true.');
$this->assertFalse($query->hasAllTags('test', 'stuff'), 'hasAllTags() returned false.');
}
/**
* Test extended query tagging "has at least one of these tags" functionality.
*/
function testExtenderHasAnyTag() {
$query = db_select('test')
->extend('SelectQueryExtender');
$query->addField('test', 'name');
$query->addField('test', 'age', 'age');
$query->addTag('test');
$this->assertTrue($query->hasAnyTag('test', 'other'), 'hasAnyTag() returned true.');
$this->assertFalse($query->hasAnyTag('other', 'stuff'), 'hasAnyTag() returned false.');
}
/**
* Test that we can attach meta data to a query object.
*
@@ -3069,6 +3183,15 @@ class DatabaseTemporaryQueryTestCase extends DrupalWebTestCase {
$this->assertEqual($this->countTableRows($table_name_system), $this->countTableRows("system"), 'A temporary table was created successfully in this request.');
$this->assertEqual($this->countTableRows($table_name_users), $this->countTableRows("users"), 'A second temporary table was created successfully in this request.');
// Check that leading whitespace and comments do not cause problems
// in the modified query.
$sql = "
-- Let's select some rows into a temporary table
SELECT name FROM {test}
";
$table_name_test = db_query_temporary($sql, array());
$this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'Leading white space and comments do not interfere with temporary table creation.');
}
}
@@ -3307,6 +3430,34 @@ class DatabaseQueryTestCase extends DatabaseTestCase {
$this->assertEqual(count($names), 3, 'Correct number of names returned');
}
/**
* Test SQL injection via database query array arguments.
*/
public function testArrayArgumentsSQLInjection() {
// Attempt SQL injection and verify that it does not work.
$condition = array(
"1 ;INSERT INTO {test} (name) VALUES ('test12345678'); -- " => '',
'1' => '',
);
try {
db_query("SELECT * FROM {test} WHERE name = :name", array(':name' => $condition))->fetchObject();
$this->fail('SQL injection attempt via array arguments should result in a PDOException.');
}
catch (PDOException $e) {
$this->pass('SQL injection attempt via array arguments should result in a PDOException.');
}
// Test that the insert query that was used in the SQL injection attempt did
// not result in a row being inserted in the database.
$result = db_select('test')
->condition('name', 'test12345678')
->countQuery()
->execute()
->fetchField();
$this->assertFalse($result, 'SQL injection attempt did not result in a row being inserted in the database table.');
}
}
/**
@@ -3340,12 +3491,14 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
}
/**
* Helper method for transaction unit test. This "outer layer" transaction
* starts and then encapsulates the "inner layer" transaction. This nesting
* is used to evaluate whether the the database transaction API properly
* supports nesting. By "properly supports," we mean the outer transaction
* continues to exist regardless of what functions are called and whether
* those functions start their own transactions.
* Helper method for transaction unit test.
*
* This "outer layer" transaction starts and then encapsulates the
* "inner layer" transaction. This nesting is used to evaluate whether the
* database transaction API properly supports nesting. By "properly supports,"
* we mean the outer transaction continues to exist regardless of what
* functions are called and whether those functions start their own
* transactions.
*
* In contrast, a typical database would commit the outer transaction, start
* a new transaction for the inner layer, commit the inner layer transaction,
@@ -0,0 +1,13 @@
name = "Drupal code registry test"
description = "Support module for testing the code registry."
files[] = drupal_autoload_test_interface.inc
files[] = drupal_autoload_test_class.inc
package = Testing
version = VERSION
core = 7.x
hidden = TRUE
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1600272641"
@@ -0,0 +1,22 @@
<?php
/**
* @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,
);
}
}
}
@@ -0,0 +1,11 @@
<?php
/**
* @file
* Test classes for code registry testing.
*/
/**
* This class is empty because we only care if Drupal can find it.
*/
class DrupalAutoloadTestClass implements DrupalAutoloadTestInterface {}
@@ -0,0 +1,11 @@
<?php
/**
* @file
* Test interfaces for code registry testing.
*/
/**
* This interface is empty because we only care if Drupal can find it.
*/
interface DrupalAutoloadTestInterface {}
@@ -0,0 +1,16 @@
<?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 {}
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -6,8 +6,7 @@ core = 7.x
dependencies[] = entity_cache_test_dependency
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+49
View File
@@ -0,0 +1,49 @@
<?php
/**
* @file
* Tests for the Entity CRUD API.
*/
/**
* Tests the entity_load() function.
*/
class EntityLoadTestCase extends DrupalWebTestCase {
protected $profile = 'testing';
public static function getInfo() {
return array(
'name' => 'Entity loading',
'description' => 'Tests the entity_load() function.',
'group' => 'Entity API',
);
}
/**
* Tests the functionality for loading entities matching certain conditions.
*/
public function testEntityLoadConditions() {
// Create a few nodes. One of them is given an edge-case title of "Array",
// because loading entities by an array of conditions is subject to PHP
// array-to-string conversion issues and we want to test those.
$node_1 = $this->drupalCreateNode(array('title' => 'Array'));
$node_2 = $this->drupalCreateNode(array('title' => 'Node 2'));
$node_3 = $this->drupalCreateNode(array('title' => 'Node 3'));
// Load all entities so that they are statically cached.
$all_nodes = entity_load('node', FALSE);
// Check that the first node can be loaded by title.
$nodes_loaded = entity_load('node', FALSE, array('title' => 'Array'));
$this->assertEqual(array_keys($nodes_loaded), array($node_1->nid));
// Check that the second and third nodes can be loaded by title using an
// array of conditions, and that the first node is not loaded from the
// cache along with them.
$nodes_loaded = entity_load('node', FALSE, array('title' => array('Node 2', 'Node 3')));
ksort($nodes_loaded);
$this->assertEqual(array_keys($nodes_loaded), array($node_2->nid, $node_3->nid));
$this->assertIdentical($nodes_loaded[$node_2->nid], $all_nodes[$node_2->nid], 'Loaded node 2 is identical to cached node.');
$this->assertIdentical($nodes_loaded[$node_3->nid], $all_nodes[$node_3->nid], 'Loaded node 3 is identical to cached node.');
}
}
@@ -5,8 +5,7 @@ package = Testing
version = VERSION
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+121 -121
View File
@@ -169,7 +169,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->entityCondition('entity_id', '5');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle', 5),
), t('Test query on an entity type with a generated bundle.'));
), 'Test query on an entity type with a generated bundle.');
// Test entity_type condition.
$query = new EntityFieldQuery();
@@ -181,7 +181,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test entity entity_type condition.'));
), 'Test entity entity_type condition.');
// Test entity_id condition.
$query = new EntityFieldQuery();
@@ -190,7 +190,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->entityCondition('entity_id', '3');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 3),
), t('Test entity entity_id condition.'));
), 'Test entity entity_id condition.');
$query = new EntityFieldQuery();
$query
@@ -198,7 +198,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->propertyCondition('ftid', '3');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 3),
), t('Test entity entity_id condition and entity_id property condition.'));
), 'Test entity entity_id condition and entity_id property condition.');
// Test bundle condition.
$query = new EntityFieldQuery();
@@ -210,7 +210,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test entity bundle condition: bundle1.'));
), 'Test entity bundle condition: bundle1.');
$query = new EntityFieldQuery();
$query
@@ -219,7 +219,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test entity bundle condition: bundle2.'));
), 'Test entity bundle condition: bundle2.');
$query = new EntityFieldQuery();
$query
@@ -228,7 +228,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test entity bundle condition and bundle property condition.'));
), 'Test entity bundle condition and bundle property condition.');
// Test revision_id condition.
$query = new EntityFieldQuery();
@@ -237,7 +237,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->entityCondition('revision_id', '3');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 3),
), t('Test entity revision_id condition.'));
), 'Test entity revision_id condition.');
$query = new EntityFieldQuery();
$query
@@ -245,7 +245,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->propertyCondition('ftvid', '3');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 3),
), t('Test entity revision_id condition and revision_id property condition.'));
), 'Test entity revision_id condition and revision_id property condition.');
$query = new EntityFieldQuery();
$query
@@ -255,7 +255,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity', 100),
array('test_entity', 101),
), t('Test revision age.'));
), 'Test revision age.');
// Test that fields attached to the non-revision supporting entity
// 'test_entity_bundle_key' are reachable in FIELD_LOAD_REVISION.
@@ -274,7 +274,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 2),
array('test_entity', 3),
array('test_entity', 4),
), t('Test that fields are reachable from FIELD_LOAD_REVISION even for non-revision entities.'));
), 'Test that fields are reachable from FIELD_LOAD_REVISION even for non-revision entities.');
// Test entity sort by entity_id.
$query = new EntityFieldQuery();
@@ -288,7 +288,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test sort entity entity_id in ascending order.'), TRUE);
), 'Test sort entity entity_id in ascending order.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -301,7 +301,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test sort entity entity_id in descending order.'), TRUE);
), 'Test sort entity entity_id in descending order.', TRUE);
// Test entity sort by entity_id, with a field condition.
$query = new EntityFieldQuery();
@@ -316,7 +316,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test sort entity entity_id in ascending order, with a field condition.'), TRUE);
), 'Test sort entity entity_id in ascending order, with a field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -330,7 +330,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test sort entity entity_id property in descending order, with a field condition.'), TRUE);
), 'Test sort entity entity_id property in descending order, with a field condition.', TRUE);
// Test property sort by entity id.
$query = new EntityFieldQuery();
@@ -344,7 +344,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test sort entity entity_id property in ascending order.'), TRUE);
), 'Test sort entity entity_id property in ascending order.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -357,7 +357,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test sort entity entity_id property in descending order.'), TRUE);
), 'Test sort entity entity_id property in descending order.', TRUE);
// Test property sort by entity id, with a field condition.
$query = new EntityFieldQuery();
@@ -372,7 +372,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test sort entity entity_id property in ascending order, with a field condition.'), TRUE);
), 'Test sort entity entity_id property in ascending order, with a field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -386,7 +386,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test sort entity entity_id property in descending order, with a field condition.'), TRUE);
), 'Test sort entity entity_id property in descending order, with a field condition.', TRUE);
// Test entity sort by bundle.
$query = new EntityFieldQuery();
@@ -401,7 +401,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 6),
array('test_entity_bundle_key', 5),
), t('Test sort entity bundle in ascending order, property in descending order.'), TRUE);
), 'Test sort entity bundle in ascending order, property in descending order.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -415,7 +415,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test sort entity bundle in descending order, property in ascending order.'), TRUE);
), 'Test sort entity bundle in descending order, property in ascending order.', TRUE);
// Test entity sort by bundle, with a field condition.
$query = new EntityFieldQuery();
@@ -431,7 +431,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 6),
array('test_entity_bundle_key', 5),
), t('Test sort entity bundle in ascending order, property in descending order, with a field condition.'), TRUE);
), 'Test sort entity bundle in ascending order, property in descending order, with a field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -446,7 +446,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test sort entity bundle in descending order, property in ascending order, with a field condition.'), TRUE);
), 'Test sort entity bundle in descending order, property in ascending order, with a field condition.', TRUE);
// Test entity sort by bundle, field.
$query = new EntityFieldQuery();
@@ -461,7 +461,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 6),
array('test_entity_bundle_key', 5),
), t('Test sort entity bundle in ascending order, field in descending order.'), TRUE);
), 'Test sort entity bundle in ascending order, field in descending order.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -475,7 +475,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test sort entity bundle in descending order, field in ascending order.'), TRUE);
), 'Test sort entity bundle in descending order, field in ascending order.', TRUE);
// Test entity sort by revision_id.
$query = new EntityFieldQuery();
@@ -487,7 +487,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 2),
array('test_entity', 3),
array('test_entity', 4),
), t('Test sort entity revision_id in ascending order.'), TRUE);
), 'Test sort entity revision_id in ascending order.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -498,7 +498,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 3),
array('test_entity', 2),
array('test_entity', 1),
), t('Test sort entity revision_id in descending order.'), TRUE);
), 'Test sort entity revision_id in descending order.', TRUE);
// Test entity sort by revision_id, with a field condition.
$query = new EntityFieldQuery();
@@ -511,7 +511,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 2),
array('test_entity', 3),
array('test_entity', 4),
), t('Test sort entity revision_id in ascending order, with a field condition.'), TRUE);
), 'Test sort entity revision_id in ascending order, with a field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -523,7 +523,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 3),
array('test_entity', 2),
array('test_entity', 1),
), t('Test sort entity revision_id in descending order, with a field condition.'), TRUE);
), 'Test sort entity revision_id in descending order, with a field condition.', TRUE);
// Test property sort by revision_id.
$query = new EntityFieldQuery();
@@ -535,7 +535,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 2),
array('test_entity', 3),
array('test_entity', 4),
), t('Test sort entity revision_id property in ascending order.'), TRUE);
), 'Test sort entity revision_id property in ascending order.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -546,7 +546,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 3),
array('test_entity', 2),
array('test_entity', 1),
), t('Test sort entity revision_id property in descending order.'), TRUE);
), 'Test sort entity revision_id property in descending order.', TRUE);
// Test property sort by revision_id, with a field condition.
$query = new EntityFieldQuery();
@@ -559,7 +559,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 2),
array('test_entity', 3),
array('test_entity', 4),
), t('Test sort entity revision_id property in ascending order, with a field condition.'), TRUE);
), 'Test sort entity revision_id property in ascending order, with a field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -571,7 +571,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 3),
array('test_entity', 2),
array('test_entity', 1),
), t('Test sort entity revision_id property in descending order, with a field condition.'), TRUE);
), 'Test sort entity revision_id property in descending order, with a field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -584,7 +584,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test sort field in ascending order without field condition.'), TRUE);
), 'Test sort field in ascending order without field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -597,7 +597,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test sort field in descending order without field condition.'), TRUE);
), 'Test sort field in descending order without field condition.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -611,7 +611,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test sort field in ascending order.'), TRUE);
), 'Test sort field in ascending order.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -625,7 +625,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test sort field in descending order.'), TRUE);
), 'Test sort field in descending order.', TRUE);
// Test "in" operation with entity entity_type condition and entity_id
// property condition.
@@ -637,7 +637,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test "in" operation with entity entity_type condition and entity_id property condition.'));
), 'Test "in" operation with entity entity_type condition and entity_id property condition.');
// Test "in" operation with entity entity_type condition and entity_id
// property condition. Sort in descending order by entity_id.
@@ -650,7 +650,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 1),
), t('Test "in" operation with entity entity_type condition and entity_id property condition. Sort entity_id in descending order.'), TRUE);
), 'Test "in" operation with entity entity_type condition and entity_id property condition. Sort entity_id in descending order.', TRUE);
// Test query count
$query = new EntityFieldQuery();
@@ -658,7 +658,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->entityCondition('entity_type', 'test_entity_bundle_key')
->count()
->execute();
$this->assertEqual($query_count, 6, t('Test query count on entity condition.'));
$this->assertEqual($query_count, 6, 'Test query count on entity condition.');
$query = new EntityFieldQuery();
$query_count = $query
@@ -666,7 +666,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->propertyCondition('ftid', '1')
->count()
->execute();
$this->assertEqual($query_count, 1, t('Test query count on entity and property condition.'));
$this->assertEqual($query_count, 1, 'Test query count on entity and property condition.');
$query = new EntityFieldQuery();
$query_count = $query
@@ -674,7 +674,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->propertyCondition('ftid', '4', '>')
->count()
->execute();
$this->assertEqual($query_count, 2, t('Test query count on entity and property condition with operator.'));
$this->assertEqual($query_count, 2, 'Test query count on entity and property condition with operator.');
$query = new EntityFieldQuery();
$query_count = $query
@@ -682,7 +682,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 3, '=')
->count()
->execute();
$this->assertEqual($query_count, 1, t('Test query count on field condition.'));
$this->assertEqual($query_count, 1, 'Test query count on field condition.');
// First, test without options.
$query = new EntityFieldQuery();
@@ -696,13 +696,13 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test the "contains" operation on a property.'));
), 'Test the "contains" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[1], 'shape', 'uar', 'CONTAINS');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle', 5),
), t('Test the "contains" operation on a field.'));
), 'Test the "contains" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -710,14 +710,14 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->propertyCondition('ftid', 1, '=');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 1),
), t('Test the "equal to" operation on a property.'));
), 'Test the "equal to" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 3, '=');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 3),
array('test_entity', 3),
), t('Test the "equal to" operation on a field.'));
), 'Test the "equal to" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -729,7 +729,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test the "not equal to" operation on a property.'));
), 'Test the "not equal to" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 3, '<>');
@@ -742,7 +742,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 1),
array('test_entity', 2),
array('test_entity', 4),
), t('Test the "not equal to" operation on a field.'));
), 'Test the "not equal to" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -754,7 +754,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test the "not equal to" operation on a property.'));
), 'Test the "not equal to" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 3, '!=');
@@ -767,7 +767,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 1),
array('test_entity', 2),
array('test_entity', 4),
), t('Test the "not equal to" operation on a field.'));
), 'Test the "not equal to" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -775,14 +775,14 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->propertyCondition('ftid', 2, '<');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 1),
), t('Test the "less than" operation on a property.'));
), 'Test the "less than" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 2, '<');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 1),
array('test_entity', 1),
), t('Test the "less than" operation on a field.'));
), 'Test the "less than" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -791,7 +791,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 2),
), t('Test the "less than or equal to" operation on a property.'));
), 'Test the "less than or equal to" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 2, '<=');
@@ -800,7 +800,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity', 1),
array('test_entity', 2),
), t('Test the "less than or equal to" operation on a field.'));
), 'Test the "less than or equal to" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -809,7 +809,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test the "greater than" operation on a property.'));
), 'Test the "greater than" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 2, '>');
@@ -820,7 +820,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 6),
array('test_entity', 3),
array('test_entity', 4),
), t('Test the "greater than" operation on a field.'));
), 'Test the "greater than" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -830,7 +830,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test the "greater than or equal to" operation on a property.'));
), 'Test the "greater than or equal to" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 3, '>=');
@@ -841,7 +841,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 6),
array('test_entity', 3),
array('test_entity', 4),
), t('Test the "greater than or equal to" operation on a field.'));
), 'Test the "greater than or equal to" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -852,7 +852,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test the "not in" operation on a property.'));
), 'Test the "not in" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', array(3, 4, 100, 101), 'NOT IN');
@@ -863,7 +863,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 6),
array('test_entity', 1),
array('test_entity', 2),
), t('Test the "not in" operation on a field.'));
), 'Test the "not in" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -872,7 +872,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test the "in" operation on a property.'));
), 'Test the "in" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', array(2, 3), 'IN');
@@ -881,7 +881,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity', 2),
array('test_entity', 3),
), t('Test the "in" operation on a field.'));
), 'Test the "in" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -891,7 +891,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
), t('Test the "between" operation on a property.'));
), 'Test the "between" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', array(1, 3), 'BETWEEN');
@@ -902,7 +902,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 1),
array('test_entity', 2),
array('test_entity', 3),
), t('Test the "between" operation on a field.'));
), 'Test the "between" operation on a field.');
$query = new EntityFieldQuery();
$query
@@ -915,20 +915,20 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test the "starts_with" operation on a property.'));
), 'Test the "starts_with" operation on a property.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[1], 'shape', 'squ', 'STARTS_WITH');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle', 5),
), t('Test the "starts_with" operation on a field.'));
), 'Test the "starts_with" operation on a field.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 3);
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 3),
array('test_entity', 3),
), t('Test omission of an operator with a single item.'));
), 'Test omission of an operator with a single item.');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', array(2, 3));
@@ -937,7 +937,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity', 2),
array('test_entity', 3),
), t('Test omission of an operator with multiple items.'));
), 'Test omission of an operator with multiple items.');
$query = new EntityFieldQuery();
$query
@@ -947,7 +947,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
), t('Test entity, property and field conditions.'));
), 'Test entity, property and field conditions.');
$query = new EntityFieldQuery();
$query
@@ -957,7 +957,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 4);
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 4),
), t('Test entity condition with "starts_with" operation, and property and field conditions.'));
), 'Test entity condition with "starts_with" operation, and property and field conditions.');
$query = new EntityFieldQuery();
$query
@@ -967,7 +967,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 2),
), t('Test limit on a property.'), TRUE);
), 'Test limit on a property.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -978,7 +978,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 2),
), t('Test limit on a field.'), TRUE);
), 'Test limit on a field.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -988,7 +988,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test offset on a property.'), TRUE);
), 'Test offset on a property.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -1001,7 +1001,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test offset on a field.'), TRUE);
), 'Test offset on a field.', TRUE);
for ($i = 6; $i < 10; $i++) {
$entity = new stdClass();
@@ -1023,7 +1023,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity', 4),
array('test_entity_bundle', 8),
array('test_entity_bundle', 9),
), t('Select a field across multiple entities.'));
), 'Select a field across multiple entities.');
$query = new EntityFieldQuery();
$query
@@ -1031,13 +1031,13 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[1], 'color', 'blue');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle', 5),
), t('Test without a delta group.'));
), 'Test without a delta group.');
$query = new EntityFieldQuery();
$query
->fieldCondition($this->fields[1], 'shape', 'square', '=', 'group')
->fieldCondition($this->fields[1], 'color', 'blue', '=', 'group');
$this->assertEntityFieldQuery($query, array(), t('Test with a delta group.'));
$this->assertEntityFieldQuery($query, array(), 'Test with a delta group.');
// Test query on a deleted field.
field_attach_delete_bundle('test_entity_bundle_key', 'bundle1');
@@ -1046,12 +1046,12 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$query->fieldCondition($this->fields[0], 'value', '3');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle', 8),
), t('Test query on a field after deleting field from some entities.'));
), 'Test query on a field after deleting field from some entities.');
field_attach_delete_bundle('test_entity_bundle', 'test_entity_bundle');
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', '3');
$this->assertEntityFieldQuery($query, array(), t('Test query on a field after deleting field from all entities.'));
$this->assertEntityFieldQuery($query, array(), 'Test query on a field after deleting field from all entities.');
$query = new EntityFieldQuery();
$query
@@ -1061,7 +1061,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle', 8),
array('test_entity', 3),
), t('Test query on a deleted field with deleted option set to TRUE.'));
), 'Test query on a deleted field with deleted option set to TRUE.');
$pass = FALSE;
$query = new EntityFieldQuery();
@@ -1071,7 +1071,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
catch (EntityFieldQueryException $exception) {
$pass = ($exception->getMessage() == t('For this query an entity type must be specified.'));
}
$this->assertTrue($pass, t("Can't query the universe."));
$this->assertTrue($pass, "Can't query the universe.");
}
/**
@@ -1109,7 +1109,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->count()
->execute();
$this->assertEqual($query_count, 1, t("Count on translatable cardinality one field is correct."));
$this->assertEqual($query_count, 1, "Count on translatable cardinality one field is correct.");
}
/**
@@ -1144,7 +1144,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldDeltaCondition($this->fields[0], 0, '>');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a delta meta condition.'));
), 'Test with a delta meta condition.');
// Test language field meta condition.
$query = new EntityFieldQuery();
@@ -1153,7 +1153,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '<>');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a language meta condition.'));
), 'Test with a language meta condition.');
// Test language field meta condition.
$query = new EntityFieldQuery();
@@ -1162,7 +1162,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '!=');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a language meta condition.'));
), 'Test with a language meta condition.');
// Test delta grouping.
$query = new EntityFieldQuery();
@@ -1172,14 +1172,14 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldDeltaCondition($this->fields[0], 1, '<', 'group');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a grouped delta meta condition.'));
), 'Test with a grouped delta meta condition.');
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'test_entity', '=')
->fieldCondition($this->fields[0], 'value', 0, '=', 'group')
->fieldDeltaCondition($this->fields[0], 1, '>=', 'group');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped delta meta condition (empty result set).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped delta meta condition (empty result set).');
// Test language grouping.
$query = new EntityFieldQuery();
@@ -1189,7 +1189,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldLanguageCondition($this->fields[0], 'en', '<>', NULL, 'group');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a grouped language meta condition.'));
), 'Test with a grouped language meta condition.');
// Test language grouping.
$query = new EntityFieldQuery();
@@ -1199,21 +1199,21 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldLanguageCondition($this->fields[0], 'en', '!=', NULL, 'group');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a grouped language meta condition.'));
), 'Test with a grouped language meta condition.');
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'test_entity', '=')
->fieldCondition($this->fields[0], 'value', 0, '=', NULL, 'group')
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '<>', NULL, 'group');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped language meta condition (empty result set).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped language meta condition (empty result set).');
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'test_entity', '=')
->fieldCondition($this->fields[0], 'value', 0, '=', NULL, 'group')
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '!=', NULL, 'group');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped language meta condition (empty result set).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped language meta condition (empty result set).');
// Test delta and language grouping.
$query = new EntityFieldQuery();
@@ -1224,7 +1224,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldLanguageCondition($this->fields[0], 'en', '<>', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a grouped delta + language meta condition.'));
), 'Test with a grouped delta + language meta condition.');
// Test delta and language grouping.
$query = new EntityFieldQuery();
@@ -1235,7 +1235,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldLanguageCondition($this->fields[0], 'en', '!=', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(
array('test_entity', 1),
), t('Test with a grouped delta + language meta condition.'));
), 'Test with a grouped delta + language meta condition.');
$query = new EntityFieldQuery();
$query
@@ -1243,7 +1243,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 0, '=', 'delta', 'language')
->fieldDeltaCondition($this->fields[0], 1, '>=', 'delta', 'language')
->fieldLanguageCondition($this->fields[0], 'en', '<>', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped delta + language meta condition (empty result set, delta condition unsatisifed).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped delta + language meta condition (empty result set, delta condition unsatisifed).');
$query = new EntityFieldQuery();
$query
@@ -1251,7 +1251,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 0, '=', 'delta', 'language')
->fieldDeltaCondition($this->fields[0], 1, '>=', 'delta', 'language')
->fieldLanguageCondition($this->fields[0], 'en', '!=', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped delta + language meta condition (empty result set, delta condition unsatisifed).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped delta + language meta condition (empty result set, delta condition unsatisifed).');
$query = new EntityFieldQuery();
$query
@@ -1259,7 +1259,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 0, '=', 'delta', 'language')
->fieldDeltaCondition($this->fields[0], 1, '<', 'delta', 'language')
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '<>', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped delta + language meta condition (empty result set, language condition unsatisifed).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped delta + language meta condition (empty result set, language condition unsatisifed).');
$query = new EntityFieldQuery();
$query
@@ -1267,7 +1267,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 0, '=', 'delta', 'language')
->fieldDeltaCondition($this->fields[0], 1, '<', 'delta', 'language')
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '!=', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped delta + language meta condition (empty result set, language condition unsatisifed).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped delta + language meta condition (empty result set, language condition unsatisifed).');
$query = new EntityFieldQuery();
$query
@@ -1275,7 +1275,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 0, '=', 'delta', 'language')
->fieldDeltaCondition($this->fields[0], 1, '>=', 'delta', 'language')
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '<>', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped delta + language meta condition (empty result set, both conditions unsatisifed).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped delta + language meta condition (empty result set, both conditions unsatisifed).');
$query = new EntityFieldQuery();
$query
@@ -1283,7 +1283,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldCondition($this->fields[0], 'value', 0, '=', 'delta', 'language')
->fieldDeltaCondition($this->fields[0], 1, '>=', 'delta', 'language')
->fieldLanguageCondition($this->fields[0], LANGUAGE_NONE, '!=', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(), t('Test with a grouped delta + language meta condition (empty result set, both conditions unsatisifed).'));
$this->assertEntityFieldQuery($query, array(), 'Test with a grouped delta + language meta condition (empty result set, both conditions unsatisifed).');
// Test grouping with another field to ensure that grouping cache is reset
// properly.
@@ -1296,7 +1296,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
->fieldLanguageCondition($this->fields[1], LANGUAGE_NONE, '=', 'delta', 'language');
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle', 5),
), t('Test grouping cache.'));
), 'Test grouping cache.');
}
/**
@@ -1306,19 +1306,19 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
// Entity-only query.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'test_entity_bundle_key');
$this->assertIdentical($query->queryCallback(), array($query, 'propertyQuery'), t('Entity-only queries are handled by the propertyQuery handler.'));
$this->assertIdentical($query->queryCallback(), array($query, 'propertyQuery'), 'Entity-only queries are handled by the propertyQuery handler.');
// Field-only query.
$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', '3');
$this->assertIdentical($query->queryCallback(), 'field_sql_storage_field_storage_query', t('Pure field queries are handled by the Field storage handler.'));
$this->assertIdentical($query->queryCallback(), 'field_sql_storage_field_storage_query', 'Pure field queries are handled by the Field storage handler.');
// Mixed entity and field query.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'test_entity_bundle_key')
->fieldCondition($this->fields[0], 'value', '3');
$this->assertIdentical($query->queryCallback(), 'field_sql_storage_field_storage_query', t('Mixed queries are handled by the Field storage handler.'));
$this->assertIdentical($query->queryCallback(), 'field_sql_storage_field_storage_query', 'Mixed queries are handled by the Field storage handler.');
// Overriding with $query->executeCallback.
$query = new EntityFieldQuery();
@@ -1326,7 +1326,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$query->executeCallback = 'field_test_dummy_field_storage_query';
$this->assertEntityFieldQuery($query, array(
array('user', 1),
), t('executeCallback can override the query handler.'));
), 'executeCallback can override the query handler.');
// Overriding with $query->executeCallback via hook_entity_query_alter().
$query = new EntityFieldQuery();
@@ -1335,7 +1335,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$query->alterMyExecuteCallbackPlease = TRUE;
$this->assertEntityFieldQuery($query, array(
array('user', 1),
), t('executeCallback can override the query handler when set in a hook_entity_query_alter().'));
), 'executeCallback can override the query handler when set in a hook_entity_query_alter().');
// Mixed-storage queries.
$query = new EntityFieldQuery();
@@ -1350,7 +1350,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
catch (EntityFieldQueryException $exception) {
$pass = ($exception->getMessage() == t("Can't handle more than one field storage engine"));
}
$this->assertTrue($pass, t('Cannot query across field storage engines.'));
$this->assertTrue($pass, 'Cannot query across field storage engines.');
}
/**
@@ -1368,7 +1368,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
), t('Test pager integration in propertyQuery: page 1.'), TRUE);
), 'Test pager integration in propertyQuery: page 1.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -1379,7 +1379,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test pager integration in propertyQuery: page 2.'), TRUE);
), 'Test pager integration in propertyQuery: page 2.', TRUE);
// Test pager in field storage
$_GET['page'] = '0,1';
@@ -1392,7 +1392,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 2),
), t('Test pager integration in field storage: page 1.'), TRUE);
), 'Test pager integration in field storage: page 1.', TRUE);
$query = new EntityFieldQuery();
$query
@@ -1403,7 +1403,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertEntityFieldQuery($query, array(
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test pager integration in field storage: page 2.'), TRUE);
), 'Test pager integration in field storage: page 2.', TRUE);
unset($_GET['page']);
}
@@ -1451,7 +1451,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test TableSort by property: ftid ASC in propertyQuery.'), TRUE);
), 'Test TableSort by property: ftid ASC in propertyQuery.', TRUE);
$_GET['sort'] = 'desc';
$_GET['order'] = 'Id';
@@ -1466,7 +1466,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test TableSort by property: ftid DESC in propertyQuery.'), TRUE);
), 'Test TableSort by property: ftid DESC in propertyQuery.', TRUE);
$_GET['sort'] = 'asc';
$_GET['order'] = 'Type';
@@ -1481,7 +1481,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test TableSort by entity: bundle ASC in propertyQuery.'), TRUE);
), 'Test TableSort by entity: bundle ASC in propertyQuery.', TRUE);
$_GET['sort'] = 'desc';
$_GET['order'] = 'Type';
@@ -1496,7 +1496,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test TableSort by entity: bundle DESC in propertyQuery.'), TRUE);
), 'Test TableSort by entity: bundle DESC in propertyQuery.', TRUE);
// Test TableSort in field storage
$_GET['sort'] = 'asc';
@@ -1518,7 +1518,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test TableSort by property: ftid ASC in field storage.'), TRUE);
), 'Test TableSort by property: ftid ASC in field storage.', TRUE);
$_GET['sort'] = 'desc';
$_GET['order'] = 'Id';
@@ -1534,7 +1534,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test TableSort by property: ftid DESC in field storage.'), TRUE);
), 'Test TableSort by property: ftid DESC in field storage.', TRUE);
$_GET['sort'] = 'asc';
$_GET['order'] = 'Type';
@@ -1551,7 +1551,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 1),
array('test_entity_bundle_key', 6),
array('test_entity_bundle_key', 5),
), t('Test TableSort by entity: bundle ASC in field storage.'), TRUE);
), 'Test TableSort by entity: bundle ASC in field storage.', TRUE);
$_GET['sort'] = 'desc';
$_GET['order'] = 'Type';
@@ -1568,7 +1568,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 4),
), t('Test TableSort by entity: bundle DESC in field storage.'), TRUE);
), 'Test TableSort by entity: bundle DESC in field storage.', TRUE);
$_GET['sort'] = 'asc';
$_GET['order'] = 'Field';
@@ -1584,7 +1584,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 4),
array('test_entity_bundle_key', 5),
array('test_entity_bundle_key', 6),
), t('Test TableSort by field ASC.'), TRUE);
), 'Test TableSort by field ASC.', TRUE);
$_GET['sort'] = 'desc';
$_GET['order'] = 'Field';
@@ -1600,7 +1600,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
array('test_entity_bundle_key', 3),
array('test_entity_bundle_key', 2),
array('test_entity_bundle_key', 1),
), t('Test TableSort by field DESC.'), TRUE);
), 'Test TableSort by field DESC.', TRUE);
unset($_GET['sort']);
unset($_GET['order']);
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+11 -11
View File
@@ -42,7 +42,7 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
// Set error reporting to collect notices.
variable_set('error_level', ERROR_REPORTING_DISPLAY_ALL);
$this->drupalGet('error-test/generate-warnings');
$this->assertResponse(200, t('Received expected HTTP status code.'));
$this->assertResponse(200, 'Received expected HTTP status code.');
$this->assertErrorMessage($error_notice);
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
@@ -50,7 +50,7 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
// Set error reporting to not collect notices.
variable_set('error_level', ERROR_REPORTING_DISPLAY_SOME);
$this->drupalGet('error-test/generate-warnings');
$this->assertResponse(200, t('Received expected HTTP status code.'));
$this->assertResponse(200, 'Received expected HTTP status code.');
$this->assertNoErrorMessage($error_notice);
$this->assertErrorMessage($error_warning);
$this->assertErrorMessage($error_user_notice);
@@ -58,7 +58,7 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
// Set error reporting to not show any errors.
variable_set('error_level', ERROR_REPORTING_HIDE);
$this->drupalGet('error-test/generate-warnings');
$this->assertResponse(200, t('Received expected HTTP status code.'));
$this->assertResponse(200, 'Received expected HTTP status code.');
$this->assertNoErrorMessage($error_notice);
$this->assertNoErrorMessage($error_warning);
$this->assertNoErrorMessage($error_user_notice);
@@ -84,17 +84,17 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
);
$this->drupalGet('error-test/trigger-exception');
$this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), t('Received expected HTTP status line.'));
$this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
$this->assertErrorMessage($error_exception);
$this->drupalGet('error-test/trigger-pdo-exception');
$this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), t('Received expected HTTP status line.'));
$this->assertTrue(strpos($this->drupalGetHeader(':status'), '500 Service unavailable (with message)'), 'Received expected HTTP status line.');
// We cannot use assertErrorMessage() since the extact error reported
// varies from database to database. Check that the SQL string is displayed.
$this->assertText($error_pdo_exception['%type'], t('Found %type in error page.', $error_pdo_exception));
$this->assertText($error_pdo_exception['!message'], t('Found !message in error page.', $error_pdo_exception));
$error_details = t('in %function (line ', $error_pdo_exception);
$this->assertRaw($error_details, t("Found '!message' in error page.", array('!message' => $error_details)));
$this->assertText($error_pdo_exception['%type'], format_string('Found %type in error page.', $error_pdo_exception));
$this->assertText($error_pdo_exception['!message'], format_string('Found !message in error page.', $error_pdo_exception));
$error_details = format_string('in %function (line ', $error_pdo_exception);
$this->assertRaw($error_details, format_string("Found '!message' in error page.", array('!message' => $error_details)));
}
/**
@@ -102,7 +102,7 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
*/
function assertErrorMessage(array $error) {
$message = t('%type: !message in %function (line ', $error);
$this->assertRaw($message, t('Found error message: !message.', array('!message' => $message)));
$this->assertRaw($message, format_string('Found error message: !message.', array('!message' => $message)));
}
/**
@@ -110,7 +110,7 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
*/
function assertNoErrorMessage(array $error) {
$message = t('%type: !message in %function (line ', $error);
$this->assertNoRaw($message, t('Did not find error message: !message.', array('!message' => $message)));
$this->assertNoRaw($message, format_string('Did not find error message: !message.', array('!message' => $message)));
}
}
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
File diff suppressed because it is too large Load Diff
+3 -4
View File
@@ -6,8 +6,7 @@ core = 7.x
files[] = file_test.module
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -44,6 +44,8 @@ function filter_test_filter_info() {
}
/**
* Implements callback_filter_process().
*
* Process handler for filter_test_replace filter.
*
* Replaces all text with filter and text format information.
File diff suppressed because it is too large Load Diff
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+160
View File
@@ -37,6 +37,13 @@ function form_test_menu() {
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['form-test/validate-no-token'] = array(
'title' => 'Form validation without a CSRF token',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_test_validate_no_token'),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['form-test/limit-validation-errors'] = array(
'title' => 'Form validation with some error suppression',
'page callback' => 'drupal_get_form',
@@ -90,6 +97,21 @@ function form_test_menu() {
'type' => MENU_CALLBACK,
);
$items['form_test/form-storage-legacy'] = array(
'title' => 'Emulate legacy AHAH-style ajax callback',
'page callback' => 'form_test_storage_legacy_handler',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['form_test/form-storage-page-cache'] = array(
'title' => 'Form storage with page cache test',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_test_storage_page_cache_form'),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['form_test/wrapper-callback'] = array(
'title' => 'Form wrapper callback test',
'page callback' => 'form_test_wrapper_callback',
@@ -439,6 +461,27 @@ function form_test_validate_required_form_no_title_submit($form, &$form_state) {
drupal_set_message('The form_test_validate_required_form_no_title form was submitted successfully.');
}
/**
* Form builder for testing submission of a form without a CSRF token.
*/
function form_test_validate_no_token($form, &$form_state) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
$form['#token'] = FALSE;
return $form;
}
/**
* Form submission handler for form_test_validate_no_token().
*/
function form_test_validate_no_token_submit($form, &$form_state) {
drupal_set_message('The form_test_validate_no_token form has been submitted successfully.');
}
/**
* Builds a simple form with a button triggering partial validation.
*/
@@ -574,11 +617,17 @@ function _form_test_tableselect_form_builder($form, $form_state, $element_proper
$form['tableselect'] = $element_properties;
$form['tableselect'] += array(
'#prefix' => '<div id="tableselect-wrapper">',
'#suffix' => '</div>',
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#multiple' => FALSE,
'#empty' => t('Empty text.'),
'#ajax' => array(
'callback' => '_form_test_tableselect_ajax_callback',
'wrapper' => 'tableselect-wrapper',
),
);
$form['submit'] = array(
@@ -682,6 +731,13 @@ function _form_test_vertical_tabs_form($form, &$form_state) {
return $form;
}
/**
* Ajax callback that returns the form element.
*/
function _form_test_tableselect_ajax_callback($form, &$form_state) {
return $form['tableselect'];
}
/**
* A multistep form for testing the form storage.
*
@@ -746,9 +802,36 @@ function form_test_storage_form($form, &$form_state) {
$form_state['cache'] = TRUE;
}
if (isset($_REQUEST['immutable'])) {
$form_state['build_info']['immutable'] = TRUE;
}
return $form;
}
/**
* Emulate legacy AHAH-style ajax callback.
*
* Drupal 6 AHAH callbacks used to operate directly on forms retrieved using
* form_get_cache and stored using form_set_cache after manipulation. This
* callback helps testing whether form_set_cache prevents resaving of immutable
* forms.
*/
function form_test_storage_legacy_handler($form_build_id) {
$form_state = array();
$form = form_get_cache($form_build_id, $form_state);
drupal_json_output(array(
'form' => $form,
'form_state' => $form_state,
));
$form['#poisoned'] = TRUE;
$form_state['poisoned'] = TRUE;
form_set_cache($form_build_id, $form, $form_state);
}
/**
* Form element validation handler for 'value' element in form_test_storage_form().
*
@@ -785,6 +868,74 @@ function form_test_storage_form_submit($form, &$form_state) {
$form_state['redirect'] = 'node';
}
/**
* A simple form for testing form storage when page caching is enabled.
*/
function form_test_storage_page_cache_form($form, &$form_state) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => 'Title',
'#required' => TRUE,
);
$form['test_build_id_old'] = array(
'#type' => 'item',
'#title' => 'Old build id',
'#markup' => 'No old build id',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
$form['rebuild'] = array(
'#type' => 'submit',
'#value' => 'Rebuild',
'#submit' => array('form_test_storage_page_cache_rebuild'),
);
$form['#after_build'] = array('form_test_storage_page_cache_old_build_id');
$form_state['cache'] = TRUE;
return $form;
}
/**
* Form element #after_build callback: output the old form build-id.
*/
function form_test_storage_page_cache_old_build_id($form) {
if (isset($form['#build_id_old'])) {
$form['test_build_id_old']['#markup'] = check_plain($form['#build_id_old']);
}
return $form;
}
/**
* Form submit callback: Rebuild the form and continue.
*/
function form_test_storage_page_cache_rebuild($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
/**
* A simple form for testing form caching.
*/
function form_test_cache_form($form, &$form_state) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => 'Title',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
return $form;
}
/**
* A form for testing form labels and required marks.
*/
@@ -1548,6 +1699,15 @@ function form_test_programmatic_form($form, &$form_state) {
'#default_value' => array(1, 2),
);
// This is used to test that programmatic form submissions can bypass #access
// restrictions.
$form['textfield_no_access'] = array(
'#type' => 'textfield',
'#title' => 'Textfield no access',
'#default_value' => 'default value',
'#access' => FALSE,
);
$form['field_to_validate'] = array(
'#type' => 'radios',
'#title' => 'Field to validate (in the case of limited validation)',
+6 -6
View File
@@ -69,7 +69,7 @@ class GraphUnitTest extends DrupalUnitTestCase {
$this->assertReversePaths($graph, $expected_reverse_paths);
// Assert that DFS didn't created "missing" vertexes automatically.
$this->assertFALSE(isset($graph[6]), t('Vertex 6 has not been created'));
$this->assertFALSE(isset($graph[6]), 'Vertex 6 has not been created');
$expected_components = array(
array(1, 2, 3, 4, 5, 7),
@@ -115,7 +115,7 @@ class GraphUnitTest extends DrupalUnitTestCase {
// Build an array with keys = $paths and values = TRUE.
$expected = array_fill_keys($paths, TRUE);
$result = isset($graph[$vertex]['paths']) ? $graph[$vertex]['paths'] : array();
$this->assertEqual($expected, $result, t('Expected paths for vertex @vertex: @expected-paths, got @paths', array('@vertex' => $vertex, '@expected-paths' => $this->displayArray($expected, TRUE), '@paths' => $this->displayArray($result, TRUE))));
$this->assertEqual($expected, $result, format_string('Expected paths for vertex @vertex: @expected-paths, got @paths', array('@vertex' => $vertex, '@expected-paths' => $this->displayArray($expected, TRUE), '@paths' => $this->displayArray($result, TRUE))));
}
}
@@ -133,7 +133,7 @@ class GraphUnitTest extends DrupalUnitTestCase {
// Build an array with keys = $paths and values = TRUE.
$expected = array_fill_keys($paths, TRUE);
$result = isset($graph[$vertex]['reverse_paths']) ? $graph[$vertex]['reverse_paths'] : array();
$this->assertEqual($expected, $result, t('Expected reverse paths for vertex @vertex: @expected-paths, got @paths', array('@vertex' => $vertex, '@expected-paths' => $this->displayArray($expected, TRUE), '@paths' => $this->displayArray($result, TRUE))));
$this->assertEqual($expected, $result, format_string('Expected reverse paths for vertex @vertex: @expected-paths, got @paths', array('@vertex' => $vertex, '@expected-paths' => $this->displayArray($expected, TRUE), '@paths' => $this->displayArray($result, TRUE))));
}
}
@@ -153,9 +153,9 @@ class GraphUnitTest extends DrupalUnitTestCase {
$result_components[] = $graph[$vertex]['component'];
unset($unassigned_vertices[$vertex]);
}
$this->assertEqual(1, count(array_unique($result_components)), t('Expected one unique component for vertices @vertices, got @components', array('@vertices' => $this->displayArray($component), '@components' => $this->displayArray($result_components))));
$this->assertEqual(1, count(array_unique($result_components)), format_string('Expected one unique component for vertices @vertices, got @components', array('@vertices' => $this->displayArray($component), '@components' => $this->displayArray($result_components))));
}
$this->assertEqual(array(), $unassigned_vertices, t('Vertices not assigned to a component: @vertices', array('@vertices' => $this->displayArray($unassigned_vertices, TRUE))));
$this->assertEqual(array(), $unassigned_vertices, format_string('Vertices not assigned to a component: @vertices', array('@vertices' => $this->displayArray($unassigned_vertices, TRUE))));
}
/**
@@ -170,7 +170,7 @@ class GraphUnitTest extends DrupalUnitTestCase {
foreach ($expected_orders as $order) {
$previous_vertex = array_shift($order);
foreach ($order as $vertex) {
$this->assertTrue($graph[$previous_vertex]['weight'] < $graph[$vertex]['weight'], t('Weights of @previous-vertex and @vertex are correct relative to each other', array('@previous-vertex' => $previous_vertex, '@vertex' => $vertex)));
$this->assertTrue($graph[$previous_vertex]['weight'] < $graph[$vertex]['weight'], format_string('Weights of @previous-vertex and @vertex are correct relative to each other', array('@previous-vertex' => $previous_vertex, '@vertex' => $vertex)));
}
}
}
+129 -56
View File
@@ -55,19 +55,19 @@ class ImageToolkitTestCase extends DrupalWebTestCase {
// Determine if there were any expected that were not called.
$uncalled = array_diff($expected, $actual);
if (count($uncalled)) {
$this->assertTrue(FALSE, t('Expected operations %expected to be called but %uncalled was not called.', array('%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled))));
$this->assertTrue(FALSE, format_string('Expected operations %expected to be called but %uncalled was not called.', array('%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled))));
}
else {
$this->assertTrue(TRUE, t('All the expected operations were called: %expected', array('%expected' => implode(', ', $expected))));
$this->assertTrue(TRUE, format_string('All the expected operations were called: %expected', array('%expected' => implode(', ', $expected))));
}
// Determine if there were any unexpected calls.
$unexpected = array_diff($actual, $expected);
if (count($unexpected)) {
$this->assertTrue(FALSE, t('Unexpected operations were called: %unexpected.', array('%unexpected' => implode(', ', $unexpected))));
$this->assertTrue(FALSE, format_string('Unexpected operations were called: %unexpected.', array('%unexpected' => implode(', ', $unexpected))));
}
else {
$this->assertTrue(TRUE, t('No unexpected operations were called.'));
$this->assertTrue(TRUE, 'No unexpected operations were called.');
}
}
}
@@ -90,8 +90,8 @@ class ImageToolkitUnitTest extends ImageToolkitTestCase {
*/
function testGetAvailableToolkits() {
$toolkits = image_get_available_toolkits();
$this->assertTrue(isset($toolkits['test']), t('The working toolkit was returned.'));
$this->assertFalse(isset($toolkits['broken']), t('The toolkit marked unavailable was not returned'));
$this->assertTrue(isset($toolkits['test']), 'The working toolkit was returned.');
$this->assertFalse(isset($toolkits['broken']), 'The toolkit marked unavailable was not returned');
$this->assertToolkitOperationsCalled(array());
}
@@ -100,8 +100,8 @@ class ImageToolkitUnitTest extends ImageToolkitTestCase {
*/
function testLoad() {
$image = image_load($this->file, $this->toolkit);
$this->assertTrue(is_object($image), t('Returned an object.'));
$this->assertEqual($this->toolkit, $image->toolkit, t('Image had toolkit set.'));
$this->assertTrue(is_object($image), 'Returned an object.');
$this->assertEqual($this->toolkit, $image->toolkit, 'Image had toolkit set.');
$this->assertToolkitOperationsCalled(array('load', 'get_info'));
}
@@ -109,7 +109,7 @@ class ImageToolkitUnitTest extends ImageToolkitTestCase {
* Test the image_save() function.
*/
function testSave() {
$this->assertFalse(image_save($this->image), t('Function returned the expected value.'));
$this->assertFalse(image_save($this->image), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('save'));
}
@@ -117,13 +117,13 @@ class ImageToolkitUnitTest extends ImageToolkitTestCase {
* Test the image_resize() function.
*/
function testResize() {
$this->assertTrue(image_resize($this->image, 1, 2), t('Function returned the expected value.'));
$this->assertTrue(image_resize($this->image, 1, 2), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['resize'][0][1], 1, t('Width was passed correctly'));
$this->assertEqual($calls['resize'][0][2], 2, t('Height was passed correctly'));
$this->assertEqual($calls['resize'][0][1], 1, 'Width was passed correctly');
$this->assertEqual($calls['resize'][0][2], 2, 'Height was passed correctly');
}
/**
@@ -131,69 +131,69 @@ class ImageToolkitUnitTest extends ImageToolkitTestCase {
*/
function testScale() {
// TODO: need to test upscaling
$this->assertTrue(image_scale($this->image, 10, 10), t('Function returned the expected value.'));
$this->assertTrue(image_scale($this->image, 10, 10), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['resize'][0][1], 10, t('Width was passed correctly'));
$this->assertEqual($calls['resize'][0][2], 5, t('Height was based off aspect ratio and passed correctly'));
$this->assertEqual($calls['resize'][0][1], 10, 'Width was passed correctly');
$this->assertEqual($calls['resize'][0][2], 5, 'Height was based off aspect ratio and passed correctly');
}
/**
* Test the image_scale_and_crop() function.
*/
function testScaleAndCrop() {
$this->assertTrue(image_scale_and_crop($this->image, 5, 10), t('Function returned the expected value.'));
$this->assertTrue(image_scale_and_crop($this->image, 5, 10), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize', 'crop'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['crop'][0][1], 7.5, t('X was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][2], 0, t('Y was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][3], 5, t('Width was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][4], 10, t('Height was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][1], 7.5, 'X was computed and passed correctly');
$this->assertEqual($calls['crop'][0][2], 0, 'Y was computed and passed correctly');
$this->assertEqual($calls['crop'][0][3], 5, 'Width was computed and passed correctly');
$this->assertEqual($calls['crop'][0][4], 10, 'Height was computed and passed correctly');
}
/**
* Test the image_rotate() function.
*/
function testRotate() {
$this->assertTrue(image_rotate($this->image, 90, 1), t('Function returned the expected value.'));
$this->assertTrue(image_rotate($this->image, 90, 1), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('rotate'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['rotate'][0][1], 90, t('Degrees were passed correctly'));
$this->assertEqual($calls['rotate'][0][2], 1, t('Background color was passed correctly'));
$this->assertEqual($calls['rotate'][0][1], 90, 'Degrees were passed correctly');
$this->assertEqual($calls['rotate'][0][2], 1, 'Background color was passed correctly');
}
/**
* Test the image_crop() function.
*/
function testCrop() {
$this->assertTrue(image_crop($this->image, 1, 2, 3, 4), t('Function returned the expected value.'));
$this->assertTrue(image_crop($this->image, 1, 2, 3, 4), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('crop'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['crop'][0][1], 1, t('X was passed correctly'));
$this->assertEqual($calls['crop'][0][2], 2, t('Y was passed correctly'));
$this->assertEqual($calls['crop'][0][3], 3, t('Width was passed correctly'));
$this->assertEqual($calls['crop'][0][4], 4, t('Height was passed correctly'));
$this->assertEqual($calls['crop'][0][1], 1, 'X was passed correctly');
$this->assertEqual($calls['crop'][0][2], 2, 'Y was passed correctly');
$this->assertEqual($calls['crop'][0][3], 3, 'Width was passed correctly');
$this->assertEqual($calls['crop'][0][4], 4, 'Height was passed correctly');
}
/**
* Test the image_desaturate() function.
*/
function testDesaturate() {
$this->assertTrue(image_desaturate($this->image), t('Function returned the expected value.'));
$this->assertTrue(image_desaturate($this->image), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('desaturate'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual(count($calls['desaturate'][0]), 1, t('Only the image was passed.'));
$this->assertEqual(count($calls['desaturate'][0]), 1, 'Only the image was passed.');
}
}
@@ -207,9 +207,11 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
protected $green = array(0, 255, 0, 0);
protected $blue = array(0, 0, 255, 0);
protected $yellow = array(255, 255, 0, 0);
protected $fuchsia = array(255, 0, 255, 0); // Used as background colors.
protected $transparent = array(0, 0, 0, 127);
protected $white = array(255, 255, 255, 0);
protected $transparent = array(0, 0, 0, 127);
// Used as rotate background colors.
protected $fuchsia = array(255, 0, 255, 0);
protected $rotate_transparent = array(255, 255, 255, 127);
protected $width = 40;
protected $height = 20;
@@ -261,6 +263,7 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
*/
function testManipulations() {
// If GD isn't available don't bother testing this.
module_load_include('inc', 'system', 'image.gd');
if (!function_exists('image_gd_check_settings') || !image_gd_check_settings()) {
$this->pass(t('Image manipulations for the GD toolkit were skipped because the GD toolkit is not available.'));
return;
@@ -274,6 +277,7 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
$files = array(
'image-test.png',
'image-test.gif',
'image-test-no-transparency.gif',
'image-test.jpg',
);
@@ -331,15 +335,10 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
);
// Systems using non-bundled GD2 don't have imagerotate. Test if available.
if (function_exists('imagerotate')) {
// @todo Remove the version check once https://www.drupal.org/node/2918570
// is resolved.
if (function_exists('imagerotate') && (version_compare(PHP_VERSION, '7.0.26', '<') || (version_compare(PHP_VERSION, '7.1', '>=') && version_compare(PHP_VERSION, '7.1.12', '<')))) {
$operations += array(
'rotate_5' => array(
'function' => 'rotate',
'arguments' => array(5, 0xFF00FF), // Fuchsia background.
'width' => 42,
'height' => 24,
'corners' => array_fill(0, 4, $this->fuchsia),
),
'rotate_90' => array(
'function' => 'rotate',
'arguments' => array(90, 0xFF00FF), // Fuchsia background.
@@ -347,13 +346,6 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
'height' => 40,
'corners' => array($this->fuchsia, $this->red, $this->green, $this->blue),
),
'rotate_transparent_5' => array(
'function' => 'rotate',
'arguments' => array(5),
'width' => 42,
'height' => 24,
'corners' => array_fill(0, 4, $this->transparent),
),
'rotate_transparent_90' => array(
'function' => 'rotate',
'arguments' => array(90),
@@ -362,6 +354,49 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
'corners' => array($this->transparent, $this->red, $this->green, $this->blue),
),
);
// As of PHP version 5.5, GD uses a different algorithm to rotate images
// than version 5.4 and below, resulting in different dimensions.
// See https://bugs.php.net/bug.php?id=65148.
// For the 40x20 test images, the dimensions resulting from rotation will
// be 1 pixel smaller in both width and height in PHP 5.5 and above.
// @todo: The PHP bug was fixed in PHP 7.0.26 and 7.1.12. Change the code
// below to reflect that in https://www.drupal.org/node/2918570.
if (version_compare(PHP_VERSION, '5.5', '>=')) {
$operations += array(
'rotate_5' => array(
'function' => 'rotate',
'arguments' => array(5, 0xFF00FF), // Fuchsia background.
'width' => 41,
'height' => 23,
'corners' => array_fill(0, 4, $this->fuchsia),
),
'rotate_transparent_5' => array(
'function' => 'rotate',
'arguments' => array(5),
'width' => 41,
'height' => 23,
'corners' => array_fill(0, 4, $this->rotate_transparent),
),
);
}
else {
$operations += array(
'rotate_5' => array(
'function' => 'rotate',
'arguments' => array(5, 0xFF00FF), // Fuchsia background.
'width' => 42,
'height' => 24,
'corners' => array_fill(0, 4, $this->fuchsia),
),
'rotate_transparent_5' => array(
'function' => 'rotate',
'arguments' => array(5),
'width' => 42,
'height' => 24,
'corners' => array_fill(0, 4, $this->rotate_transparent),
),
);
}
}
// Systems using non-bundled GD2 don't have imagefilter. Test if available.
@@ -379,7 +414,7 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
array_fill(0, 3, 76) + array(3 => 0),
array_fill(0, 3, 149) + array(3 => 0),
array_fill(0, 3, 29) + array(3 => 0),
array_fill(0, 3, 0) + array(3 => 127)
array_fill(0, 3, 225) + array(3 => 127)
),
),
);
@@ -394,11 +429,14 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
continue 2;
}
// Transparent GIFs and the imagefilter function don't work together.
// There is a todo in image.gd.inc to correct this.
// All images should be converted to truecolor when loaded.
$image_truecolor = imageistruecolor($image->resource);
$this->assertTrue($image_truecolor, format_string('Image %file after load is a truecolor image.', array('%file' => $file)));
if ($image->info['extension'] == 'gif') {
if ($op == 'desaturate') {
$values['corners'][3] = $this->white;
// Transparent GIFs and the imagefilter function don't work together.
$values['corners'][3][3] = 0;
}
}
@@ -426,6 +464,11 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
}
// Now check each of the corners to ensure color correctness.
foreach ($values['corners'] as $key => $corner) {
// The test gif that does not have transparency has yellow where the
// others have transparent.
if ($file === 'image-test-no-transparency.gif' && $corner === $this->transparent) {
$corner = $this->yellow;
}
// Get the location of the corner.
switch ($key) {
case 0:
@@ -451,17 +494,47 @@ class ImageToolkitGdTestCase extends DrupalWebTestCase {
$directory = file_default_scheme() . '://imagetests';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
image_save($image, $directory . '/' . $op . '.' . $image->info['extension']);
$file_path = $directory . '/' . $op . '.' . $image->info['extension'];
image_save($image, $file_path);
$this->assertTrue($correct_dimensions_real, t('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op)));
$this->assertTrue($correct_dimensions_object, t('Image %file object after %action action is reporting the proper height and width values.', array('%file' => $file, '%action' => $op)));
$this->assertTrue($correct_dimensions_real, format_string('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op)));
$this->assertTrue($correct_dimensions_object, format_string('Image %file object after %action action is reporting the proper height and width values.', array('%file' => $file, '%action' => $op)));
// JPEG colors will always be messed up due to compression.
if ($image->info['extension'] != 'jpg') {
$this->assertTrue($correct_colors, t('Image %file object after %action action has the correct color placement.', array('%file' => $file, '%action' => $op)));
$this->assertTrue($correct_colors, format_string('Image %file object after %action action has the correct color placement.', array('%file' => $file, '%action' => $op)));
}
}
}
// Check that saved image reloads without raising PHP errors.
$image_reloaded = image_load($file_path);
}
}
/**
* Tests loading an image whose transparent color index is out of range.
*/
function testTransparentColorOutOfRange() {
// This image was generated by taking an initial image with a palette size
// of 6 colors, and setting the transparent color index to 6 (one higher
// than the largest allowed index), as follows:
// @code
// $image = imagecreatefromgif('modules/simpletest/files/image-test.gif');
// imagecolortransparent($image, 6);
// imagegif($image, 'modules/simpletest/files/image-test-transparent-out-of-range.gif');
// @endcode
// This allows us to test that an image with an out-of-range color index
// can be loaded correctly.
$file = 'image-test-transparent-out-of-range.gif';
$image = image_load(drupal_get_path('module', 'simpletest') . '/files/' . $file);
if (!$image) {
$this->fail(format_string('Could not load image %file.', array('%file' => $file)));
}
else {
// All images should be converted to truecolor when loaded.
$image_truecolor = imageistruecolor($image->resource);
$this->assertTrue($image_truecolor, format_string('Image %file after load is a truecolor image.', array('%file' => $file)));
}
}
}
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+10 -10
View File
@@ -23,35 +23,35 @@ class LockFunctionalTest extends DrupalWebTestCase {
function testLockAcquire() {
$lock_acquired = 'TRUE: Lock successfully acquired in system_test_lock_acquire()';
$lock_not_acquired = 'FALSE: Lock not acquired in system_test_lock_acquire()';
$this->assertTrue(lock_acquire('system_test_lock_acquire'), t('Lock acquired by this request.'), t('Lock'));
$this->assertTrue(lock_acquire('system_test_lock_acquire'), t('Lock extended by this request.'), t('Lock'));
$this->assertTrue(lock_acquire('system_test_lock_acquire'), 'Lock acquired by this request.', 'Lock');
$this->assertTrue(lock_acquire('system_test_lock_acquire'), 'Lock extended by this request.', 'Lock');
lock_release('system_test_lock_acquire');
// Cause another request to acquire the lock.
$this->drupalGet('system-test/lock-acquire');
$this->assertText($lock_acquired, t('Lock acquired by the other request.'), t('Lock'));
$this->assertText($lock_acquired, 'Lock acquired by the other request.', 'Lock');
// The other request has finished, thus it should have released its lock.
$this->assertTrue(lock_acquire('system_test_lock_acquire'), t('Lock acquired by this request.'), t('Lock'));
$this->assertTrue(lock_acquire('system_test_lock_acquire'), 'Lock acquired by this request.', 'Lock');
// This request holds the lock, so the other request cannot acquire it.
$this->drupalGet('system-test/lock-acquire');
$this->assertText($lock_not_acquired, t('Lock not acquired by the other request.'), t('Lock'));
$this->assertText($lock_not_acquired, 'Lock not acquired by the other request.', 'Lock');
lock_release('system_test_lock_acquire');
// Try a very short timeout and lock breaking.
$this->assertTrue(lock_acquire('system_test_lock_acquire', 0.5), t('Lock acquired by this request.'), t('Lock'));
$this->assertTrue(lock_acquire('system_test_lock_acquire', 0.5), 'Lock acquired by this request.', 'Lock');
sleep(1);
// The other request should break our lock.
$this->drupalGet('system-test/lock-acquire');
$this->assertText($lock_acquired, t('Lock acquired by the other request, breaking our lock.'), t('Lock'));
$this->assertText($lock_acquired, 'Lock acquired by the other request, breaking our lock.', 'Lock');
// We cannot renew it, since the other thread took it.
$this->assertFalse(lock_acquire('system_test_lock_acquire'), t('Lock cannot be extended by this request.'), t('Lock'));
$this->assertFalse(lock_acquire('system_test_lock_acquire'), 'Lock cannot be extended by this request.', 'Lock');
// Check the shut-down function.
$lock_acquired_exit = 'TRUE: Lock successfully acquired in system_test_lock_exit()';
$lock_not_acquired_exit = 'FALSE: Lock not acquired in system_test_lock_exit()';
$this->drupalGet('system-test/lock-exit');
$this->assertText($lock_acquired_exit, t('Lock acquired by the other request before exit.'), t('Lock'));
$this->assertTrue(lock_acquire('system_test_lock_exit'), t('Lock acquired by this request after the other request exits.'), t('Lock'));
$this->assertText($lock_acquired_exit, 'Lock acquired by the other request before exit.', 'Lock');
$this->assertTrue(lock_acquire('system_test_lock_exit'), 'Lock acquired by this request after the other request exits.', 'Lock');
}
}
+28 -4
View File
@@ -38,7 +38,7 @@ class MailTestCase extends DrupalWebTestCase implements MailSystemInterface {
$message = drupal_mail('simpletest', 'mail_test', 'testing@example.com', $language);
// Assert whether the message was sent through the send function.
$this->assertEqual(self::$sent_message['to'], 'testing@example.com', t('Pluggable mail system is extendable.'));
$this->assertEqual(self::$sent_message['to'], 'testing@example.com', 'Pluggable mail system is extendable.');
}
/**
@@ -267,6 +267,31 @@ class DrupalHtmlToTextTestCase extends DrupalWebTestCase {
);
}
/**
* Tests that drupal_wrap_mail() removes trailing whitespace before newlines.
*/
function testDrupalHtmltoTextRemoveTrailingWhitespace() {
$text = "Hi there! \nHerp Derp";
$mail_lines = explode("\n", drupal_wrap_mail($text));
$this->assertNotEqual(" ", substr($mail_lines[0], -1), 'Trailing whitespace removed.');
}
/**
* Tests drupal_wrap_mail() retains whitespace from Usenet style signatures.
*
* RFC 3676 says, "This is a special case; an (optionally quoted or quoted and
* stuffed) line consisting of DASH DASH SP is neither fixed nor flowed."
*/
function testDrupalHtmltoTextUsenetSignature() {
$text = "Hi there!\n-- \nHerp Derp";
$mail_lines = explode("\n", drupal_wrap_mail($text));
$this->assertEqual("-- ", $mail_lines[1], 'Trailing whitespace not removed for dash-dash-space signatures.');
$text = "Hi there!\n-- \nHerp Derp";
$mail_lines = explode("\n", drupal_wrap_mail($text));
$this->assertEqual("--", $mail_lines[1], 'Trailing whitespace removed for incorrect dash-dash-space signatures.');
}
/**
* Test that whitespace is collapsed.
*/
@@ -416,7 +441,7 @@ class DrupalHtmlToTextTestCase extends DrupalWebTestCase {
* <CRLF> is 1000 characters."
*/
function testVeryLongLineWrap() {
$input = 'Drupal<br /><p>' . str_repeat('x', 2100) . '</><br />Drupal';
$input = 'Drupal<br /><p>' . str_repeat('x', 2100) . '</p><br />Drupal';
$output = drupal_html_to_text($input);
// This awkward construct comes from includes/mail.inc lines 8-13.
$eol = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
@@ -430,7 +455,6 @@ class DrupalHtmlToTextTestCase extends DrupalWebTestCase {
$maximum_line_length = max($maximum_line_length, strlen($line . $eol));
}
$verbose = 'Maximum line length found was ' . $maximum_line_length . ' octets.';
// @todo This should assert that $maximum_line_length <= 1000.
$this->pass($verbose);
$this->assertTrue($maximum_line_length <= 1000, $verbose);
}
}
+94 -94
View File
@@ -48,7 +48,7 @@ class MenuWebTestCase extends DrupalWebTestCase {
// No parts must be left, or an expected "Home" will always pass.
$pass = ($pass && empty($parts));
$this->assertTrue($pass, t('Breadcrumb %parts found on @path.', array(
$this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', array(
'%parts' => implode(' » ', $trail),
'@path' => $this->getUrl(),
)));
@@ -78,7 +78,7 @@ class MenuWebTestCase extends DrupalWebTestCase {
$i++;
}
$elements = $this->xpath($xpath);
$this->assertTrue(!empty($elements), t('Active trail to current page was found in menu tree.'));
$this->assertTrue(!empty($elements), 'Active trail to current page was found in menu tree.');
// Append prefix for active link asserted below.
$xpath .= '/following-sibling::ul/descendant::';
@@ -95,7 +95,7 @@ class MenuWebTestCase extends DrupalWebTestCase {
':title' => $active_link_title,
);
$elements = $this->xpath($xpath, $args);
$this->assertTrue(!empty($elements), t('Active link %title was found in menu tree, including active trail links %tree.', array(
$this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', array(
'%title' => $active_link_title,
'%tree' => implode(' » ', $tree),
)));
@@ -145,8 +145,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
*/
function testTitleCallbackFalse() {
$this->drupalGet('node');
$this->assertText('A title with @placeholder', t('Raw text found on the page'));
$this->assertNoText(t('A title with @placeholder', array('@placeholder' => 'some other text')), t('Text with placeholder substitutions not found.'));
$this->assertText('A title with @placeholder', 'Raw text found on the page');
$this->assertNoText(t('A title with @placeholder', array('@placeholder' => 'some other text')), 'Text with placeholder substitutions not found.');
}
/**
@@ -166,8 +166,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
*/
function testThemeCallbackAdministrative() {
$this->drupalGet('menu-test/theme-callback/use-admin-theme');
$this->assertText('Custom theme: seven. Actual theme: seven.', t('The administrative theme can be correctly set in a theme callback.'));
$this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page."));
$this->assertText('Custom theme: seven. Actual theme: seven.', 'The administrative theme can be correctly set in a theme callback.');
$this->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page.");
}
/**
@@ -175,8 +175,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
*/
function testThemeCallbackInheritance() {
$this->drupalGet('menu-test/theme-callback/use-admin-theme/inheritance');
$this->assertText('Custom theme: seven. Actual theme: seven. Theme callback inheritance is being tested.', t('Theme callback inheritance correctly uses the administrative theme.'));
$this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page."));
$this->assertText('Custom theme: seven. Actual theme: seven. Theme callback inheritance is being tested.', 'Theme callback inheritance correctly uses the administrative theme.');
$this->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page.");
}
/**
@@ -185,7 +185,7 @@ class MenuRouterTestCase extends DrupalWebTestCase {
*/
function testFileInheritance() {
$this->drupalGet('admin/config/development/file-inheritance');
$this->assertText('File inheritance test description', t('File inheritance works.'));
$this->assertText('File inheritance test description', 'File inheritance works.');
}
/**
@@ -208,14 +208,14 @@ class MenuRouterTestCase extends DrupalWebTestCase {
// For a regular user, the fact that the site is in maintenance mode means
// we expect the theme callback system to be bypassed entirely.
$this->drupalGet('menu-test/theme-callback/use-admin-theme');
$this->assertRaw('bartik/css/style.css', t("The maintenance theme's CSS appears on the page."));
$this->assertRaw('bartik/css/style.css', "The maintenance theme's CSS appears on the page.");
// An administrator, however, should continue to see the requested theme.
$admin_user = $this->drupalCreateUser(array('access site in maintenance mode'));
$this->drupalLogin($admin_user);
$this->drupalGet('menu-test/theme-callback/use-admin-theme');
$this->assertText('Custom theme: seven. Actual theme: seven.', t('The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.'));
$this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page."));
$this->assertText('Custom theme: seven. Actual theme: seven.', 'The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.');
$this->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page.");
}
/**
@@ -244,11 +244,11 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$this->drupalGet('user/login');
// Check that we got to 'user'.
$this->assertTrue($this->url == url('user', array('absolute' => TRUE)), t("Logged-in user redirected to q=user on accessing q=user/login"));
$this->assertTrue($this->url == url('user', array('absolute' => TRUE)), "Logged-in user redirected to q=user on accessing q=user/login");
// user/register should redirect to user/UID/edit.
$this->drupalGet('user/register');
$this->assertTrue($this->url == url('user/' . $this->loggedInUser->uid . '/edit', array('absolute' => TRUE)), t("Logged-in user redirected to q=user/UID/edit on accessing q=user/register"));
$this->assertTrue($this->url == url('user/' . $this->loggedInUser->uid . '/edit', array('absolute' => TRUE)), "Logged-in user redirected to q=user/UID/edit on accessing q=user/register");
}
/**
@@ -257,14 +257,14 @@ class MenuRouterTestCase extends DrupalWebTestCase {
function testThemeCallbackOptionalTheme() {
// Request a theme that is not enabled.
$this->drupalGet('menu-test/theme-callback/use-stark-theme');
$this->assertText('Custom theme: NONE. Actual theme: bartik.', t('The theme callback system falls back on the default theme when a theme that is not enabled is requested.'));
$this->assertRaw('bartik/css/style.css', t("The default theme's CSS appears on the page."));
$this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that is not enabled is requested.');
$this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");
// Now enable the theme and request it again.
theme_enable(array('stark'));
$this->drupalGet('menu-test/theme-callback/use-stark-theme');
$this->assertText('Custom theme: stark. Actual theme: stark.', t('The theme callback system uses an optional theme once it has been enabled.'));
$this->assertRaw('stark/layout.css', t("The optional theme's CSS appears on the page."));
$this->assertText('Custom theme: stark. Actual theme: stark.', 'The theme callback system uses an optional theme once it has been enabled.');
$this->assertRaw('stark/layout.css', "The optional theme's CSS appears on the page.");
}
/**
@@ -272,8 +272,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
*/
function testThemeCallbackFakeTheme() {
$this->drupalGet('menu-test/theme-callback/use-fake-theme');
$this->assertText('Custom theme: NONE. Actual theme: bartik.', t('The theme callback system falls back on the default theme when a theme that does not exist is requested.'));
$this->assertRaw('bartik/css/style.css', t("The default theme's CSS appears on the page."));
$this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that does not exist is requested.');
$this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");
}
/**
@@ -281,8 +281,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
*/
function testThemeCallbackNoThemeRequested() {
$this->drupalGet('menu-test/theme-callback/no-theme-requested');
$this->assertText('Custom theme: NONE. Actual theme: bartik.', t('The theme callback system falls back on the default theme when no theme is requested.'));
$this->assertRaw('bartik/css/style.css', t("The default theme's CSS appears on the page."));
$this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when no theme is requested.');
$this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");
}
/**
@@ -297,8 +297,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
// Visit a page that does not implement a theme callback. The above request
// should be honored.
$this->drupalGet('menu-test/no-theme-callback');
$this->assertText('Custom theme: stark. Actual theme: stark.', t('The result of hook_custom_theme() is used as the theme for the current page.'));
$this->assertRaw('stark/layout.css', t("The Stark theme's CSS appears on the page."));
$this->assertText('Custom theme: stark. Actual theme: stark.', 'The result of hook_custom_theme() is used as the theme for the current page.');
$this->assertRaw('stark/layout.css', "The Stark theme's CSS appears on the page.");
}
/**
@@ -313,8 +313,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
// The menu "theme callback" should take precedence over a value set in
// hook_custom_theme().
$this->drupalGet('menu-test/theme-callback/use-admin-theme');
$this->assertText('Custom theme: seven. Actual theme: seven.', t('The result of hook_custom_theme() does not override what was set in a theme callback.'));
$this->assertRaw('seven/style.css', t("The Seven theme's CSS appears on the page."));
$this->assertText('Custom theme: seven. Actual theme: seven.', 'The result of hook_custom_theme() does not override what was set in a theme callback.');
$this->assertRaw('seven/style.css', "The Seven theme's CSS appears on the page.");
}
/**
@@ -348,19 +348,19 @@ class MenuRouterTestCase extends DrupalWebTestCase {
menu_link_maintain('menu_test', 'update', 'menu_test_maintain/1', 'Menu link updated');
// Load a different page to be sure that we have up to date information.
$this->drupalGet('menu_test_maintain/1');
$this->assertLink(t('Menu link updated'), 0, t('Found updated menu link'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1-1'));
$this->assertLink(t('Menu link #2'), 0, t('Found menu link #2'));
$this->assertLink(t('Menu link updated'), 0, 'Found updated menu link');
$this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1');
$this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1-1');
$this->assertLink(t('Menu link #2'), 0, 'Found menu link #2');
// Delete all links for the given path.
menu_link_maintain('menu_test', 'delete', 'menu_test_maintain/1', '');
// Load a different page to be sure that we have up to date information.
$this->drupalGet('menu_test_maintain/2');
$this->assertNoLink(t('Menu link updated'), 0, t('Not found deleted menu link'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1'));
$this->assertNoLink(t('Menu link #1'), 0, t('Not found menu link #1-1'));
$this->assertLink(t('Menu link #2'), 0, t('Found menu link #2'));
$this->assertNoLink(t('Menu link updated'), 0, 'Not found deleted menu link');
$this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1');
$this->assertNoLink(t('Menu link #1'), 0, 'Not found menu link #1-1');
$this->assertLink(t('Menu link #2'), 0, 'Found menu link #2');
}
/**
@@ -397,7 +397,7 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
$name = db_query($sql)->fetchField();
$this->assertEqual($name, 'original', t('Menu name is "original".'));
$this->assertEqual($name, 'original', 'Menu name is "original".');
// Change the menu_name parameter in menu_test.module, then force a menu
// rebuild.
@@ -406,7 +406,7 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'";
$name = db_query($sql)->fetchField();
$this->assertEqual($name, 'changed', t('Menu name was successfully changed after rebuild.'));
$this->assertEqual($name, 'changed', 'Menu name was successfully changed after rebuild.');
}
/**
@@ -417,8 +417,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child'))->fetchAssoc();
$unattached_child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child2/child'))->fetchAssoc();
$this->assertEqual($child_link['plid'], $parent_link['mlid'], t('The parent of a directly attached child is correct.'));
$this->assertEqual($unattached_child_link['plid'], $parent_link['mlid'], t('The parent of a non-directly attached child is correct.'));
$this->assertEqual($child_link['plid'], $parent_link['mlid'], 'The parent of a directly attached child is correct.');
$this->assertEqual($unattached_child_link['plid'], $parent_link['mlid'], 'The parent of a non-directly attached child is correct.');
}
/**
@@ -438,40 +438,40 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$plid = $parent['mlid'];
$link = $links['menu-test/hidden/menu/list'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/add'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/settings'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/manage/%'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$parent = $links['menu-test/hidden/menu/manage/%'];
$depth = $parent['depth'] + 1;
$plid = $parent['mlid'];
$link = $links['menu-test/hidden/menu/manage/%/list'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/manage/%/add'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/manage/%/edit'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/menu/manage/%/delete'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
// Verify links for two dynamic arguments.
$links = db_select('menu_links', 'ml')
@@ -486,28 +486,28 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$plid = $parent['mlid'];
$link = $links['menu-test/hidden/block/list'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/block/add'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/block/manage/%/%'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$parent = $links['menu-test/hidden/block/manage/%/%'];
$depth = $parent['depth'] + 1;
$plid = $parent['mlid'];
$link = $links['menu-test/hidden/block/manage/%/%/configure'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$link = $links['menu-test/hidden/block/manage/%/%/delete'];
$this->assertEqual($link['depth'], $depth, t('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, t('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
$this->assertEqual($link['depth'], $depth, format_string('%path depth @link_depth is equal to @depth.', array('%path' => $link['router_path'], '@link_depth' => $link['depth'], '@depth' => $depth)));
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
}
/**
@@ -524,7 +524,7 @@ class MenuRouterTestCase extends DrupalWebTestCase {
function testMenuSetItem() {
$item = menu_get_item('node');
$this->assertEqual($item['path'], 'node', t("Path from menu_get_item('node') is equal to 'node'"), 'menu');
$this->assertEqual($item['path'], 'node', "Path from menu_get_item('node') is equal to 'node'", 'menu');
// Modify the path for the item then save it.
$item['path'] = 'node_test';
@@ -532,7 +532,7 @@ class MenuRouterTestCase extends DrupalWebTestCase {
menu_set_item('node', $item);
$compare_item = menu_get_item('node');
$this->assertEqual($compare_item, $item, t('Modified menu item is equal to newly retrieved menu item.'), 'menu');
$this->assertEqual($compare_item, $item, 'Modified menu item is equal to newly retrieved menu item.', 'menu');
}
/**
@@ -541,13 +541,13 @@ class MenuRouterTestCase extends DrupalWebTestCase {
function testMenuItemHooks() {
// Create an item.
menu_link_maintain('menu_test', 'insert', 'menu_test_maintain/4', 'Menu link #4');
$this->assertEqual(menu_test_static_variable(), 'insert', t('hook_menu_link_insert() fired correctly'));
$this->assertEqual(menu_test_static_variable(), 'insert', 'hook_menu_link_insert() fired correctly');
// Update the item.
menu_link_maintain('menu_test', 'update', 'menu_test_maintain/4', 'Menu link updated');
$this->assertEqual(menu_test_static_variable(), 'update', t('hook_menu_link_update() fired correctly'));
$this->assertEqual(menu_test_static_variable(), 'update', 'hook_menu_link_update() fired correctly');
// Delete the item.
menu_link_maintain('menu_test', 'delete', 'menu_test_maintain/4', '');
$this->assertEqual(menu_test_static_variable(), 'delete', t('hook_menu_link_delete() fired correctly'));
$this->assertEqual(menu_test_static_variable(), 'delete', 'hook_menu_link_delete() fired correctly');
}
/**
@@ -572,8 +572,8 @@ class MenuRouterTestCase extends DrupalWebTestCase {
// Load front page.
$this->drupalGet('node');
$this->assertRaw('title="Test title attribute"', t('Title attribute of a menu link renders.'));
$this->assertRaw('testparam=testvalue', t('Query parameter added to menu link.'));
$this->assertRaw('title="Test title attribute"', 'Title attribute of a menu link renders.');
$this->assertRaw('testparam=testvalue', 'Query parameter added to menu link.');
}
/**
@@ -606,7 +606,7 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$this->drupalGet('menu-title-test/case' . $case_no);
$this->assertResponse(200);
$asserted_title = $override ? 'Alternative example title - Case ' . $case_no : 'Example title - Case ' . $case_no;
$this->assertTitle($asserted_title . ' | Drupal', t('Menu title is') . ': ' . $asserted_title, 'Menu');
$this->assertTitle($asserted_title . ' | Drupal', format_string('Menu title is: %title.', array('%title' => $asserted_title)), 'Menu');
}
/**
@@ -663,7 +663,7 @@ class MenuRouterTestCase extends DrupalWebTestCase {
foreach ($expected as $router_path => $load_functions) {
$router_item = $this->menuLoadRouter($router_path);
$this->assertIdentical(unserialize($router_item['load_functions']), $load_functions, t('Expected load functions for router %router_path' , array('%router_path' => $router_path)));
$this->assertIdentical(unserialize($router_item['load_functions']), $load_functions, format_string('Expected load functions for router %router_path' , array('%router_path' => $router_path)));
}
}
}
@@ -744,7 +744,7 @@ class MenuLinksUnitTestCase extends DrupalWebTestCase {
$menu_link = menu_link_load($mlid);
menu_link_save($menu_link);
$this->assertEqual($menu_link['plid'], $plid, t('Menu link %mlid has parent of %plid, expected %expected_plid.', array('%mlid' => $mlid, '%plid' => $menu_link['plid'], '%expected_plid' => $plid)));
$this->assertEqual($menu_link['plid'], $plid, format_string('Menu link %mlid has parent of %plid, expected %expected_plid.', array('%mlid' => $mlid, '%plid' => $menu_link['plid'], '%expected_plid' => $plid)));
}
}
@@ -905,14 +905,14 @@ class MenuRebuildTestCase extends DrupalWebTestCase {
function testMenuRebuildByVariable() {
// Check if 'admin' path exists.
$admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
$this->assertEqual($admin_exists, 'admin', t("The path 'admin/' exists prior to deleting."));
$this->assertEqual($admin_exists, 'admin', "The path 'admin/' exists prior to deleting.");
// Delete the path item 'admin', and test that the path doesn't exist in the database.
$delete = db_delete('menu_router')
->condition('path', 'admin')
->execute();
$admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
$this->assertFalse($admin_exists, t("The path 'admin/' has been deleted and doesn't exist in the database."));
$this->assertFalse($admin_exists, "The path 'admin/' has been deleted and doesn't exist in the database.");
// Now we enable the rebuild variable and trigger menu_execute_active_handler()
// to rebuild the menu item. Now 'admin' should exist.
@@ -920,7 +920,7 @@ class MenuRebuildTestCase extends DrupalWebTestCase {
// menu_execute_active_handler() should trigger the rebuild.
$this->drupalGet('<front>');
$admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
$this->assertEqual($admin_exists, 'admin', t("The menu has been rebuilt, the path 'admin' now exists again."));
$this->assertEqual($admin_exists, 'admin', "The menu has been rebuilt, the path 'admin' now exists again.");
}
}
@@ -955,12 +955,12 @@ class MenuTreeDataTestCase extends DrupalUnitTestCase {
$tree = menu_tree_data($this->links);
// Validate that parent items #1, #2, and #5 exist on the root level.
$this->assertSameLink($this->links[1], $tree[1]['link'], t('Parent item #1 exists.'));
$this->assertSameLink($this->links[2], $tree[2]['link'], t('Parent item #2 exists.'));
$this->assertSameLink($this->links[5], $tree[5]['link'], t('Parent item #5 exists.'));
$this->assertSameLink($this->links[1], $tree[1]['link'], 'Parent item #1 exists.');
$this->assertSameLink($this->links[2], $tree[2]['link'], 'Parent item #2 exists.');
$this->assertSameLink($this->links[5], $tree[5]['link'], 'Parent item #5 exists.');
// Validate that child item #4 exists at the correct location in the hierarchy.
$this->assertSameLink($this->links[4], $tree[2]['below'][3]['below'][4]['link'], t('Child item #4 exists in the hierarchy.'));
$this->assertSameLink($this->links[4], $tree[2]['below'][3]['below'][4]['link'], 'Child item #4 exists in the hierarchy.');
}
/**
@@ -976,7 +976,7 @@ class MenuTreeDataTestCase extends DrupalUnitTestCase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertSameLink($link1, $link2, $message = '') {
return $this->assert($link1['mlid'] == $link2['mlid'], $message ? $message : t('First link is identical to second link'));
return $this->assert($link1['mlid'] == $link2['mlid'], $message ? $message : 'First link is identical to second link');
}
}
@@ -1025,16 +1025,16 @@ class MenuTreeOutputTestCase extends DrupalWebTestCase {
$output = menu_tree_output($this->tree_data);
// Validate that the - in main-menu is changed into an underscore
$this->assertEqual( $output['1']['#theme'], 'menu_link__main_menu', t('Hyphen is changed to a dash on menu_link'));
$this->assertEqual( $output['#theme_wrappers'][0], 'menu_tree__main_menu', t('Hyphen is changed to a dash on menu_tree wrapper'));
$this->assertEqual($output['1']['#theme'], 'menu_link__main_menu', 'Hyphen is changed to an underscore on menu_link');
$this->assertEqual($output['#theme_wrappers'][0], 'menu_tree__main_menu', 'Hyphen is changed to an underscore on menu_tree wrapper');
// Looking for child items in the data
$this->assertEqual( $output['1']['#below']['2']['#href'], 'a/b', t('Checking the href on a child item'));
$this->assertTrue( in_array('active-trail',$output['1']['#below']['2']['#attributes']['class']) , t('Checking the active trail class'));
$this->assertEqual( $output['1']['#below']['2']['#href'], 'a/b', 'Checking the href on a child item');
$this->assertTrue( in_array('active-trail',$output['1']['#below']['2']['#attributes']['class']) , 'Checking the active trail class');
// Validate that the hidden and no access items are missing
$this->assertFalse( isset($output['5']), t('Hidden item should be missing'));
$this->assertFalse( isset($output['6']), t('False access should be missing'));
$this->assertFalse( isset($output['5']), 'Hidden item should be missing');
$this->assertFalse( isset($output['6']), 'False access should be missing');
// Item 7 is after a couple hidden items. Just to make sure that 5 and 6 are skipped and 7 still included
$this->assertTrue( isset($output['7']), t('Item after hidden items is present'));
$this->assertTrue( isset($output['7']), 'Item after hidden items is present');
}
}
@@ -1698,13 +1698,13 @@ class MenuTrailTestCase extends MenuWebTestCase {
// Check that the initial trail (during the Drupal bootstrap) matches
// what we expect.
$initial_trail = variable_get('menu_test_active_trail_initial', array());
$this->assertEqual(count($initial_trail), count($expected_trail[$status_code]['initial']), t('The initial active trail for a @status_code page contains the expected number of items (expected: @expected, found: @found).', array(
$this->assertEqual(count($initial_trail), count($expected_trail[$status_code]['initial']), format_string('The initial active trail for a @status_code page contains the expected number of items (expected: @expected, found: @found).', array(
'@status_code' => $status_code,
'@expected' => count($expected_trail[$status_code]['initial']),
'@found' => count($initial_trail),
)));
foreach (array_keys($expected_trail[$status_code]['initial']) as $index => $path) {
$this->assertEqual($initial_trail[$index]['href'], $path, t('Element number @number of the initial active trail for a @status_code page contains the correct path (expected: @expected, found: @found)', array(
$this->assertEqual($initial_trail[$index]['href'], $path, format_string('Element number @number of the initial active trail for a @status_code page contains the correct path (expected: @expected, found: @found)', array(
'@number' => $index + 1,
'@status_code' => $status_code,
'@expected' => $path,
@@ -1715,13 +1715,13 @@ class MenuTrailTestCase extends MenuWebTestCase {
// Check that the final trail (after the user has been redirected to the
// custom 403/404 page) matches what we expect.
$final_trail = variable_get('menu_test_active_trail_final', array());
$this->assertEqual(count($final_trail), count($expected_trail[$status_code]['final']), t('The final active trail for a @status_code page contains the expected number of items (expected: @expected, found: @found).', array(
$this->assertEqual(count($final_trail), count($expected_trail[$status_code]['final']), format_string('The final active trail for a @status_code page contains the expected number of items (expected: @expected, found: @found).', array(
'@status_code' => $status_code,
'@expected' => count($expected_trail[$status_code]['final']),
'@found' => count($final_trail),
)));
foreach (array_keys($expected_trail[$status_code]['final']) as $index => $path) {
$this->assertEqual($final_trail[$index]['href'], $path, t('Element number @number of the final active trail for a @status_code page contains the correct path (expected: @expected, found: @found)', array(
$this->assertEqual($final_trail[$index]['href'], $path, format_string('Element number @number of the final active trail for a @status_code page contains the correct path (expected: @expected, found: @found)', array(
'@number' => $index + 1,
'@status_code' => $status_code,
'@expected' => $path,
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+83 -41
View File
@@ -76,9 +76,9 @@ class ModuleUnitTest extends DrupalWebTestCase {
*/
protected function assertModuleList(Array $expected_values, $condition) {
$expected_values = array_combine($expected_values, $expected_values);
$this->assertEqual($expected_values, module_list(), t('@condition: module_list() returns correct results', array('@condition' => $condition)));
$this->assertEqual($expected_values, module_list(), format_string('@condition: module_list() returns correct results', array('@condition' => $condition)));
ksort($expected_values);
$this->assertIdentical($expected_values, module_list(FALSE, FALSE, TRUE), t('@condition: module_list() returns correctly sorted results', array('@condition' => $condition)));
$this->assertIdentical($expected_values, module_list(FALSE, FALSE, TRUE), format_string('@condition: module_list() returns correctly sorted results', array('@condition' => $condition)));
}
/**
@@ -87,16 +87,16 @@ class ModuleUnitTest extends DrupalWebTestCase {
function testModuleImplements() {
// Clear the cache.
cache_clear_all('module_implements', 'cache_bootstrap');
$this->assertFalse(cache_get('module_implements', 'cache_bootstrap'), t('The module implements cache is empty.'));
$this->assertFalse(cache_get('module_implements', 'cache_bootstrap'), 'The module implements cache is empty.');
$this->drupalGet('');
$this->assertTrue(cache_get('module_implements', 'cache_bootstrap'), t('The module implements cache is populated after requesting a page.'));
$this->assertTrue(cache_get('module_implements', 'cache_bootstrap'), 'The module implements cache is populated after requesting a page.');
// Test again with an authenticated user.
$this->user = $this->drupalCreateUser();
$this->drupalLogin($this->user);
cache_clear_all('module_implements', 'cache_bootstrap');
$this->drupalGet('');
$this->assertTrue(cache_get('module_implements', 'cache_bootstrap'), t('The module implements cache is populated after requesting a page.'));
$this->assertTrue(cache_get('module_implements', 'cache_bootstrap'), 'The module implements cache is populated after requesting a page.');
// Make sure group include files are detected properly even when the file is
// already loaded when the cache is rebuilt.
@@ -117,7 +117,7 @@ class ModuleUnitTest extends DrupalWebTestCase {
module_enable(array('module_test'), FALSE);
$this->resetAll();
$this->drupalGet('module-test/hook-dynamic-loading-invoke');
$this->assertText('success!', t('module_invoke() dynamically loads a hook defined in hook_hook_info().'));
$this->assertText('success!', 'module_invoke() dynamically loads a hook defined in hook_hook_info().');
}
/**
@@ -127,7 +127,7 @@ class ModuleUnitTest extends DrupalWebTestCase {
module_enable(array('module_test'), FALSE);
$this->resetAll();
$this->drupalGet('module-test/hook-dynamic-loading-invoke-all');
$this->assertText('success!', t('module_invoke_all() dynamically loads a hook defined in hook_hook_info().'));
$this->assertText('success!', 'module_invoke_all() dynamically loads a hook defined in hook_hook_info().');
}
/**
@@ -138,79 +138,79 @@ class ModuleUnitTest extends DrupalWebTestCase {
// are not already enabled. (If they were, the tests below would not work
// correctly.)
module_enable(array('module_test'), FALSE);
$this->assertTrue(module_exists('module_test'), t('Test module is enabled.'));
$this->assertFalse(module_exists('forum'), t('Forum module is disabled.'));
$this->assertFalse(module_exists('poll'), t('Poll module is disabled.'));
$this->assertFalse(module_exists('php'), t('PHP module is disabled.'));
$this->assertTrue(module_exists('module_test'), 'Test module is enabled.');
$this->assertFalse(module_exists('forum'), 'Forum module is disabled.');
$this->assertFalse(module_exists('poll'), 'Poll module is disabled.');
$this->assertFalse(module_exists('php'), 'PHP module is disabled.');
// First, create a fake missing dependency. Forum depends on poll, which
// depends on a made-up module, foo. Nothing should be installed.
variable_set('dependency_test', 'missing dependency');
drupal_static_reset('system_rebuild_module_data');
$result = module_enable(array('forum'));
$this->assertFalse($result, t('module_enable() returns FALSE if dependencies are missing.'));
$this->assertFalse(module_exists('forum'), t('module_enable() aborts if dependencies are missing.'));
$this->assertFalse($result, 'module_enable() returns FALSE if dependencies are missing.');
$this->assertFalse(module_exists('forum'), 'module_enable() aborts if dependencies are missing.');
// Now, fix the missing dependency. Forum module depends on poll, but poll
// depends on the PHP module. module_enable() should work.
variable_set('dependency_test', 'dependency');
drupal_static_reset('system_rebuild_module_data');
$result = module_enable(array('forum'));
$this->assertTrue($result, t('module_enable() returns the correct value.'));
$this->assertTrue($result, 'module_enable() returns the correct value.');
// Verify that the fake dependency chain was installed.
$this->assertTrue(module_exists('poll') && module_exists('php'), t('Dependency chain was installed by module_enable().'));
$this->assertTrue(module_exists('poll') && module_exists('php'), 'Dependency chain was installed by module_enable().');
// Verify that the original module was installed.
$this->assertTrue(module_exists('forum'), t('Module installation with unlisted dependencies succeeded.'));
$this->assertTrue(module_exists('forum'), 'Module installation with unlisted dependencies succeeded.');
// Finally, verify that the modules were enabled in the correct order.
$this->assertEqual(variable_get('test_module_enable_order', array()), array('php', 'poll', 'forum'), t('Modules were enabled in the correct order by module_enable().'));
$this->assertEqual(variable_get('test_module_enable_order', array()), array('php', 'poll', 'forum'), 'Modules were enabled in the correct order by module_enable().');
// Now, disable the PHP module. Both forum and poll should be disabled as
// well, in the correct order.
module_disable(array('php'));
$this->assertTrue(!module_exists('forum') && !module_exists('poll'), t('Depedency chain was disabled by module_disable().'));
$this->assertFalse(module_exists('php'), t('Disabling a module with unlisted dependents succeeded.'));
$this->assertEqual(variable_get('test_module_disable_order', array()), array('forum', 'poll', 'php'), t('Modules were disabled in the correct order by module_disable().'));
$this->assertTrue(!module_exists('forum') && !module_exists('poll'), 'Depedency chain was disabled by module_disable().');
$this->assertFalse(module_exists('php'), 'Disabling a module with unlisted dependents succeeded.');
$this->assertEqual(variable_get('test_module_disable_order', array()), array('forum', 'poll', 'php'), 'Modules were disabled in the correct order by module_disable().');
// Disable a module that is listed as a dependency by the installation
// profile. Make sure that the profile itself is not on the list of
// dependent modules to be disabled.
$profile = drupal_get_profile();
$info = install_profile_info($profile);
$this->assertTrue(in_array('comment', $info['dependencies']), t('Comment module is listed as a dependency of the installation profile.'));
$this->assertTrue(module_exists('comment'), t('Comment module is enabled.'));
$this->assertTrue(in_array('comment', $info['dependencies']), 'Comment module is listed as a dependency of the installation profile.');
$this->assertTrue(module_exists('comment'), 'Comment module is enabled.');
module_disable(array('comment'));
$this->assertFalse(module_exists('comment'), t('Comment module was disabled.'));
$this->assertFalse(module_exists('comment'), 'Comment module was disabled.');
$disabled_modules = variable_get('test_module_disable_order', array());
$this->assertTrue(in_array('comment', $disabled_modules), t('Comment module is in the list of disabled modules.'));
$this->assertFalse(in_array($profile, $disabled_modules), t('The installation profile is not in the list of disabled modules.'));
$this->assertTrue(in_array('comment', $disabled_modules), 'Comment module is in the list of disabled modules.');
$this->assertFalse(in_array($profile, $disabled_modules), 'The installation profile is not in the list of disabled modules.');
// Try to uninstall the PHP module by itself. This should be rejected,
// since the modules which it depends on need to be uninstalled first, and
// that is too destructive to perform automatically.
$result = drupal_uninstall_modules(array('php'));
$this->assertFalse($result, t('Calling drupal_uninstall_modules() on a module whose dependents are not uninstalled fails.'));
$this->assertFalse($result, 'Calling drupal_uninstall_modules() on a module whose dependents are not uninstalled fails.');
foreach (array('forum', 'poll', 'php') as $module) {
$this->assertNotEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, t('The @module module was not uninstalled.', array('@module' => $module)));
$this->assertNotEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, format_string('The @module module was not uninstalled.', array('@module' => $module)));
}
// Now uninstall all three modules explicitly, but in the incorrect order,
// and make sure that drupal_uninstal_modules() uninstalled them in the
// correct sequence.
$result = drupal_uninstall_modules(array('poll', 'php', 'forum'));
$this->assertTrue($result, t('drupal_uninstall_modules() returns the correct value.'));
$this->assertTrue($result, 'drupal_uninstall_modules() returns the correct value.');
foreach (array('forum', 'poll', 'php') as $module) {
$this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, t('The @module module was uninstalled.', array('@module' => $module)));
$this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, format_string('The @module module was uninstalled.', array('@module' => $module)));
}
$this->assertEqual(variable_get('test_module_uninstall_order', array()), array('forum', 'poll', 'php'), t('Modules were uninstalled in the correct order by drupal_uninstall_modules().'));
$this->assertEqual(variable_get('test_module_uninstall_order', array()), array('forum', 'poll', 'php'), 'Modules were uninstalled in the correct order by drupal_uninstall_modules().');
// Uninstall the profile module from above, and make sure that the profile
// itself is not on the list of dependent modules to be uninstalled.
$result = drupal_uninstall_modules(array('comment'));
$this->assertTrue($result, t('drupal_uninstall_modules() returns the correct value.'));
$this->assertEqual(drupal_get_installed_schema_version('comment'), SCHEMA_UNINSTALLED, t('Comment module was uninstalled.'));
$this->assertTrue($result, 'drupal_uninstall_modules() returns the correct value.');
$this->assertEqual(drupal_get_installed_schema_version('comment'), SCHEMA_UNINSTALLED, 'Comment module was uninstalled.');
$uninstalled_modules = variable_get('test_module_uninstall_order', array());
$this->assertTrue(in_array('comment', $uninstalled_modules), t('Comment module is in the list of uninstalled modules.'));
$this->assertFalse(in_array($profile, $uninstalled_modules), t('The installation profile is not in the list of uninstalled modules.'));
$this->assertTrue(in_array('comment', $uninstalled_modules), 'Comment module is in the list of uninstalled modules.');
$this->assertFalse(in_array($profile, $uninstalled_modules), 'The installation profile is not in the list of uninstalled modules.');
// Enable forum module again, which should enable both the poll module and
// php module. But, this time do it with poll module declaring a dependency
@@ -219,11 +219,11 @@ class ModuleUnitTest extends DrupalWebTestCase {
variable_set('dependency_test', 'version dependency');
drupal_static_reset('system_rebuild_module_data');
$result = module_enable(array('forum'));
$this->assertTrue($result, t('module_enable() returns the correct value.'));
$this->assertTrue($result, 'module_enable() returns the correct value.');
// Verify that the fake dependency chain was installed.
$this->assertTrue(module_exists('poll') && module_exists('php'), t('Dependency chain was installed by module_enable().'));
$this->assertTrue(module_exists('poll') && module_exists('php'), 'Dependency chain was installed by module_enable().');
// Verify that the original module was installed.
$this->assertTrue(module_exists('forum'), t('Module installation with version dependencies succeeded.'));
$this->assertTrue(module_exists('forum'), 'Module installation with version dependencies succeeded.');
// Finally, verify that the modules were enabled in the correct order.
$enable_order = variable_get('test_module_enable_order', array());
$php_position = array_search('php', $enable_order);
@@ -231,7 +231,7 @@ class ModuleUnitTest extends DrupalWebTestCase {
$forum_position = array_search('forum', $enable_order);
$php_before_poll = $php_position !== FALSE && $poll_position !== FALSE && $php_position < $poll_position;
$poll_before_forum = $poll_position !== FALSE && $forum_position !== FALSE && $poll_position < $forum_position;
$this->assertTrue($php_before_poll && $poll_before_forum, t('Modules were enabled in the correct order by module_enable().'));
$this->assertTrue($php_before_poll && $poll_before_forum, 'Modules were enabled in the correct order by module_enable().');
}
}
@@ -267,8 +267,8 @@ class ModuleInstallTestCase extends DrupalWebTestCase {
// Check for data that was inserted using drupal_write_record() while the
// 'module_test' module was being installed and enabled.
$data = db_query("SELECT data FROM {module_test}")->fetchCol();
$this->assertTrue(in_array('Data inserted in hook_install()', $data), t('Data inserted using drupal_write_record() in hook_install() is correctly saved.'));
$this->assertTrue(in_array('Data inserted in hook_enable()', $data), t('Data inserted using drupal_write_record() in hook_enable() is correctly saved.'));
$this->assertTrue(in_array('Data inserted in hook_install()', $data), 'Data inserted using drupal_write_record() in hook_install() is correctly saved.');
$this->assertTrue(in_array('Data inserted in hook_enable()', $data), 'Data inserted using drupal_write_record() in hook_enable() is correctly saved.');
}
}
@@ -299,6 +299,48 @@ class ModuleUninstallTestCase extends DrupalWebTestCase {
// Are the perms defined by module_test removed from {role_permission}.
$count = db_query("SELECT COUNT(rid) FROM {role_permission} WHERE permission = :perm", array(':perm' => 'module_test perm'))->fetchField();
$this->assertEqual(0, $count, t('Permissions were all removed.'));
$this->assertEqual(0, $count, 'Permissions were all removed.');
}
}
class ModuleImplementsAlterTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Module implements alter',
'description' => 'Tests hook_module_implements_alter().',
'group' => 'Module',
);
}
/**
* Tests hook_module_implements_alter() adding an implementation.
*/
function testModuleImplementsAlter() {
module_enable(array('module_test'), FALSE);
$this->assertTrue(module_exists('module_test'), 'Test module is enabled.');
// Assert that module_test.module is now included.
$this->assertTrue(function_exists('module_test_permission'),
'The file module_test.module was successfully included.');
$modules = module_implements('permission');
$this->assertTrue(in_array('module_test', $modules), 'module_test implements hook_permission.');
$modules = module_implements('module_implements_alter');
$this->assertTrue(in_array('module_test', $modules), 'module_test implements hook_module_implements_alter().');
// Assert that module_test.implementations.inc is not included yet.
$this->assertFalse(function_exists('module_test_altered_test_hook'),
'The file module_test.implementations.inc is not included yet.');
// Assert that module_test_module_implements_alter(*, 'altered_test_hook')
// has added an implementation
$this->assertTrue(in_array('module_test', module_implements('altered_test_hook')),
'module_test implements hook_altered_test_hook().');
// Assert that module_test.implementations.inc was included as part of the process.
$this->assertTrue(function_exists('module_test_altered_test_hook'),
'The file module_test.implementations.inc was included.');
}
}
@@ -0,0 +1,10 @@
<?php
/**
* Implements hook_altered_test_hook()
*
* @see module_test_module_implements_alter()
*/
function module_test_altered_test_hook() {
return __FUNCTION__;
}
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -129,3 +129,14 @@ function module_test_modules_uninstalled($modules) {
// can check that the modules were uninstalled in the correct sequence.
variable_set('test_module_uninstall_order', $modules);
}
/**
* Implements hook_module_implements_alter()
*/
function module_test_module_implements_alter(&$implementations, $hook) {
if ($hook === 'altered_test_hook') {
// Add a hook implementation, that will be found in
// module_test.implementations.inc.
$implementations['module_test'] = 'implementations';
}
}
+28 -13
View File
@@ -55,6 +55,22 @@ class PagerFunctionalWebTestCase extends DrupalWebTestCase {
$this->assertPagerItems($current_page);
}
/**
* Tests theme_pager() when an empty quantity is passed.
*/
public function testThemePagerQuantityNotSet() {
$variables = array(
'element' => 0,
'parameters' => array(),
'quantity' => '',
'tags' => '',
);
pager_default_initialize(100, 10);
$rendered_output = theme_pager($variables);
$this->assertNotIdentical(stripos($rendered_output, 'next'), FALSE);
$this->assertNotIdentical(stripos($rendered_output, 'last'), FALSE);
}
/**
* Asserts pager items and links.
*
@@ -101,24 +117,24 @@ class PagerFunctionalWebTestCase extends DrupalWebTestCase {
// Verify first/previous and next/last items and links.
if (isset($first)) {
$this->assertClass($first, 'pager-first', "Item for first page has .pager-first class.");
$this->assertTrue($first->a, "Link to first page found.");
$this->assertNoClass($first->a, 'active', "Link to first page is not active.");
$this->assertClass($first, 'pager-first', 'Item for first page has .pager-first class.');
$this->assertTrue($first->a, 'Link to first page found.');
$this->assertNoClass($first->a, 'active', 'Link to first page is not active.');
}
if (isset($previous)) {
$this->assertClass($previous, 'pager-previous', "Item for first page has .pager-previous class.");
$this->assertTrue($previous->a, "Link to previous page found.");
$this->assertNoClass($previous->a, 'active', "Link to previous page is not active.");
$this->assertClass($previous, 'pager-previous', 'Item for first page has .pager-previous class.');
$this->assertTrue($previous->a, 'Link to previous page found.');
$this->assertNoClass($previous->a, 'active', 'Link to previous page is not active.');
}
if (isset($next)) {
$this->assertClass($next, 'pager-next', "Item for next page has .pager-next class.");
$this->assertTrue($next->a, "Link to next page found.");
$this->assertNoClass($next->a, 'active', "Link to next page is not active.");
$this->assertClass($next, 'pager-next', 'Item for next page has .pager-next class.');
$this->assertTrue($next->a, 'Link to next page found.');
$this->assertNoClass($next->a, 'active', 'Link to next page is not active.');
}
if (isset($last)) {
$this->assertClass($last, 'pager-last', "Item for last page has .pager-last class.");
$this->assertTrue($last->a, "Link to last page found.");
$this->assertNoClass($last->a, 'active', "Link to last page is not active.");
$this->assertClass($last, 'pager-last', 'Item for last page has .pager-last class.');
$this->assertTrue($last->a, 'Link to last page found.');
$this->assertNoClass($last->a, 'active', 'Link to last page is not active.');
}
}
@@ -156,4 +172,3 @@ class PagerFunctionalWebTestCase extends DrupalWebTestCase {
$this->assertTrue(strpos($element['class'], $class) === FALSE, $message);
}
}
+31 -10
View File
@@ -35,26 +35,47 @@ class PasswordHashingTest extends DrupalWebTestCase {
$password = 'baz';
$account = (object) array('name' => 'foo', 'pass' => md5($password));
// The md5 password should be flagged as needing an update.
$this->assertTrue(user_needs_new_hash($account), t('User with md5 password needs a new hash.'));
$this->assertTrue(user_needs_new_hash($account), 'User with md5 password needs a new hash.');
// Re-hash the password.
$old_hash = $account->pass;
$account->pass = user_hash_password($password);
$this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_MIN_HASH_COUNT, t('Re-hashed password has the minimum number of log2 iterations.'));
$this->assertTrue($account->pass != $old_hash, t('Password hash changed.'));
$this->assertTrue(user_check_password($password, $account), t('Password check succeeds.'));
$this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_MIN_HASH_COUNT, 'Re-hashed password has the minimum number of log2 iterations.');
$this->assertTrue($account->pass != $old_hash, 'Password hash changed.');
$this->assertTrue(user_check_password($password, $account), 'Password check succeeds.');
// Since the log2 setting hasn't changed and the user has a valid password,
// user_needs_new_hash() should return FALSE.
$this->assertFalse(user_needs_new_hash($account), t('User does not need a new hash.'));
$this->assertFalse(user_needs_new_hash($account), 'User does not need a new hash.');
// Increment the log2 iteration to MIN + 1.
variable_set('password_count_log2', DRUPAL_MIN_HASH_COUNT + 1);
$this->assertTrue(user_needs_new_hash($account), t('User needs a new hash after incrementing the log2 count.'));
$this->assertTrue(user_needs_new_hash($account), 'User needs a new hash after incrementing the log2 count.');
// Re-hash the password.
$old_hash = $account->pass;
$account->pass = user_hash_password($password);
$this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_MIN_HASH_COUNT + 1, t('Re-hashed password has the correct number of log2 iterations.'));
$this->assertTrue($account->pass != $old_hash, t('Password hash changed again.'));
$this->assertIdentical(_password_get_count_log2($account->pass), DRUPAL_MIN_HASH_COUNT + 1, 'Re-hashed password has the correct number of log2 iterations.');
$this->assertTrue($account->pass != $old_hash, 'Password hash changed again.');
// Now the hash should be OK.
$this->assertFalse(user_needs_new_hash($account), t('Re-hashed password does not need a new hash.'));
$this->assertTrue(user_check_password($password, $account), t('Password check succeeds with re-hashed password.'));
$this->assertFalse(user_needs_new_hash($account), 'Re-hashed password does not need a new hash.');
$this->assertTrue(user_check_password($password, $account), 'Password check succeeds with re-hashed password.');
}
/**
* Verifies that passwords longer than 512 bytes are not hashed.
*/
public function testLongPassword() {
$password = str_repeat('x', 512);
$result = user_hash_password($password);
$this->assertFalse(empty($result), '512 byte long password is allowed.');
$password = str_repeat('x', 513);
$result = user_hash_password($password);
$this->assertFalse($result, '513 byte long password is not allowed.');
// Check a string of 3-byte UTF-8 characters.
$password = str_repeat('€', 170);
$result = user_hash_password($password);
$this->assertFalse(empty($result), '510 byte long password is allowed.');
$password .= 'xx';
$this->assertFalse(empty($result), '512 byte long password is allowed.');
$password = str_repeat('€', 171);
$result = user_hash_password($password);
$this->assertFalse($result, '513 byte long password is not allowed.');
}
}
+18 -18
View File
@@ -41,7 +41,7 @@ class DrupalMatchPathTestCase extends DrupalWebTestCase {
foreach ($tests as $patterns => $cases) {
foreach ($cases as $path => $expected_result) {
$actual_result = drupal_match_path($path, $patterns);
$this->assertIdentical($actual_result, $expected_result, t('Tried matching the path <code>@path</code> to the pattern <pre>@patterns</pre> - expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE))));
$this->assertIdentical($actual_result, $expected_result, format_string('Tried matching the path <code>@path</code> to the pattern <pre>@patterns</pre> - expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE))));
}
}
}
@@ -196,8 +196,8 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase {
*/
function testCurrentUrlRequestedPath() {
$this->drupalGet('url-alter-test/bar');
$this->assertRaw('request_path=url-alter-test/bar', t('request_path() returns the requested path.'));
$this->assertRaw('current_path=url-alter-test/foo', t('current_path() returns the internal path.'));
$this->assertRaw('request_path=url-alter-test/bar', 'request_path() returns the requested path.');
$this->assertRaw('current_path=url-alter-test/foo', 'current_path() returns the internal path.');
}
/**
@@ -223,7 +223,7 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase {
$result = url($original);
$base_path = base_path() . (variable_get('clean_url', '0') ? '' : '?q=');
$result = substr($result, strlen($base_path));
$this->assertIdentical($result, $final, t('Altered outbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
$this->assertIdentical($result, $final, format_string('Altered outbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
}
/**
@@ -240,7 +240,7 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase {
protected function assertUrlInboundAlter($original, $final) {
// Test inbound altering.
$result = drupal_get_normal_path($original);
$this->assertIdentical($result, $final, t('Altered inbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
$this->assertIdentical($result, $final, format_string('Altered inbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
}
}
@@ -271,8 +271,8 @@ class PathLookupTest extends DrupalWebTestCase {
'alias' => 'foo',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Basic alias lookup works.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Basic source lookup works.'));
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], 'Basic alias lookup works.');
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], 'Basic source lookup works.');
// Create a language specific alias for the default language (English).
$path = array(
@@ -281,8 +281,8 @@ class PathLookupTest extends DrupalWebTestCase {
'language' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('English alias overrides language-neutral alias.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('English source overrides language-neutral source.'));
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], 'English alias overrides language-neutral alias.');
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], 'English source overrides language-neutral source.');
// Create a language-neutral alias for the same path, again.
$path = array(
@@ -290,7 +290,7 @@ class PathLookupTest extends DrupalWebTestCase {
'alias' => 'bar',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a language-neutral alias.'));
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", 'English alias still returned after entering a language-neutral alias.');
// Create a language-specific (xx-lolspeak) alias for the same path.
$path = array(
@@ -299,9 +299,9 @@ class PathLookupTest extends DrupalWebTestCase {
'language' => 'xx-lolspeak',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a LOLspeak alias.'));
$this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", 'English alias still returned after entering a LOLspeak alias.');
// The LOLspeak alias should be returned if we really want LOLspeak.
$this->assertEqual(drupal_lookup_path('alias', $path['source'], 'xx-lolspeak'), 'LOL', t('LOLspeak alias returned if we specify xx-lolspeak to drupal_lookup_path().'));
$this->assertEqual(drupal_lookup_path('alias', $path['source'], 'xx-lolspeak'), 'LOL', 'LOLspeak alias returned if we specify xx-lolspeak to drupal_lookup_path().');
// Create a new alias for this path in English, which should override the
// previous alias for "user/$uid".
@@ -311,8 +311,8 @@ class PathLookupTest extends DrupalWebTestCase {
'language' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Recently created English alias returned.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Recently created English source returned.'));
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], 'Recently created English alias returned.');
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], 'Recently created English source returned.');
// Remove the English aliases, which should cause a fallback to the most
// recently created language-neutral alias, 'bar'.
@@ -320,7 +320,7 @@ class PathLookupTest extends DrupalWebTestCase {
->condition('language', 'en')
->execute();
drupal_clear_path_cache();
$this->assertEqual(drupal_lookup_path('alias', $path['source']), 'bar', t('Path lookup falls back to recently created language-neutral alias.'));
$this->assertEqual(drupal_lookup_path('alias', $path['source']), 'bar', 'Path lookup falls back to recently created language-neutral alias.');
// Test the situation where the alias and language are the same, but
// the source differs. The newer alias record should be returned.
@@ -330,7 +330,7 @@ class PathLookupTest extends DrupalWebTestCase {
'alias' => 'bar',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Newer alias record is returned when comparing two LANGUAGE_NONE paths with the same alias.'));
$this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], 'Newer alias record is returned when comparing two LANGUAGE_NONE paths with the same alias.');
}
}
@@ -375,7 +375,7 @@ class PathSaveTest extends DrupalWebTestCase {
// Test to see if the original alias is available to modules during
// hook_path_update().
$results = variable_get('path_test_results', array());
$this->assertIdentical($results['hook_path_update']['original']['alias'], $path_original['alias'], t('Old path alias available to modules during hook_path_update.'));
$this->assertIdentical($results['hook_path_update']['original']['source'], $path_original['source'], t('Old path alias available to modules during hook_path_update.'));
$this->assertIdentical($results['hook_path_update']['original']['alias'], $path_original['alias'], 'Old path alias available to modules during hook_path_update.');
$this->assertIdentical($results['hook_path_update']['original']['source'], $path_original['source'], 'Old path alias available to modules during hook_path_update.');
}
}
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -5,8 +5,7 @@ core = 7.x
hidden = TRUE
package = Testing
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -0,0 +1,11 @@
name = PSR-4 Test cases
description = Test classes to be discovered by simpletest.
core = 7.x
hidden = TRUE
package = Testing
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1600272641"
@@ -0,0 +1 @@
<?php
@@ -0,0 +1,18 @@
<?php
namespace Drupal\psr_4_test\Tests;
class ExampleTest extends \DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'PSR4 example test: PSR-4 in disabled modules.',
'description' => 'We want to assert that this test case is being discovered.',
'group' => 'SimpleTest',
);
}
function testArithmetics() {
$this->assert(1 + 1 == 2, '1 + 1 == 2');
}
}
@@ -0,0 +1,18 @@
<?php
namespace Drupal\psr_4_test\Tests\Nested;
class NestedExampleTest extends \DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'PSR4 example test: PSR-4 in nested subfolders.',
'description' => 'We want to assert that this PSR-4 test case is being discovered.',
'group' => 'SimpleTest',
);
}
function testArithmetics() {
$this->assert(1 + 1 == 2, '1 + 1 == 2');
}
}
@@ -0,0 +1,354 @@
<?php
/**
* @file
* Tests for the RequestSanitizer class.
*/
/**
* Tests DrupalRequestSanitizer class.
*/
class RequestSanitizerTest extends DrupalUnitTestCase {
/**
* Log of errors triggered during sanitization.
*
* @var array
*/
protected $errors;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'DrupalRequestSanitizer',
'description' => 'Test the DrupalRequestSanitizer class',
'group' => 'System',
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
require_once DRUPAL_ROOT . '/includes/request-sanitizer.inc';
parent::setUp();
set_error_handler(array($this, "sanitizerTestErrorHandler"));
}
/**
* Iterate through all the RequestSanitizerTests.
*/
public function testRequestSanitization() {
foreach ($this->requestSanitizerTests() as $label => $data) {
$this->errors = array();
// Normalize the test parameters.
$test = array(
'request' => $data[0],
'expected' => isset($data[1]) ? $data[1] : array(),
'expected_errors' => isset($data[2]) ? $data[2] : NULL,
'whitelist' => isset($data[3]) ? $data[3] : array(),
);
$this->requestSanitizationTest($test['request'], $test['expected'], $test['expected_errors'], $test['whitelist'], $label);
}
}
/**
* Tests RequestSanitizer class.
*
* @param \SanitizerTestRequest $request
* The request to sanitize.
* @param array $expected
* An array of expected request parameters after sanitization.
* @param array|null $expected_errors
* An array of expected errors. If set to NULL then error logging is
* disabled.
* @param array $whitelist
* An array of keys to whitelist and not sanitize.
* @param string $label
* A descriptive name for each test / group of assertions.
*
* @throws \ReflectionException
*/
public function requestSanitizationTest(SanitizerTestRequest $request, array $expected = array(), array $expected_errors = NULL, array $whitelist = array(), $label = NULL) {
// Set up globals.
$_GET = $request->getQuery();
$_POST = $request->getRequest();
$_COOKIE = $request->getCookies();
$_REQUEST = array_merge($request->getQuery(), $request->getRequest());
$GLOBALS['conf']['sanitize_input_whitelist'] = $whitelist;
$GLOBALS['conf']['sanitize_input_logging'] = is_null($expected_errors) ? FALSE : TRUE;
if ($label !== 'already sanitized request') {
$reflection = new \ReflectionProperty('DrupalRequestSanitizer', 'sanitized');
$reflection->setAccessible(TRUE);
$reflection->setValue(NULL, FALSE);
}
DrupalRequestSanitizer::sanitize();
if (isset($_GET['destination'])) {
DrupalRequestSanitizer::cleanDestination();
}
// Normalise the expected data.
$expected += array(
'cookies' => array(),
'query' => array(),
'request' => array(),
);
// Test PHP globals.
$this->assertEqualLabelled($expected['cookies'], $_COOKIE, NULL, 'Other', $label . ' (COOKIE)');
$this->assertEqualLabelled($expected['query'], $_GET, NULL, 'Other', $label . ' (GET)');
$this->assertEqualLabelled($expected['request'], $_POST, NULL, 'Other', $label . ' (POST)');
$expected_request = array_merge($expected['query'], $expected['request']);
$this->assertEqualLabelled($expected_request, $_REQUEST, NULL, 'Other', $label . ' (REQUEST)');
// Ensure any expected errors have been triggered.
if (!empty($expected_errors)) {
foreach ($expected_errors as $expected_error) {
$this->assertError($expected_error, E_USER_NOTICE, $label . ' (errors)');
}
}
else {
$this->assertEqualLabelled(array(), $this->errors, NULL, 'Other', $label . ' (errors)');
}
}
/**
* Data provider for testRequestSanitization.
*
* @return array
* A list of tests to carry out.
*/
public function requestSanitizerTests() {
$tests = array();
$request = new SanitizerTestRequest(array('q' => 'index.php'));
$tests['no sanitization GET'] = array($request, array('query' => array('q' => 'index.php')));
$request = new SanitizerTestRequest(array(), array('field' => 'value'));
$tests['no sanitization POST'] = array($request, array('request' => array('field' => 'value')));
$request = new SanitizerTestRequest(array(), array(), array(), array('key' => 'value'));
$tests['no sanitization COOKIE'] = array($request, array('cookies' => array('key' => 'value')));
$request = new SanitizerTestRequest(array('q' => 'index.php'), array('field' => 'value'), array(), array('key' => 'value'));
$tests['no sanitization GET, POST, COOKIE'] = array($request, array('query' => array('q' => 'index.php'), 'request' => array('field' => 'value'), 'cookies' => array('key' => 'value')));
$request = new SanitizerTestRequest(array('q' => 'index.php'));
$tests['no sanitization GET log'] = array($request, array('query' => array('q' => 'index.php')), array());
$request = new SanitizerTestRequest(array(), array('field' => 'value'));
$tests['no sanitization POST log'] = array($request, array('request' => array('field' => 'value')), array());
$request = new SanitizerTestRequest(array(), array(), array(), array('key' => 'value'));
$tests['no sanitization COOKIE log'] = array($request, array('cookies' => array('key' => 'value')), array());
$request = new SanitizerTestRequest(array('#q' => 'index.php'));
$tests['sanitization GET'] = array($request);
$request = new SanitizerTestRequest(array(), array('#field' => 'value'));
$tests['sanitization POST'] = array($request);
$request = new SanitizerTestRequest(array(), array(), array(), array('#key' => 'value'));
$tests['sanitization COOKIE'] = array($request);
$request = new SanitizerTestRequest(array('#q' => 'index.php'), array('#field' => 'value'), array(), array('#key' => 'value'));
$tests['sanitization GET, POST, COOKIE'] = array($request);
$request = new SanitizerTestRequest(array('#q' => 'index.php'));
$tests['sanitization GET log'] = array($request, array(), array('Potentially unsafe keys removed from query string parameters (GET): #q'));
$request = new SanitizerTestRequest(array(), array('#field' => 'value'));
$tests['sanitization POST log'] = array($request, array(), array('Potentially unsafe keys removed from request body parameters (POST): #field'));
$request = new SanitizerTestRequest(array(), array(), array(), array('#key' => 'value'));
$tests['sanitization COOKIE log'] = array($request, array(), array('Potentially unsafe keys removed from cookie parameters (COOKIE): #key'));
$request = new SanitizerTestRequest(array('#q' => 'index.php'), array('#field' => 'value'), array(), array('#key' => 'value'));
$tests['sanitization GET, POST, COOKIE log'] = array($request, array(), array('Potentially unsafe keys removed from query string parameters (GET): #q', 'Potentially unsafe keys removed from request body parameters (POST): #field', 'Potentially unsafe keys removed from cookie parameters (COOKIE): #key'));
$request = new SanitizerTestRequest(array('q' => 'index.php', 'foo' => array('#bar' => 'foo')));
$tests['recursive sanitization log'] = array($request, array('query' => array('q' => 'index.php', 'foo' => array())), array('Potentially unsafe keys removed from query string parameters (GET): #bar'));
$request = new SanitizerTestRequest(array('q' => 'index.php', 'foo' => array('#bar' => 'foo')));
$tests['recursive no sanitization whitelist'] = array($request, array('query' => array('q' => 'index.php', 'foo' => array('#bar' => 'foo'))), array(), array('#bar'));
$request = new SanitizerTestRequest(array(), array('#field' => 'value'));
$tests['no sanitization POST whitelist'] = array($request, array('request' => array('#field' => 'value')), array(), array('#field'));
$request = new SanitizerTestRequest(array('q' => 'index.php', 'foo' => array('#bar' => 'foo', '#foo' => 'bar')));
$tests['recursive multiple sanitization log'] = array($request, array('query' => array('q' => 'index.php', 'foo' => array())), array('Potentially unsafe keys removed from query string parameters (GET): #bar, #foo'));
$request = new SanitizerTestRequest(array('#q' => 'index.php'));
$tests['already sanitized request'] = array($request, array('query' => array('#q' => 'index.php')));
$request = new SanitizerTestRequest(array('destination' => 'whatever?%23test=value'));
$tests['destination removal GET'] = array($request);
$request = new SanitizerTestRequest(array('destination' => 'whatever?%23test=value'));
$tests['destination removal GET log'] = array($request, array(), array('Potentially unsafe destination removed from query string parameters (GET) because it contained the following keys: #test'));
$request = new SanitizerTestRequest(array('destination' => 'whatever?q[%23test]=value'));
$tests['destination removal subkey'] = array($request);
$request = new SanitizerTestRequest(array('destination' => 'whatever?q[%23test]=value'));
$tests['destination whitelist'] = array($request, array('query' => array('destination' => 'whatever?q[%23test]=value')), array(), array('#test'));
$request = new SanitizerTestRequest(array('destination' => "whatever?\x00bar=base&%23test=value"));
$tests['destination removal zero byte'] = array($request);
$request = new SanitizerTestRequest(array('destination' => 'whatever?q=value'));
$tests['destination kept'] = array($request, array('query' => array('destination' => 'whatever?q=value')));
$request = new SanitizerTestRequest(array('destination' => 'whatever'));
$tests['destination no query'] = array($request, array('query' => array('destination' => 'whatever')));
return $tests;
}
/**
* Catches and logs errors to $this->errors.
*
* @param int $errno
* The severity level of the error.
* @param string $errstr
* The error message.
*/
public function sanitizerTestErrorHandler($errno, $errstr) {
$this->errors[] = compact('errno', 'errstr');
}
/**
* Asserts that the expected error has been logged.
*
* @param string $errstr
* The error message.
* @param int $errno
* The severity level of the error.
* @param string $label
* The label to include with the message.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertError($errstr, $errno, $label) {
$label = (empty($label)) ? '' : $label . ': ';
foreach ($this->errors as $error) {
if ($error['errstr'] === $errstr && $error['errno'] === $errno) {
return $this->pass($label . "Error with level $errno and message '$errstr' found");
}
}
return $this->fail($label . "Error with level $errno and message '$errstr' not found in " . var_export($this->errors, TRUE));
}
/**
* Asserts two values are equal, includes a label.
*
* @param mixed $first
* The first value to check.
* @param mixed $second
* The second value to check.
* @param string $message
* The message to display along with the assertion.
* @param string $group
* The type of assertion - examples are "Browser", "PHP".
* @param string $label
* The label to include with the message.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertEqualLabelled($first, $second, $message = '', $group = 'Other', $label = '') {
$label = (empty($label)) ? '' : $label . ': ';
$message = $message ? $message : t('Value @first is equal to value @second.', array(
'@first' => var_export($first, TRUE),
'@second' => var_export($second, TRUE),
));
return $this->assert($first == $second, $label . $message, $group);
}
}
/**
* Basic HTTP Request class.
*/
class SanitizerTestRequest {
/**
* The query (GET).
*
* @var array
*/
protected $query;
/**
* The request (POST).
*
* @var array
*/
protected $request;
/**
* The request attributes.
*
* @var array
*/
protected $attributes;
/**
* The request cookies.
*
* @var array
*/
protected $cookies;
/**
* Constructor.
*
* @param array $query
* The GET parameters.
* @param array $request
* The POST parameters.
* @param array $attributes
* The request attributes.
* @param array $cookies
* The COOKIE parameters.
*/
public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array()) {
$this->query = $query;
$this->request = $request;
$this->attributes = $attributes;
$this->cookies = $cookies;
}
/**
* Getter for $query.
*/
public function getQuery() {
return $this->query;
}
/**
* Getter for $request.
*/
public function getRequest() {
return $this->request;
}
/**
* Getter for $attributes.
*/
public function getAttributes() {
return $this->attributes;
}
/**
* Getter for $cookies.
*/
public function getCookies() {
return $this->cookies;
}
}
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -7,8 +7,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+24 -24
View File
@@ -44,7 +44,7 @@ class SchemaTestCase extends DrupalWebTestCase {
db_create_table('test_table', $table_specification);
// Assert that the table exists.
$this->assertTrue(db_table_exists('test_table'), t('The table exists.'));
$this->assertTrue(db_table_exists('test_table'), 'The table exists.');
// Assert that the table comment has been set.
$this->checkSchemaComment($table_specification['description'], 'test_table');
@@ -53,46 +53,46 @@ class SchemaTestCase extends DrupalWebTestCase {
$this->checkSchemaComment($table_specification['fields']['test_field']['description'], 'test_table', 'test_field');
// An insert without a value for the column 'test_table' should fail.
$this->assertFalse($this->tryInsert(), t('Insert without a default failed.'));
$this->assertFalse($this->tryInsert(), 'Insert without a default failed.');
// Add a default value to the column.
db_field_set_default('test_table', 'test_field', 0);
// The insert should now succeed.
$this->assertTrue($this->tryInsert(), t('Insert with a default succeeded.'));
$this->assertTrue($this->tryInsert(), 'Insert with a default succeeded.');
// Remove the default.
db_field_set_no_default('test_table', 'test_field');
// The insert should fail again.
$this->assertFalse($this->tryInsert(), t('Insert without a default failed.'));
$this->assertFalse($this->tryInsert(), 'Insert without a default failed.');
// Test for fake index and test for the boolean result of indexExists().
$index_exists = Database::getConnection()->schema()->indexExists('test_table', 'test_field');
$this->assertIdentical($index_exists, FALSE, t('Fake index does not exists'));
$this->assertIdentical($index_exists, FALSE, 'Fake index does not exists');
// Add index.
db_add_index('test_table', 'test_field', array('test_field'));
// Test for created index and test for the boolean result of indexExists().
$index_exists = Database::getConnection()->schema()->indexExists('test_table', 'test_field');
$this->assertIdentical($index_exists, TRUE, t('Index created.'));
$this->assertIdentical($index_exists, TRUE, 'Index created.');
// Rename the table.
db_rename_table('test_table', 'test_table2');
// Index should be renamed.
$index_exists = Database::getConnection()->schema()->indexExists('test_table2', 'test_field');
$this->assertTrue($index_exists, t('Index was renamed.'));
$this->assertTrue($index_exists, 'Index was renamed.');
// We need the default so that we can insert after the rename.
db_field_set_default('test_table2', 'test_field', 0);
$this->assertFalse($this->tryInsert(), t('Insert into the old table failed.'));
$this->assertTrue($this->tryInsert('test_table2'), t('Insert into the new table succeeded.'));
$this->assertFalse($this->tryInsert(), 'Insert into the old table failed.');
$this->assertTrue($this->tryInsert('test_table2'), 'Insert into the new table succeeded.');
// We should have successfully inserted exactly two rows.
$count = db_query('SELECT COUNT(*) FROM {test_table2}')->fetchField();
$this->assertEqual($count, 2, t('Two fields were successfully inserted.'));
$this->assertEqual($count, 2, 'Two fields were successfully inserted.');
// Try to drop the table.
db_drop_table('test_table2');
$this->assertFalse(db_table_exists('test_table2'), t('The dropped table does not exist.'));
$this->assertFalse(db_table_exists('test_table2'), 'The dropped table does not exist.');
// Recreate the table.
db_create_table('test_table', $table_specification);
@@ -108,14 +108,14 @@ class SchemaTestCase extends DrupalWebTestCase {
// Assert that the column comment has been set.
$this->checkSchemaComment('Changed column description.', 'test_table', 'test_serial');
$this->assertTrue($this->tryInsert(), t('Insert with a serial succeeded.'));
$this->assertTrue($this->tryInsert(), 'Insert with a serial succeeded.');
$max1 = db_query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
$this->assertTrue($this->tryInsert(), t('Insert with a serial succeeded.'));
$this->assertTrue($this->tryInsert(), 'Insert with a serial succeeded.');
$max2 = db_query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
$this->assertTrue($max2 > $max1, t('The serial is monotone.'));
$this->assertTrue($max2 > $max1, 'The serial is monotone.');
$count = db_query('SELECT COUNT(*) FROM {test_table}')->fetchField();
$this->assertEqual($count, 2, t('There were two rows.'));
$this->assertEqual($count, 2, 'There were two rows.');
// Use database specific data type and ensure that table is created.
$table_specification = array(
@@ -134,7 +134,7 @@ class SchemaTestCase extends DrupalWebTestCase {
db_create_table('test_timestamp', $table_specification);
}
catch (Exception $e) {}
$this->assertTrue(db_table_exists('test_timestamp'), t('Table with database specific datatype was created.'));
$this->assertTrue(db_table_exists('test_timestamp'), 'Table with database specific datatype was created.');
}
function tryInsert($table = 'test_table') {
@@ -162,7 +162,7 @@ class SchemaTestCase extends DrupalWebTestCase {
function checkSchemaComment($description, $table, $column = NULL) {
if (method_exists(Database::getConnection()->schema(), 'getComment')) {
$comment = Database::getConnection()->schema()->getComment($table, $column);
$this->assertEqual($comment, $description, t('The comment matches the schema description.'));
$this->assertEqual($comment, $description, 'The comment matches the schema description.');
}
}
@@ -193,8 +193,8 @@ class SchemaTestCase extends DrupalWebTestCase {
// Finally, check each column and try to insert invalid values into them.
foreach ($table_spec['fields'] as $column_name => $column_spec) {
$this->assertTrue(db_field_exists($table_name, $column_name), t('Unsigned @type column was created.', array('@type' => $column_spec['type'])));
$this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), t('Unsigned @type column rejected a negative value.', array('@type' => $column_spec['type'])));
$this->assertTrue(db_field_exists($table_name, $column_name), format_string('Unsigned @type column was created.', array('@type' => $column_spec['type'])));
$this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), format_string('Unsigned @type column rejected a negative value.', array('@type' => $column_spec['type'])));
}
}
@@ -312,7 +312,7 @@ class SchemaTestCase extends DrupalWebTestCase {
'primary key' => array('serial_column'),
);
db_create_table($table_name, $table_spec);
$this->pass(t('Table %table created.', array('%table' => $table_name)));
$this->pass(format_string('Table %table created.', array('%table' => $table_name)));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
@@ -329,7 +329,7 @@ class SchemaTestCase extends DrupalWebTestCase {
'primary key' => array('serial_column'),
);
db_create_table($table_name, $table_spec);
$this->pass(t('Table %table created.', array('%table' => $table_name)));
$this->pass(format_string('Table %table created.', array('%table' => $table_name)));
// Insert some rows to the table to test the handling of initial values.
for ($i = 0; $i < 3; $i++) {
@@ -339,7 +339,7 @@ class SchemaTestCase extends DrupalWebTestCase {
}
db_add_field($table_name, 'test_field', $field_spec);
$this->pass(t('Column %column created.', array('%column' => 'test_field')));
$this->pass(format_string('Column %column created.', array('%column' => 'test_field')));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
@@ -362,7 +362,7 @@ class SchemaTestCase extends DrupalWebTestCase {
->countQuery()
->execute()
->fetchField();
$this->assertEqual($count, 0, t('Initial values filled out.'));
$this->assertEqual($count, 0, 'Initial values filled out.');
}
// Check that the default value has been registered.
@@ -376,7 +376,7 @@ class SchemaTestCase extends DrupalWebTestCase {
->condition('serial_column', $id)
->execute()
->fetchField();
$this->assertEqual($field_value, $field_spec['default'], t('Default value registered.'));
$this->assertEqual($field_value, $field_spec['default'], 'Default value registered.');
}
db_drop_field($table_name, $field_name);
+97 -48
View File
@@ -22,11 +22,11 @@ class SessionTestCase extends DrupalWebTestCase {
* Tests for drupal_save_session() and drupal_session_regenerate().
*/
function testSessionSaveRegenerate() {
$this->assertFalse(drupal_save_session(), t('drupal_save_session() correctly returns FALSE (inside of testing framework) when initially called with no arguments.'), t('Session'));
$this->assertFalse(drupal_save_session(FALSE), t('drupal_save_session() correctly returns FALSE when called with FALSE.'), t('Session'));
$this->assertFalse(drupal_save_session(), t('drupal_save_session() correctly returns FALSE when saving has been disabled.'), t('Session'));
$this->assertTrue(drupal_save_session(TRUE), t('drupal_save_session() correctly returns TRUE when called with TRUE.'), t('Session'));
$this->assertTrue(drupal_save_session(), t('drupal_save_session() correctly returns TRUE when saving has been enabled.'), t('Session'));
$this->assertFalse(drupal_save_session(), 'drupal_save_session() correctly returns FALSE (inside of testing framework) when initially called with no arguments.', 'Session');
$this->assertFalse(drupal_save_session(FALSE), 'drupal_save_session() correctly returns FALSE when called with FALSE.', 'Session');
$this->assertFalse(drupal_save_session(), 'drupal_save_session() correctly returns FALSE when saving has been disabled.', 'Session');
$this->assertTrue(drupal_save_session(TRUE), 'drupal_save_session() correctly returns TRUE when called with TRUE.', 'Session');
$this->assertTrue(drupal_save_session(), 'drupal_save_session() correctly returns TRUE when saving has been enabled.', 'Session');
// Test session hardening code from SA-2008-044.
$user = $this->drupalCreateUser(array('access content'));
@@ -36,7 +36,7 @@ class SessionTestCase extends DrupalWebTestCase {
// Make sure the session cookie is set as HttpOnly.
$this->drupalLogin($user);
$this->assertTrue(preg_match('/HttpOnly/i', $this->drupalGetHeader('Set-Cookie', TRUE)), t('Session cookie is set as HttpOnly.'));
$this->assertTrue(preg_match('/HttpOnly/i', $this->drupalGetHeader('Set-Cookie', TRUE)), 'Session cookie is set as HttpOnly.');
$this->drupalLogout();
// Verify that the session is regenerated if a module calls exit
@@ -46,7 +46,7 @@ class SessionTestCase extends DrupalWebTestCase {
$this->drupalGet('session-test/id');
$matches = array();
preg_match('/\s*session_id:(.*)\n/', $this->drupalGetContent(), $matches);
$this->assertTrue(!empty($matches[1]) , t('Found session ID before logging in.'));
$this->assertTrue(!empty($matches[1]) , 'Found session ID before logging in.');
$original_session = $matches[1];
// We cannot use $this->drupalLogin($user); because we exit in
@@ -57,19 +57,18 @@ class SessionTestCase extends DrupalWebTestCase {
);
$this->drupalPost('user', $edit, t('Log in'));
$this->drupalGet('user');
$pass = $this->assertText($user->name, t('Found name: %name', array('%name' => $user->name)), t('User login'));
$pass = $this->assertText($user->name, format_string('Found name: %name', array('%name' => $user->name)), 'User login');
$this->_logged_in = $pass;
$this->drupalGet('session-test/id');
$matches = array();
preg_match('/\s*session_id:(.*)\n/', $this->drupalGetContent(), $matches);
$this->assertTrue(!empty($matches[1]) , t('Found session ID after logging in.'));
$this->assertTrue($matches[1] != $original_session, t('Session ID changed after login.'));
$this->assertTrue(!empty($matches[1]) , 'Found session ID after logging in.');
$this->assertTrue($matches[1] != $original_session, 'Session ID changed after login.');
}
/**
* Test data persistence via the session_test module callbacks. Also tests
* drupal_session_count() since session data is already generated here.
* Test data persistence via the session_test module callbacks.
*/
function testDataPersistence() {
$user = $this->drupalCreateUser(array('access content'));
@@ -80,48 +79,48 @@ class SessionTestCase extends DrupalWebTestCase {
$value_1 = $this->randomName();
$this->drupalGet('session-test/set/' . $value_1);
$this->assertText($value_1, t('The session value was stored.'), t('Session'));
$this->assertText($value_1, 'The session value was stored.', 'Session');
$this->drupalGet('session-test/get');
$this->assertText($value_1, t('Session correctly returned the stored data for an authenticated user.'), t('Session'));
$this->assertText($value_1, 'Session correctly returned the stored data for an authenticated user.', 'Session');
// Attempt to write over val_1. If drupal_save_session(FALSE) is working.
// properly, val_1 will still be set.
$value_2 = $this->randomName();
$this->drupalGet('session-test/no-set/' . $value_2);
$this->assertText($value_2, t('The session value was correctly passed to session-test/no-set.'), t('Session'));
$this->assertText($value_2, 'The session value was correctly passed to session-test/no-set.', 'Session');
$this->drupalGet('session-test/get');
$this->assertText($value_1, t('Session data is not saved for drupal_save_session(FALSE).'), t('Session'));
$this->assertText($value_1, 'Session data is not saved for drupal_save_session(FALSE).', 'Session');
// Switch browser cookie to anonymous user, then back to user 1.
$this->sessionReset();
$this->sessionReset($user->uid);
$this->assertText($value_1, t('Session data persists through browser close.'), t('Session'));
$this->assertText($value_1, 'Session data persists through browser close.', 'Session');
// Logout the user and make sure the stored value no longer persists.
$this->drupalLogout();
$this->sessionReset();
$this->drupalGet('session-test/get');
$this->assertNoText($value_1, t("After logout, previous user's session data is not available."), t('Session'));
$this->assertNoText($value_1, "After logout, previous user's session data is not available.", 'Session');
// Now try to store some data as an anonymous user.
$value_3 = $this->randomName();
$this->drupalGet('session-test/set/' . $value_3);
$this->assertText($value_3, t('Session data stored for anonymous user.'), t('Session'));
$this->assertText($value_3, 'Session data stored for anonymous user.', 'Session');
$this->drupalGet('session-test/get');
$this->assertText($value_3, t('Session correctly returned the stored data for an anonymous user.'), t('Session'));
$this->assertText($value_3, 'Session correctly returned the stored data for an anonymous user.', 'Session');
// Try to store data when drupal_save_session(FALSE).
$value_4 = $this->randomName();
$this->drupalGet('session-test/no-set/' . $value_4);
$this->assertText($value_4, t('The session value was correctly passed to session-test/no-set.'), t('Session'));
$this->assertText($value_4, 'The session value was correctly passed to session-test/no-set.', 'Session');
$this->drupalGet('session-test/get');
$this->assertText($value_3, t('Session data is not saved for drupal_save_session(FALSE).'), t('Session'));
$this->assertText($value_3, 'Session data is not saved for drupal_save_session(FALSE).', 'Session');
// Login, the data should persist.
$this->drupalLogin($user);
$this->sessionReset($user->uid);
$this->drupalGet('session-test/get');
$this->assertNoText($value_1, t('Session has persisted for an authenticated user after logging out and then back in.'), t('Session'));
$this->assertNoText($value_1, 'Session has persisted for an authenticated user after logging out and then back in.', 'Session');
// Change session and create another user.
$user2 = $this->drupalCreateUser(array('access content'));
@@ -143,29 +142,29 @@ class SessionTestCase extends DrupalWebTestCase {
$this->drupalGet('');
$this->assertSessionCookie(FALSE);
$this->assertSessionEmpty(TRUE);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
// Start a new session by setting a message.
$this->drupalGet('session-test/set-message');
$this->assertSessionCookie(TRUE);
$this->assertTrue($this->drupalGetHeader('Set-Cookie'), t('New session was started.'));
$this->assertTrue($this->drupalGetHeader('Set-Cookie'), 'New session was started.');
// Display the message, during the same request the session is destroyed
// and the session cookie is unset.
$this->drupalGet('');
$this->assertSessionCookie(FALSE);
$this->assertSessionEmpty(FALSE);
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Caching was bypassed.'));
$this->assertText(t('This is a dummy message.'), t('Message was displayed.'));
$this->assertTrue(preg_match('/SESS\w+=deleted/', $this->drupalGetHeader('Set-Cookie')), t('Session cookie was deleted.'));
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Caching was bypassed.');
$this->assertText(t('This is a dummy message.'), 'Message was displayed.');
$this->assertTrue(preg_match('/SESS\w+=deleted/', $this->drupalGetHeader('Set-Cookie')), 'Session cookie was deleted.');
// Verify that session was destroyed.
$this->drupalGet('');
$this->assertSessionCookie(FALSE);
$this->assertSessionEmpty(TRUE);
$this->assertNoText(t('This is a dummy message.'), t('Message was not cached.'));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.'));
$this->assertFalse($this->drupalGetHeader('Set-Cookie'), t('New session was not started.'));
$this->assertNoText(t('This is a dummy message.'), 'Message was not cached.');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$this->assertFalse($this->drupalGetHeader('Set-Cookie'), 'New session was not started.');
// Verify that no session is created if drupal_save_session(FALSE) is called.
$this->drupalGet('session-test/set-message-but-dont-save');
@@ -176,7 +175,7 @@ class SessionTestCase extends DrupalWebTestCase {
$this->drupalGet('');
$this->assertSessionCookie(FALSE);
$this->assertSessionEmpty(TRUE);
$this->assertNoText(t('This is a dummy message.'), t('The message was not saved.'));
$this->assertNoText(t('This is a dummy message.'), 'The message was not saved.');
}
/**
@@ -196,29 +195,29 @@ class SessionTestCase extends DrupalWebTestCase {
sleep(1);
$this->drupalGet('session-test/set/foo');
$times2 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
$this->assertEqual($times2->access, $times1->access, t('Users table was not updated.'));
$this->assertNotEqual($times2->timestamp, $times1->timestamp, t('Sessions table was updated.'));
$this->assertEqual($times2->access, $times1->access, 'Users table was not updated.');
$this->assertNotEqual($times2->timestamp, $times1->timestamp, 'Sessions table was updated.');
// Write the same value again, i.e. do not modify the session.
sleep(1);
$this->drupalGet('session-test/set/foo');
$times3 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
$this->assertEqual($times3->access, $times1->access, t('Users table was not updated.'));
$this->assertEqual($times3->timestamp, $times2->timestamp, t('Sessions table was not updated.'));
$this->assertEqual($times3->access, $times1->access, 'Users table was not updated.');
$this->assertEqual($times3->timestamp, $times2->timestamp, 'Sessions table was not updated.');
// Do not change the session.
sleep(1);
$this->drupalGet('');
$times4 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
$this->assertEqual($times4->access, $times3->access, t('Users table was not updated.'));
$this->assertEqual($times4->timestamp, $times3->timestamp, t('Sessions table was not updated.'));
$this->assertEqual($times4->access, $times3->access, 'Users table was not updated.');
$this->assertEqual($times4->timestamp, $times3->timestamp, 'Sessions table was not updated.');
// Force updating of users and sessions table once per second.
variable_set('session_write_interval', 0);
$this->drupalGet('');
$times5 = db_query($sql, array(':uid' => $user->uid))->fetchObject();
$this->assertNotEqual($times5->access, $times4->access, t('Users table was updated.'));
$this->assertNotEqual($times5->timestamp, $times4->timestamp, t('Sessions table was updated.'));
$this->assertNotEqual($times5->access, $times4->access, 'Users table was updated.');
$this->assertNotEqual($times5->timestamp, $times4->timestamp, 'Sessions table was updated.');
}
/**
@@ -228,7 +227,7 @@ class SessionTestCase extends DrupalWebTestCase {
$user = $this->drupalCreateUser(array('access content'));
$this->drupalLogin($user);
$this->drupalGet('session-test/is-logged-in');
$this->assertResponse(200, t('User is logged in.'));
$this->assertResponse(200, 'User is logged in.');
// Reset the sid in {sessions} to a blank string. This may exist in the
// wild in some cases, although we normally prevent it from happening.
@@ -239,10 +238,10 @@ class SessionTestCase extends DrupalWebTestCase {
$this->curlClose();
$this->additionalCurlOptions[CURLOPT_COOKIE] = rawurlencode($this->session_name) . '=;';
$this->drupalGet('session-test/id-from-cookie');
$this->assertRaw("session_id:\n", t('Session ID is blank as sent from cookie header.'));
$this->assertRaw("session_id:\n", 'Session ID is blank as sent from cookie header.');
// Assert that we have an anonymous session now.
$this->drupalGet('session-test/is-logged-in');
$this->assertResponse(403, t('An empty session ID is not allowed.'));
$this->assertResponse(403, 'An empty session ID is not allowed.');
}
/**
@@ -260,7 +259,7 @@ class SessionTestCase extends DrupalWebTestCase {
$this->additionalCurlOptions[CURLOPT_COOKIEFILE] = $this->cookieFile;
$this->additionalCurlOptions[CURLOPT_COOKIESESSION] = TRUE;
$this->drupalGet('session-test/get');
$this->assertResponse(200, t('Session test module is correctly enabled.'), t('Session'));
$this->assertResponse(200, 'Session test module is correctly enabled.', 'Session');
}
/**
@@ -268,10 +267,10 @@ class SessionTestCase extends DrupalWebTestCase {
*/
function assertSessionCookie($sent) {
if ($sent) {
$this->assertNotNull($this->session_id, t('Session cookie was sent.'));
$this->assertNotNull($this->session_id, 'Session cookie was sent.');
}
else {
$this->assertNull($this->session_id, t('Session cookie was not sent.'));
$this->assertNull($this->session_id, 'Session cookie was not sent.');
}
}
@@ -280,10 +279,10 @@ class SessionTestCase extends DrupalWebTestCase {
*/
function assertSessionEmpty($empty) {
if ($empty) {
$this->assertIdentical($this->drupalGetHeader('X-Session-Empty'), '1', t('Session was empty.'));
$this->assertIdentical($this->drupalGetHeader('X-Session-Empty'), '1', 'Session was empty.');
}
else {
$this->assertIdentical($this->drupalGetHeader('X-Session-Empty'), '0', t('Session was not empty.'));
$this->assertIdentical($this->drupalGetHeader('X-Session-Empty'), '0', 'Session was not empty.');
}
}
}
@@ -478,6 +477,56 @@ class SessionHttpsTestCase extends DrupalWebTestCase {
$this->assertResponse(200);
}
/**
* Tests that empty session IDs do not cause unrelated sessions to load.
*/
public function testEmptySessionId() {
global $is_https;
if ($is_https) {
$secure_session_name = session_name();
}
else {
$secure_session_name = 'S' . session_name();
}
// Enable mixed mode for HTTP and HTTPS.
variable_set('https', TRUE);
$admin_user = $this->drupalCreateUser(array('access administration pages'));
$standard_user = $this->drupalCreateUser(array('access content'));
// First log in as the admin user on HTTP.
// We cannot use $this->drupalLogin() here because we need to use the
// special http.php URLs.
$edit = array(
'name' => $admin_user->name,
'pass' => $admin_user->pass_raw
);
$this->drupalGet('user');
$form = $this->xpath('//form[@id="user-login"]');
$form[0]['action'] = $this->httpUrl('user');
$this->drupalPost(NULL, $edit, t('Log in'));
$this->curlClose();
// Now start a session for the standard user on HTTPS.
$edit = array(
'name' => $standard_user->name,
'pass' => $standard_user->pass_raw
);
$this->drupalGet('user');
$form = $this->xpath('//form[@id="user-login"]');
$form[0]['action'] = $this->httpsUrl('user');
$this->drupalPost(NULL, $edit, t('Log in'));
// Make the secure session cookie blank.
curl_setopt($this->curlHandle, CURLOPT_COOKIE, "$secure_session_name=");
$this->drupalGet($this->httpsUrl('user'));
$this->assertNoText($admin_user->name, 'User is not logged in as admin');
$this->assertNoText($standard_user->name, "The user's own name is not displayed because the invalid session cookie has logged them out.");
}
/**
* Test that there exists a session with two specific session IDs.
*
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -6,8 +6,7 @@ core = 7.x
hidden = TRUE
dependencies[] = _missing_dependency
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -6,8 +6,7 @@ core = 7.x
hidden = TRUE
dependencies[] = system_incompatible_core_version_test
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -5,8 +5,7 @@ version = VERSION
core = 5.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -7,8 +7,7 @@ hidden = TRUE
; system_incompatible_module_version_test declares version 1.0
dependencies[] = system_incompatible_module_version_test (>2.0)
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -5,8 +5,7 @@ version = 1.0
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -0,0 +1,12 @@
name = "System project namespace test"
description = "Support module for testing project namespace dependencies."
package = Testing
version = VERSION
core = 7.x
hidden = TRUE
dependencies[] = drupal:filter
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1600272641"
@@ -0,0 +1 @@
<?php
+3 -4
View File
@@ -6,8 +6,7 @@ core = 7.x
files[] = system_test.module
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -0,0 +1,20 @@
<?php
/**
* @file
* Install, update and uninstall functions for the system_test module.
*/
/**
* Implements hook_schema().
*/
function system_test_schema() {
// Trigger a search for a module in the filesystem when requested by
// system_test_drupal_get_filename_with_schema_rebuild().
if (variable_get('system_test_drupal_get_filename_attempt_recursive_rebuild')) {
$module_name = variable_get('system_test_drupal_get_filename_test_module_name');
drupal_get_filename('module', $module_name);
}
return array();
}
+166 -2
View File
@@ -78,6 +78,13 @@ function system_test_menu() {
'type' => MENU_CALLBACK,
);
$items['system-test/drupal-set-message'] = array(
'title' => 'Set messages with drupal_set_message()',
'page callback' => 'system_test_drupal_set_message',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['system-test/main-content-handling'] = array(
'title' => 'Test main content handling',
'page callback' => 'system_test_main_content_fallback',
@@ -106,6 +113,34 @@ function system_test_menu() {
'type' => MENU_CALLBACK,
);
$items['system-test/get-destination'] = array(
'title' => 'Test $_GET[\'destination\']',
'page callback' => 'system_test_get_destination',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['system-test/request-destination'] = array(
'title' => 'Test $_REQUEST[\'destination\']',
'page callback' => 'system_test_request_destination',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['system-test/drupal-get-filename'] = array(
'title' => 'Test drupal_get_filename()',
'page callback' => 'system_test_drupal_get_filename',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['system-test/drupal-get-filename-with-schema-rebuild'] = array(
'title' => 'Test drupal_get_filename() with a schema rebuild',
'page callback' => 'system_test_drupal_get_filename_with_schema_rebuild',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
@@ -114,8 +149,23 @@ function system_test_sleep($seconds) {
}
function system_test_basic_auth_page() {
$output = t('$_SERVER[\'PHP_AUTH_USER\'] is @username.', array('@username' => $_SERVER['PHP_AUTH_USER']));
$output .= t('$_SERVER[\'PHP_AUTH_PW\'] is @password.', array('@password' => $_SERVER['PHP_AUTH_PW']));
// The Authorization HTTP header is forwarded via Drupal's .htaccess file even
// for PHP CGI SAPIs.
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
$authorization_header = $_SERVER['HTTP_AUTHORIZATION'];
}
// If using CGI on Apache with mod_rewrite, the forwarded HTTP header appears
// in the redirected HTTP headers. See
// https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/ServerBag.php#L61
elseif (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
$authorization_header = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
}
// Resemble PHP_AUTH_USER and PHP_AUTH_PW for a Basic authentication from
// the HTTP_AUTHORIZATION header. See
// http://www.php.net/manual/features.http-auth.php
list($user, $pw) = explode(':', base64_decode(substr($authorization_header, 6)));
$output = t('Username is @username.', array('@username' => $user));
$output .= t('Password is @password.', array('@password' => $pw));
return $output;
}
@@ -260,6 +310,9 @@ function system_test_system_info_alter(&$info, $file, $type) {
}
}
if ($file->name == 'system_project_namespace_test') {
$info['hidden'] = FALSE;
}
// Make the system_dependencies_test visible by default.
if ($file->name == 'system_dependencies_test') {
$info['hidden'] = FALSE;
@@ -405,3 +458,114 @@ function system_test_authorize_init_page($page_title) {
system_authorized_init('system_test_authorize_run', drupal_get_path('module', 'system_test') . '/system_test.module', array(), $page_title);
drupal_goto($authorize_url);
}
/**
* Sets two messages and removes the first one before the messages are displayed.
*/
function system_test_drupal_set_message() {
// Set two messages.
drupal_set_message('First message (removed).');
drupal_set_message('Second message (not removed).');
// Remove the first.
unset($_SESSION['messages']['status'][0]);
return '';
}
/**
* Page callback to print out $_GET['destination'] for testing.
*/
function system_test_get_destination() {
if (isset($_GET['destination'])) {
print $_GET['destination'];
}
// No need to render the whole page, we are just interested in this bit of
// information.
exit;
}
/**
* Page callback to print out $_REQUEST['destination'] for testing.
*/
function system_test_request_destination() {
if (isset($_REQUEST['destination'])) {
print $_REQUEST['destination'];
}
// No need to render the whole page, we are just interested in this bit of
// information.
exit;
}
/**
* Page callback to run drupal_get_filename() on a particular module.
*/
function system_test_drupal_get_filename() {
// Prevent SimpleTest from failing as a result of the expected PHP warnings
// this function causes. Any warnings will be recorded in the database logs
// for examination by the tests.
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
$module_name = variable_get('system_test_drupal_get_filename_test_module_name');
drupal_get_filename('module', $module_name);
return '';
}
/**
* Page callback to run drupal_get_filename() and do a schema rebuild.
*/
function system_test_drupal_get_filename_with_schema_rebuild() {
// Prevent SimpleTest from failing as a result of the expected PHP warnings
// this function causes.
define('SIMPLETEST_COLLECT_ERRORS', FALSE);
// Record the original database tables from drupal_get_schema().
variable_set('system_test_drupal_get_filename_with_schema_rebuild_original_tables', array_keys(drupal_get_schema(NULL, TRUE)));
// Trigger system_test_schema() and system_test_watchdog() to perform an
// attempted recursive rebuild when drupal_get_schema() is called. See
// BootstrapGetFilenameWebTestCase::testRecursiveRebuilds().
variable_set('system_test_drupal_get_filename_attempt_recursive_rebuild', TRUE);
drupal_get_schema(NULL, TRUE);
return '';
}
/**
* Implements hook_watchdog().
*/
function system_test_watchdog($log_entry) {
// If an attempted recursive schema rebuild has been triggered by
// system_test_drupal_get_filename_with_schema_rebuild(), perform the rebuild
// in response to the missing file message triggered by system_test_schema().
if (!variable_get('system_test_drupal_get_filename_attempt_recursive_rebuild')) {
return;
}
if ($log_entry['type'] != 'php' || $log_entry['severity'] != WATCHDOG_WARNING) {
return;
}
$module_name = variable_get('system_test_drupal_get_filename_test_module_name');
if (!isset($log_entry['variables']['!message']) || strpos($log_entry['variables']['!message'], format_string('The following module is missing from the file system: %name', array('%name' => $module_name))) === FALSE) {
return;
}
variable_set('system_test_drupal_get_filename_with_schema_rebuild_final_tables', array_keys(drupal_get_schema()));
}
/**
* Implements hook_module_implements_alter().
*/
function system_test_module_implements_alter(&$implementations, $hook) {
// For BootstrapGetFilenameWebTestCase::testRecursiveRebuilds() to work
// correctly, this module's hook_schema() implementation cannot be either the
// first implementation (since that would trigger a potential recursive
// rebuild before anything is in the drupal_get_schema() cache) or the last
// implementation (since that would trigger a potential recursive rebuild
// after the cache is already complete). So put it somewhere in the middle.
if ($hook == 'schema') {
$group = $implementations['system_test'];
unset($implementations['system_test']);
$count = count($implementations);
$implementations = array_merge(array_slice($implementations, 0, $count / 2, TRUE), array('system_test' => $group), array_slice($implementations, $count / 2, NULL, TRUE));
}
}
+6 -6
View File
@@ -58,7 +58,7 @@ class TableSortTest extends DrupalUnitTestCase {
);
$ts = tablesort_init($headers);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, t('Simple table headers sorted correctly.'));
$this->assertEqual($ts, $expected_ts, 'Simple table headers sorted correctly.');
// Test with simple table headers plus $_GET parameters that should _not_
// override the default.
@@ -71,7 +71,7 @@ class TableSortTest extends DrupalUnitTestCase {
);
$ts = tablesort_init($headers);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, t('Simple table headers plus non-overriding $_GET parameters sorted correctly.'));
$this->assertEqual($ts, $expected_ts, 'Simple table headers plus non-overriding $_GET parameters sorted correctly.');
// Test with simple table headers plus $_GET parameters that _should_
// override the default.
@@ -87,7 +87,7 @@ class TableSortTest extends DrupalUnitTestCase {
$expected_ts['query'] = array('alpha' => 'beta');
$ts = tablesort_init($headers);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, t('Simple table headers plus $_GET parameters sorted correctly.'));
$this->assertEqual($ts, $expected_ts, 'Simple table headers plus $_GET parameters sorted correctly.');
// Test complex table headers.
@@ -118,7 +118,7 @@ class TableSortTest extends DrupalUnitTestCase {
'query' => array(),
);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, t('Complex table headers sorted correctly.'));
$this->assertEqual($ts, $expected_ts, 'Complex table headers sorted correctly.');
// Test complex table headers plus $_GET parameters that should _not_
// override the default.
@@ -137,7 +137,7 @@ class TableSortTest extends DrupalUnitTestCase {
'query' => array(),
);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, t('Complex table headers plus non-overriding $_GET parameters sorted correctly.'));
$this->assertEqual($ts, $expected_ts, 'Complex table headers plus non-overriding $_GET parameters sorted correctly.');
unset($_GET['sort'], $_GET['order'], $_GET['alpha']);
// Test complex table headers plus $_GET parameters that _should_
@@ -159,7 +159,7 @@ class TableSortTest extends DrupalUnitTestCase {
);
$ts = tablesort_init($headers);
$this->verbose(strtr('$ts: <pre>!ts</pre>', array('!ts' => check_plain(var_export($ts, TRUE)))));
$this->assertEqual($ts, $expected_ts, t('Complex table headers plus $_GET parameters sorted correctly.'));
$this->assertEqual($ts, $expected_ts, 'Complex table headers plus $_GET parameters sorted correctly.');
unset($_GET['sort'], $_GET['order'], $_GET['alpha']);
}
+3 -4
View File
@@ -6,8 +6,7 @@ core = 7.x
hidden = TRUE
dependencies[] = taxonomy
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -109,3 +109,33 @@ function taxonomy_test_get_antonym($tid) {
->execute()
->fetchField();
}
/**
* Implements hook_query_alter().
*/
function taxonomy_test_query_alter(QueryAlterableInterface $query) {
$value = variable_get(__FUNCTION__);
if (isset($value)) {
variable_set(__FUNCTION__, ++$value);
}
}
/**
* Implements hook_query_TAG_alter().
*/
function taxonomy_test_query_term_access_alter(QueryAlterableInterface $query) {
$value = variable_get(__FUNCTION__);
if (isset($value)) {
variable_set(__FUNCTION__, ++$value);
}
}
/**
* Implements hook_query_TAG_alter().
*/
function taxonomy_test_query_taxonomy_term_access_alter(QueryAlterableInterface $query) {
$value = variable_get(__FUNCTION__);
if (isset($value)) {
variable_set(__FUNCTION__, ++$value);
}
}
+268 -56
View File
@@ -33,22 +33,22 @@ class ThemeTestCase extends DrupalWebTestCase {
variable_set('site_frontpage', 'nobody-home');
$args = array('node', '1', 'edit');
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1', 'page__node__edit'), t('Found expected node edit page suggestions'));
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1', 'page__node__edit'), 'Found expected node edit page suggestions');
// Check attack vectors.
$args = array('node', '\\1');
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\ from suggestions'));
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), 'Removed invalid \\ from suggestions');
$args = array('node', '1/');
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid / from suggestions'));
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), 'Removed invalid / from suggestions');
$args = array('node', "1\0");
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\0 from suggestions'));
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), 'Removed invalid \\0 from suggestions');
// Define path with hyphens to be used to generate suggestions.
$args = array('node', '1', 'hyphen-path');
$result = array('page__node', 'page__node__%', 'page__node__1', 'page__node__hyphen_path');
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, $result, t('Found expected page suggestions for paths containing hyphens.'));
$this->assertEqual($suggestions, $result, 'Found expected page suggestions for paths containing hyphens.');
}
/**
@@ -78,7 +78,7 @@ class ThemeTestCase extends DrupalWebTestCase {
$suggestions = theme_get_suggestions(explode('/', $_GET['q']), 'page');
// Set it back to not annoy the batch runner.
$_GET['q'] = $q;
$this->assertTrue(in_array('page__front', $suggestions), t('Front page template was suggested.'));
$this->assertTrue(in_array('page__front', $suggestions), 'Front page template was suggested.');
}
/**
@@ -86,7 +86,7 @@ class ThemeTestCase extends DrupalWebTestCase {
*/
function testAlter() {
$this->drupalGet('theme-test/alter');
$this->assertText('The altered data is test_theme_theme_test_alter_alter was invoked.', t('The theme was able to implement an alter hook during page building before anything was rendered.'));
$this->assertText('The altered data is test_theme_theme_test_alter_alter was invoked.', 'The theme was able to implement an alter hook during page building before anything was rendered.');
}
/**
@@ -101,7 +101,7 @@ class ThemeTestCase extends DrupalWebTestCase {
// test theme. First we test with CSS aggregation disabled.
variable_set('preprocess_css', 0);
$this->drupalGet('theme-test/suggestion');
$this->assertNoText('system.base.css', t('The theme\'s .info file is able to override a module CSS file from being added to the page.'));
$this->assertNoText('system.base.css', 'The theme\'s .info file is able to override a module CSS file from being added to the page.');
// Also test with aggregation enabled, simply ensuring no PHP errors are
// triggered during drupal_build_css_cache() when a source file doesn't
@@ -131,19 +131,19 @@ class ThemeTestCase extends DrupalWebTestCase {
function testListThemes() {
$themes = list_themes();
// Check if drupal_theme_access() retrieves enabled themes properly from list_themes().
$this->assertTrue(drupal_theme_access('test_theme'), t('Enabled theme detected'));
$this->assertTrue(drupal_theme_access('test_theme'), 'Enabled theme detected');
// Check if list_themes() returns disabled themes.
$this->assertTrue(array_key_exists('test_basetheme', $themes), t('Disabled theme detected'));
$this->assertTrue(array_key_exists('test_basetheme', $themes), 'Disabled theme detected');
// Check for base theme and subtheme lists.
$base_theme_list = array('test_basetheme' => 'Theme test base theme');
$sub_theme_list = array('test_subtheme' => 'Theme test subtheme');
$this->assertIdentical($themes['test_basetheme']->sub_themes, $sub_theme_list, t('Base theme\'s object includes list of subthemes.'));
$this->assertIdentical($themes['test_subtheme']->base_themes, $base_theme_list, t('Subtheme\'s object includes list of base themes.'));
$this->assertIdentical($themes['test_basetheme']->sub_themes, $sub_theme_list, 'Base theme\'s object includes list of subthemes.');
$this->assertIdentical($themes['test_subtheme']->base_themes, $base_theme_list, 'Subtheme\'s object includes list of base themes.');
// Check for theme engine in subtheme.
$this->assertIdentical($themes['test_subtheme']->engine, 'phptemplate', t('Subtheme\'s object includes the theme engine.'));
$this->assertIdentical($themes['test_subtheme']->engine, 'phptemplate', 'Subtheme\'s object includes the theme engine.');
// Check for theme engine prefix.
$this->assertIdentical($themes['test_basetheme']->prefix, 'phptemplate', t('Base theme\'s object includes the theme engine prefix.'));
$this->assertIdentical($themes['test_subtheme']->prefix, 'phptemplate', t('Subtheme\'s object includes the theme engine prefix.'));
$this->assertIdentical($themes['test_basetheme']->prefix, 'phptemplate', 'Base theme\'s object includes the theme engine prefix.');
$this->assertIdentical($themes['test_subtheme']->prefix, 'phptemplate', 'Subtheme\'s object includes the theme engine prefix.');
}
/**
@@ -151,9 +151,18 @@ class ThemeTestCase extends DrupalWebTestCase {
*/
function testThemeGetSetting() {
$GLOBALS['theme_key'] = 'test_theme';
$this->assertIdentical(theme_get_setting('theme_test_setting'), 'default value', t('theme_get_setting() uses the default theme automatically.'));
$this->assertNotEqual(theme_get_setting('subtheme_override', 'test_basetheme'), theme_get_setting('subtheme_override', 'test_subtheme'), t('Base theme\'s default settings values can be overridden by subtheme.'));
$this->assertIdentical(theme_get_setting('basetheme_only', 'test_subtheme'), 'base theme value', t('Base theme\'s default settings values are inherited by subtheme.'));
$this->assertIdentical(theme_get_setting('theme_test_setting'), 'default value', 'theme_get_setting() uses the default theme automatically.');
$this->assertNotEqual(theme_get_setting('subtheme_override', 'test_basetheme'), theme_get_setting('subtheme_override', 'test_subtheme'), 'Base theme\'s default settings values can be overridden by subtheme.');
$this->assertIdentical(theme_get_setting('basetheme_only', 'test_subtheme'), 'base theme value', 'Base theme\'s default settings values are inherited by subtheme.');
}
/**
* Test the drupal_add_region_content() function.
*/
function testDrupalAddRegionContent() {
$this->drupalGet('theme-test/drupal-add-region-content');
$this->assertText('Hello');
$this->assertText('World');
}
}
@@ -177,8 +186,8 @@ class ThemeTableTestCase extends DrupalWebTestCase {
$rows = array(array(1,2,3), array(4,5,6), array(7,8,9));
$this->content = theme('table', array('header' => $header, 'rows' => $rows));
$js = drupal_add_js();
$this->assertTrue(isset($js['misc/tableheader.js']), t('tableheader.js was included when $sticky = TRUE.'));
$this->assertRaw('sticky-enabled', t('Table has a class of sticky-enabled when $sticky = TRUE.'));
$this->assertTrue(isset($js['misc/tableheader.js']), 'tableheader.js was included when $sticky = TRUE.');
$this->assertRaw('sticky-enabled', 'Table has a class of sticky-enabled when $sticky = TRUE.');
drupal_static_reset('drupal_add_js');
}
@@ -193,8 +202,8 @@ class ThemeTableTestCase extends DrupalWebTestCase {
$colgroups = array();
$this->content = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => $attributes, 'caption' => $caption, 'colgroups' => $colgroups, 'sticky' => FALSE));
$js = drupal_add_js();
$this->assertFalse(isset($js['misc/tableheader.js']), t('tableheader.js was not included because $sticky = FALSE.'));
$this->assertNoRaw('sticky-enabled', t('Table does not have a class of sticky-enabled because $sticky = FALSE.'));
$this->assertFalse(isset($js['misc/tableheader.js']), 'tableheader.js was not included because $sticky = FALSE.');
$this->assertNoRaw('sticky-enabled', 'Table does not have a class of sticky-enabled because $sticky = FALSE.');
drupal_static_reset('drupal_add_js');
}
@@ -211,10 +220,45 @@ class ThemeTableTestCase extends DrupalWebTestCase {
),
);
$this->content = theme('table', array('header' => $header, 'rows' => array(), 'empty' => t('No strings available.')));
$this->assertRaw('<tr class="odd"><td colspan="3" class="empty message">No strings available.</td>', t('Correct colspan was set on empty message.'));
$this->assertRaw('<thead><tr><th>Header 1</th>', t('Table header was printed.'));
$this->assertRaw('<tr class="odd"><td colspan="3" class="empty message">No strings available.</td>', 'Correct colspan was set on empty message.');
$this->assertRaw('<thead><tr><th>Header 1</th>', 'Table header was printed.');
}
/**
* Tests that the 'no_striping' option works correctly.
*/
function testThemeTableWithNoStriping() {
$rows = array(
array(
'data' => array(1),
'no_striping' => TRUE,
),
);
$this->content = theme('table', array('rows' => $rows));
$this->assertNoRaw('class="odd"', 'Odd/even classes were not added because $no_striping = TRUE.');
$this->assertNoRaw('no_striping', 'No invalid no_striping HTML attribute was printed.');
}
/**
* Test that the 'footer' option works correctly.
*/
function testThemeTableFooter() {
$footer = array(
array(
'data' => array(1),
),
array('Foo'),
);
$table = array(
'rows' => array(),
'footer' => $footer,
);
$this->content = theme('table', $table);
$this->content = preg_replace('@>\s+<@', '><', $this->content);
$this->assertRaw('<tfoot><tr><td>1</td></tr><tr><td>Foo</td></tr></tfoot>', 'Table footer found.');
}
}
/**
@@ -321,14 +365,14 @@ class ThemeLinksTest extends DrupalWebTestCase {
$html = drupal_render($render_array);
$dom = new DOMDocument();
$dom->loadHTML($html);
$this->assertEqual($dom->getElementsByTagName('ul')->length, 1, t('One "ul" tag found in the rendered HTML.'));
$this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered HTML.');
$list_elements = $dom->getElementsByTagName('li');
$this->assertEqual($list_elements->length, 3, t('Three "li" tags found in the rendered HTML.'));
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', t('First expected link found.'));
$this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', t('Second expected link found.'));
$this->assertEqual($list_elements->item(2)->nodeValue, 'Second child link', t('Third expected link found.'));
$this->assertIdentical(strpos($html, 'Parent link copy'), FALSE, t('"Parent link copy" link not found.'));
$this->assertIdentical(strpos($html, 'Third child link'), FALSE, t('"Third child link" link not found.'));
$this->assertEqual($list_elements->length, 3, 'Three "li" tags found in the rendered HTML.');
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
$this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
$this->assertEqual($list_elements->item(2)->nodeValue, 'Second child link', 'Third expected link found.');
$this->assertIdentical(strpos($html, 'Parent link copy'), FALSE, '"Parent link copy" link not found.');
$this->assertIdentical(strpos($html, 'Third child link'), FALSE, '"Third child link" link not found.');
// Now render 'first_child', followed by the rest of the links, and make
// sure we get two separate <ul>'s with the appropriate links contained
@@ -339,21 +383,21 @@ class ThemeLinksTest extends DrupalWebTestCase {
// First check the child HTML.
$dom = new DOMDocument();
$dom->loadHTML($child_html);
$this->assertEqual($dom->getElementsByTagName('ul')->length, 1, t('One "ul" tag found in the rendered child HTML.'));
$this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered child HTML.');
$list_elements = $dom->getElementsByTagName('li');
$this->assertEqual($list_elements->length, 2, t('Two "li" tags found in the rendered child HTML.'));
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link copy', t('First expected link found.'));
$this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', t('Second expected link found.'));
$this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered child HTML.');
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link copy', 'First expected link found.');
$this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
// Then check the parent HTML.
$dom = new DOMDocument();
$dom->loadHTML($parent_html);
$this->assertEqual($dom->getElementsByTagName('ul')->length, 1, t('One "ul" tag found in the rendered parent HTML.'));
$this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered parent HTML.');
$list_elements = $dom->getElementsByTagName('li');
$this->assertEqual($list_elements->length, 2, t('Two "li" tags found in the rendered parent HTML.'));
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', t('First expected link found.'));
$this->assertEqual($list_elements->item(1)->nodeValue, 'Second child link', t('Second expected link found.'));
$this->assertIdentical(strpos($parent_html, 'First child link'), FALSE, t('"First child link" link not found.'));
$this->assertIdentical(strpos($parent_html, 'Third child link'), FALSE, t('"Third child link" link not found.'));
$this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered parent HTML.');
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
$this->assertEqual($list_elements->item(1)->nodeValue, 'Second child link', 'Second expected link found.');
$this->assertIdentical(strpos($parent_html, 'First child link'), FALSE, '"First child link" link not found.');
$this->assertIdentical(strpos($parent_html, 'Third child link'), FALSE, '"Third child link" link not found.');
}
}
@@ -378,8 +422,8 @@ class ThemeHookInitTestCase extends DrupalWebTestCase {
*/
function testThemeInitializationHookInit() {
$this->drupalGet('theme-test/hook-init');
$this->assertRaw('Themed output generated in hook_init()', t('Themed output generated in hook_init() correctly appears on the page.'));
$this->assertRaw('bartik/css/style.css', t("The default theme's CSS appears on the page when the theme system is initialized in hook_init()."));
$this->assertRaw('Themed output generated in hook_init()', 'Themed output generated in hook_init() correctly appears on the page.');
$this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page when the theme system is initialized in hook_init().");
}
}
@@ -406,33 +450,105 @@ class ThemeFastTestCase extends DrupalWebTestCase {
function testUserAutocomplete() {
$this->drupalLogin($this->account);
$this->drupalGet('user/autocomplete/' . $this->account->name);
$this->assertText('registry not initialized', t('The registry was not initialized'));
$this->assertText('registry not initialized', 'The registry was not initialized');
}
}
/**
* Unit tests for theme_html_tag().
* Tests the markup of core render element types passed to drupal_render().
*/
class ThemeHtmlTag extends DrupalUnitTestCase {
class RenderElementTypesTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Theme HTML Tag',
'description' => 'Tests theme_html_tag() built-in theme functions.',
'name' => 'Render element types',
'description' => 'Tests the markup of core render element types passed to drupal_render().',
'group' => 'Theme',
);
}
/**
* Test function theme_html_tag()
* Asserts that an array of elements is rendered properly.
*
* @param array $elements
* An array of associative arrays describing render elements and their
* expected markup. Each item in $elements must contain the following:
* - 'name': This human readable description will be displayed on the test
* results page.
* - 'value': This is the render element to test.
* - 'expected': This is the expected markup for the element in 'value'.
*/
function testThemeHtmlTag() {
// Test auto-closure meta tag generation
$tag['element'] = array('#tag' => 'meta', '#attributes' => array('name' => 'description', 'content' => 'Drupal test'));
$this->assertEqual('<meta name="description" content="Drupal test" />'."\n", theme_html_tag($tag), t('Test auto-closure meta tag generation.'));
function assertElements($elements) {
foreach($elements as $element) {
$this->assertIdentical(drupal_render($element['value']), $element['expected'], '"' . $element['name'] . '" input rendered correctly by drupal_render().');
}
}
// Test title tag generation
$tag['element'] = array('#tag' => 'title', '#value' => 'title test');
$this->assertEqual('<title>title test</title>'."\n", theme_html_tag($tag), t('Test title tag generation.'));
/**
* Tests system #type 'container'.
*/
function testContainer() {
$elements = array(
// Basic container with no attributes.
array(
'name' => "#type 'container' with no HTML attributes",
'value' => array(
'#type' => 'container',
'child' => array(
'#markup' => 'foo',
),
),
'expected' => '<div>foo</div>',
),
// Container with a class.
array(
'name' => "#type 'container' with a class HTML attribute",
'value' => array(
'#type' => 'container',
'child' => array(
'#markup' => 'foo',
),
'#attributes' => array(
'class' => 'bar',
),
),
'expected' => '<div class="bar">foo</div>',
),
);
$this->assertElements($elements);
}
/**
* Tests system #type 'html_tag'.
*/
function testHtmlTag() {
$elements = array(
// Test auto-closure meta tag generation.
array(
'name' => "#type 'html_tag' auto-closure meta tag generation",
'value' => array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'description',
'content' => 'Drupal test',
),
),
'expected' => '<meta name="description" content="Drupal test" />' . "\n",
),
// Test title tag generation.
array(
'name' => "#type 'html_tag' title tag generation",
'value' => array(
'#type' => 'html_tag',
'#tag' => 'title',
'#value' => 'title test',
),
'expected' => '<title>title test</title>' . "\n",
),
);
$this->assertElements($elements);
}
}
@@ -486,3 +602,99 @@ class ThemeRegistryTestCase extends DrupalWebTestCase {
$this->assertTrue($registry['theme_test_template_test_2'], 'Offset was returned correctly from the theme registry');
}
}
/**
* Tests for theme debug markup.
*/
class ThemeDebugMarkupTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Theme debug markup',
'description' => 'Tests theme debug markup output.',
'group' => 'Theme',
);
}
function setUp() {
parent::setUp('theme_test', 'node');
theme_enable(array('test_theme'));
}
/**
* Tests debug markup added to template output.
*/
function testDebugOutput() {
variable_set('theme_default', 'test_theme');
// Enable the debug output.
variable_set('theme_debug', TRUE);
$registry = theme_get_registry();
$extension = '.tpl.php';
// Populate array of templates.
$templates = drupal_find_theme_templates($registry, $extension, drupal_get_path('theme', 'test_theme'));
$templates += drupal_find_theme_templates($registry, $extension, drupal_get_path('module', 'node'));
// Create a node and test different features of the debug markup.
$node = $this->drupalCreateNode();
$this->drupalGet('node/' . $node->nid);
$this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
$this->assertRaw("CALL: theme('node')", 'Theme call information found.');
$this->assertRaw('x node--1' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node' . $extension, 'Suggested template files found in order and node ID specific template shown as current template.');
$template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension;
$this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');
// Create another node and make sure the template suggestions shown in the
// debug markup are correct.
$node2 = $this->drupalCreateNode();
$this->drupalGet('node/' . $node2->nid);
$this->assertRaw('* node--2' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' x node' . $extension, 'Suggested template files found in order and base template shown as current template.');
// Create another node and make sure the template suggestions shown in the
// debug markup are correct.
$node3 = $this->drupalCreateNode();
$build = array('#theme' => 'node__foo__bar');
$build += node_view($node3);
$output = drupal_render($build);
$this->assertTrue(strpos($output, "CALL: theme('node__foo__bar')") !== FALSE, 'Theme call information found.');
$this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
// Disable theme debug.
variable_set('theme_debug', FALSE);
$this->drupalGet('node/' . $node->nid);
$this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
}
}
/**
* Tests module-provided theme engines.
*/
class ModuleProvidedThemeEngineTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Theme engine test',
'description' => 'Tests module-provided theme engines.',
'group' => 'Theme',
);
}
function setUp() {
parent::setUp('theme_test');
theme_enable(array('test_theme', 'test_theme_nyan_cat'));
}
/**
* Ensures that the module provided theme engine is found and used by core.
*/
function testEngineIsFoundAndWorking() {
variable_set('theme_default', 'test_theme_nyan_cat');
variable_set('admin_theme', 'test_theme_nyan_cat');
$this->drupalGet('theme-test/engine-info-test');
$this->assertText('Miaou');
}
}
+3 -4
View File
@@ -5,8 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"

Some files were not shown because too many files have changed in this diff Show More