diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 251c5c1..2592a72 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -245,7 +245,8 @@ abstract class DrupalTestCase { } /** - * Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). + * Check to see if a value is not false (not an empty string, 0, NULL, + * or FALSE). * * @param $value * The value on which the assertion is to be done. @@ -555,21 +556,29 @@ abstract class DrupalTestCase { 'file' => $exception->getFile(), )); require_once DRUPAL_ROOT . '/includes/errors.inc'; - // The exception message is run through check_plain() by _drupal_decode_exception(). + // The exception message is run through check_plain() + // by _drupal_decode_exception(). $this->error(t('%type: !message in %function (line %line of %file).', _drupal_decode_exception($exception)), 'Uncaught exception', _drupal_get_last_caller($backtrace)); } /** * Generates a random string of ASCII characters of codes 32 to 126. * - * The generated string includes alpha-numeric characters and common misc - * characters. Use this method when testing general input where the content - * is not restricted. + * The generated string includes alpha-numeric characters and common + * miscellaneous characters. Use this method when testing general input + * where the content is not restricted. + * + * Do not use this method when special characters are not possible (e.g., in + * machine or file names that have already been validated); instead, + * use DrupalWebTestCase::randomName(). * * @param $length * Length of random string to generate. + * * @return * Randomly generated string. + * + * @see DrupalWebTestCase::randomName() */ public static function randomString($length = 8) { $str = ''; @@ -588,10 +597,16 @@ abstract class DrupalTestCase { * require machine readable values (i.e. without spaces and non-standard * characters) this method is best. * + * Do not use this method when testing unvalidated user input. Instead, use + * DrupalWebTestCase::randomString(). + * * @param $length * Length of random string to generate. + * * @return * Randomly generated string. + * + * @see DrupalWebTestCase::randomString() */ public static function randomName($length = 8) { $values = array_merge(range(65, 90), range(97, 122), range(48, 57)); @@ -687,7 +702,8 @@ class DrupalUnitTestCase extends DrupalTestCase { // Reset all statics so that test is performed with a clean environment. drupal_static_reset(); - // Generate temporary prefixed database to ensure that tests have a clean starting point. + // Generate temporary prefixed database to ensure that tests have + // a clean starting point. $this->databasePrefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}'); // Create test directory. @@ -774,14 +790,16 @@ class DrupalWebTestCase extends DrupalTestCase { protected $content; /** - * The content of the page currently loaded in the internal browser (plain text version). + * The content of the page currently loaded in the internal browser + * (plain text version). * * @var string */ protected $plainTextContent; /** - * The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser. + * The value of the Drupal.settings JavaScript variable for the page + * currently loaded in the internal browser. * * @var Array */ @@ -817,14 +835,16 @@ class DrupalWebTestCase extends DrupalTestCase { protected $additionalCurlOptions = array(); /** - * The original user, before it was changed to a clean uid = 1 for testing purposes. + * The original user, before it was changed to a clean uid = 1 for testing + * purposes. * * @var object */ protected $originalUser = NULL; /** - * The original shutdown handlers array, before it was cleaned for testing purposes. + * The original shutdown handlers array, before it was cleaned for testing + * purposes. * * @var array */ @@ -994,7 +1014,8 @@ class DrupalWebTestCase extends DrupalTestCase { $this->assertEqual($saved_type, SAVED_NEW, t('Created content type %type.', array('%type' => $type->type))); - // Reset permissions so that permissions for this content type are available. + // Reset permissions so that permissions for this content type are + // available. $this->checkPermissions(array(), TRUE); return $type; @@ -1004,7 +1025,8 @@ class DrupalWebTestCase extends DrupalTestCase { * Get a list files that can be used in tests. * * @param $type - * File type, possible values: 'binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'. + * File type, possible values: 'binary', 'html', 'image', 'javascript', + * 'php', 'sql', 'text'. * @param $size * File size in bytes to match. Please check the tests/files folder. * @return @@ -1234,7 +1256,8 @@ class DrupalWebTestCase extends DrupalTestCase { } /* - * Logs a user out of the internal browser, then check the login page to confirm logout. + * Logs a user out of the internal browser, then check the login page to + * confirm logout. */ protected function drupalLogout() { // Make a request to the logout page, and redirect to the user page, the @@ -1264,7 +1287,8 @@ class DrupalWebTestCase extends DrupalTestCase { protected function setUp() { global $user, $language, $conf; - // Generate a temporary prefixed database to ensure that tests have a clean starting point. + // Generate a temporary prefixed database to ensure that tests have a clean + // starting point. $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000); db_update('simpletest_test_id') ->fields(array('last_prefix' => $this->databasePrefix)) @@ -1331,7 +1355,8 @@ class DrupalWebTestCase extends DrupalTestCase { // system_rebuild_module_data() (in drupal_install_system()) will register // the test's profile as a module. Without this, the installation profile of // the parent site (executing the test) is registered, and the test - // profile's hook_install() and other hook implementations are never invoked. + // profile's hook_install() and other hook implementations + // are never invoked. $conf['install_profile'] = $this->profile; include_once DRUPAL_ROOT . '/includes/install.inc'; @@ -1472,13 +1497,13 @@ class DrupalWebTestCase extends DrupalTestCase { * Refresh the in-memory set of variables. Useful after a page request is made * that changes a variable in a different thread. * - * In other words calling a settings page with $this->drupalPost() with a changed - * value would update a variable to reflect that change, but in the thread that - * made the call (thread running the test) the changed variable would not be - * picked up. + * In other words calling a settings page with $this->drupalPost() with a + * changed value would update a variable to reflect that change, but in the + * thread that made the call (thread running the test) the changed variable + * would not be picked up. * - * This method clears the variables cache and loads a fresh copy from the database - * to ensure that the most up-to-date set of variables is loaded. + * This method clears the variables cache and loads a fresh copy from the + * database to ensure that the most up-to-date set of variables is loaded. */ protected function refreshVariables() { global $conf; @@ -1487,8 +1512,8 @@ class DrupalWebTestCase extends DrupalTestCase { } /** - * Delete created files and temporary files directory, delete the tables created by setUp(), - * and reset the database prefix. + * Delete created files and temporary files directory, delete the tables + * created by setUp(), and reset the database prefix. */ protected function tearDown() { global $user, $language; @@ -1921,10 +1946,12 @@ class DrupalWebTestCase extends DrupalTestCase { $post = implode('&', $post) . $extra_post; } $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post, CURLOPT_HTTPHEADER => $headers)); - // Ensure that any changes to variables in the other thread are picked up. + // Ensure that any changes to variables in the other thread + // are picked up. $this->refreshVariables(); - // Replace original page output with new output from redirected page(s). + // Replace original page output with new output from + // redirected page(s). if ($new = $this->checkForMetaRefresh()) { $out = $new; } @@ -2186,8 +2213,8 @@ class DrupalWebTestCase extends DrupalTestCase { /** * Handle form input related to drupalPost(). Ensure that the specified fields - * exist and attempt to create POST data in the correct manner for the particular - * field type. + * exist and attempt to create POST data in the correct manner for the + * particular field type. * * @param $post * Reference to array of post values. @@ -2667,7 +2694,8 @@ class DrupalWebTestCase extends DrupalTestCase { } /** - * Gets the value of the Drupal.settings JavaScript variable for the currently loaded page. + * Gets the value of the Drupal.settings JavaScript variable for the currently + * loaded page. */ protected function drupalGetSettings() { return $this->drupalSettings; @@ -2677,7 +2705,8 @@ class DrupalWebTestCase extends DrupalTestCase { * Gets an array containing all e-mails sent during this test case. * * @param $filter - * An array containing key/value pairs used to filter the e-mails that are returned. + * An array containing key/value pairs used to filter the e-mails that + * are returned. * @return * An array containing e-mail messages captured during the current test. */ @@ -2718,7 +2747,8 @@ class DrupalWebTestCase extends DrupalTestCase { } /** - * Sets the value of the Drupal.settings JavaScript variable for the currently loaded page. + * Sets the value of the Drupal.settings JavaScript variable for the currently + * loaded page. */ protected function drupalSetSettings($settings) { $this->drupalSettings = $settings; @@ -2770,8 +2800,8 @@ class DrupalWebTestCase extends DrupalTestCase { } /** - * Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text - * refers to the raw HTML that the page generated. + * Pass if the raw text is NOT found on the loaded page, fail otherwise. + * Raw text refers to the raw HTML that the page generated. * * @param $raw * Raw (HTML) string to look for. @@ -2791,8 +2821,8 @@ class DrupalWebTestCase extends DrupalTestCase { /** * Pass if the text IS found on the text version of the page. The text version - * is the equivalent of what a user would see when viewing through a web browser. - * In other words the HTML has been filtered out of the contents. + * is the equivalent of what a user would see when viewing through a + * web browser. In other words the HTML has been filtered out of the contents. * * @param $text * Plain text to look for. @@ -2808,9 +2838,9 @@ class DrupalWebTestCase extends DrupalTestCase { } /** - * Pass if the text is NOT found on the text version of the page. The text version - * is the equivalent of what a user would see when viewing through a web browser. - * In other words the HTML has been filtered out of the contents. + * Pass if the text is NOT found on the text version of the page. The text + * version is the equivalent of what a user would see when viewing through a + * web browser. In other words the HTML has been filtered out of the contents. * * @param $text * Plain text to look for. @@ -2903,7 +2933,8 @@ class DrupalWebTestCase extends DrupalTestCase { * @param $group * The group this message belongs to. * @param $be_unique - * TRUE if this text should be found only once, FALSE if it should be found more than once. + * TRUE if this text should be found only once, FALSE if it should be found + * more than once. * @return * TRUE on pass, FALSE on fail. */ @@ -3114,7 +3145,8 @@ class DrupalWebTestCase extends DrupalTestCase { } /** - * Asserts that a field exists in the current page with the given name and value. + * Asserts that a field exists in the current page with the given name + * and value. * * @param $name * Name of field to assert. @@ -3327,7 +3359,8 @@ class DrupalWebTestCase extends DrupalTestCase { } /** - * Helper function: construct an XPath for the given set of attributes and value. + * Helper function: construct an XPath for the given set of attributes and + * value. * * @param $attribute * Field attributes. @@ -3382,7 +3415,8 @@ class DrupalWebTestCase extends DrupalTestCase { * The field in $name must have the content described in $value. * * @param $name - * Name of field or message property to assert. Examples: subject, body, id, ... + * Name of field or message property to assert. Examples: subject, body, + * id, ... * @param $value * Value of the field to assert. * @param $message