summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/simpletest/drupal_web_test_case.php402
-rw-r--r--modules/simpletest/simpletest.module10
-rw-r--r--modules/simpletest/simpletest.test10
-rw-r--r--modules/simpletest/tests/common.test12
-rw-r--r--modules/simpletest/tests/database_test.test2
-rw-r--r--modules/simpletest/tests/session.test6
-rwxr-xr-xscripts/run-tests.sh6
7 files changed, 264 insertions, 184 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 4d43592d1..73aec6f2e 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -5,40 +5,119 @@
* Test case for typical Drupal tests.
*/
class DrupalWebTestCase {
- protected $_logged_in = FALSE;
- protected $_content;
- protected $_url;
- protected $plain_text;
- protected $ch;
- protected $elements;
- // We do not reuse the cookies in further runs, so we do not need a file
- // but we still need cookie handling, so we set the jar to NULL
- protected $cookie_file = NULL;
- // Overwrite this any time to supply cURL options as necessary,
- // DrupalTestCase itself never sets this but always obeys whats set.
- protected $curl_options = array();
- protected $db_prefix_original;
- protected $original_file_directory;
-
- var $_results = array('#pass' => 0, '#fail' => 0, '#exception' => 0);
- var $_assertions = array();
+
+ /**
+ * The test run ID.
+ *
+ * @var string
+ */
+ protected $testId;
+
+ /**
+ * The URL currently loaded in the internal browser.
+ *
+ * @var string
+ */
+ protected $url;
+
+ /**
+ * The handle of the current cURL connection.
+ *
+ * @var resource
+ */
+ protected $curlHandle;
+
+ /**
+ * The content of the page currently loaded in the internal browser.
+ *
+ * @var string
+ */
+ protected $content;
+
+ /**
+ * The content of the page currently loaded in the internal browser (plain text version).
+ *
+ * @var string
+ */
+ protected $plainTextContent;
+
+ /**
+ * The parsed version of the page.
+ *
+ * @var SimpleXMLElement
+ */
+ protected $elements = NULL;
+
+ /**
+ * Whether a user is logged in the internal browser.
+ *
+ * @var bool
+ */
+ protected $isLoggedIn = FALSE;
+
+ /**
+ * The current cookie file used by cURL.
+ *
+ * We do not reuse the cookies in further runs, so we do not need a file
+ * but we still need cookie handling, so we set the jar to NULL.
+ */
+ protected $cookieFile = NULL;
+
+ /**
+ * Additional cURL options.
+ *
+ * DrupalWebTestCase itself never sets this but always obeys what is set.
+ */
+ protected $additionalCurlOptions = array();
+
+ /**
+ * The original database prefix, before it was changed for testing purposes.
+ *
+ * @var string
+ */
+ protected $originalPrefix = NULL;
+
+ /**
+ * The original file directory, before it was changed for testing purposes.
+ *
+ * @var string
+ */
+ protected $originalFileDirectory = NULL;
+
+ /**
+ * Current results of this test case.
+ *
+ * @var Array
+ */
+ public $results = array(
+ '#pass' => 0,
+ '#fail' => 0,
+ '#exception' => 0,
+ );
+
+ /**
+ * Assertions thrown in that test case.
+ *
+ * @var Array
+ */
+ protected $assertions = array();
/**
* Constructor for DrupalWebTestCase.
*
- * @param @test_id
+ * @param $test_id
* Tests with the same id are reported together.
*/
- function __construct($test_id = NULL) {
- $this->test_id = $test_id;
+ public function __construct($test_id = NULL) {
+ $this->testId = $test_id;
}
/**
- * This function stores the assert. Do not call directly.
+ * Internal helper: stores the assert.
*
* @param $status
- * Can be 'pass', 'fail', 'exception'. TRUE is a synonym for 'pass', FALSE
- * for 'fail'.
+ * Can be 'pass', 'fail', 'exception'.
+ * TRUE is a synonym for 'pass', FALSE for 'fail'.
* @param $message
* The message string.
* @param $group
@@ -50,7 +129,7 @@ class DrupalWebTestCase {
* the name of the source file, 'line' is the line number and 'function'
* is the caller function itself.
*/
- protected function _assert($status, $message = '', $group = 'Other', $caller = NULL) {
+ private function assert($status, $message = '', $group = 'Other', $caller = NULL) {
global $db_prefix;
// Convert boolean status to string status.
@@ -59,7 +138,7 @@ class DrupalWebTestCase {
}
// Increment summary result counter.
- $this->_results['#' . $status]++;
+ $this->results['#' . $status]++;
// Get the function information about the call to the assertion method.
if (!$caller) {
@@ -68,11 +147,11 @@ class DrupalWebTestCase {
// Switch to non-testing database to store results in.
$current_db_prefix = $db_prefix;
- $db_prefix = $this->db_prefix_original;
+ $db_prefix = $this->originalPrefix;
// Creation assertion array that can be displayed while tests are running.
- $this->_assertions[] = $assertion = array(
- 'test_id' => $this->test_id,
+ $this->assertions[] = $assertion = array(
+ 'test_id' => $this->testId,
'test_class' => get_class($this),
'status' => $status,
'message' => $message,
@@ -87,7 +166,7 @@ class DrupalWebTestCase {
// Return to testing prefix.
$db_prefix = $current_db_prefix;
- return $status;
+ return $status == 'pass' ? TRUE : FALSE;
}
/**
@@ -122,10 +201,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertTrue($value, $message = '', $group = 'Other') {
- return $this->_assert((bool) $value, $message ? $message : t('Value is TRUE'), $group);
+ return $this->assert((bool) $value, $message ? $message : t('Value is TRUE'), $group);
}
/**
@@ -138,10 +217,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertFalse($value, $message = '', $group = 'Other') {
- return $this->_assert(!$value, $message ? $message : t('Value is FALSE'), $group);
+ return $this->assert(!$value, $message ? $message : t('Value is FALSE'), $group);
}
/**
@@ -154,10 +233,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNull($value, $message = '', $group = 'Other') {
- return $this->_assert(!isset($value), $message ? $message : t('Value is NULL'), $group);
+ return $this->assert(!isset($value), $message ? $message : t('Value is NULL'), $group);
}
/**
@@ -170,10 +249,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotNull($value, $message = '', $group = 'Other') {
- return $this->_assert(isset($value), $message ? $message : t('Value is not NULL'), $group);
+ return $this->assert(isset($value), $message ? $message : t('Value is not NULL'), $group);
}
/**
@@ -188,10 +267,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertEqual($first, $second, $message = '', $group = 'Other') {
- return $this->_assert($first == $second, $message ? $message : t('First value is equal to second value'), $group);
+ return $this->assert($first == $second, $message ? $message : t('First value is equal to second value'), $group);
}
/**
@@ -206,10 +285,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotEqual($first, $second, $message = '', $group = 'Other') {
- return $this->_assert($first != $second, $message ? $message : t('First value is not equal to second value'), $group);
+ return $this->assert($first != $second, $message ? $message : t('First value is not equal to second value'), $group);
}
/**
@@ -224,10 +303,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertIdentical($first, $second, $message = '', $group = 'Other') {
- return $this->_assert($first === $second, $message ? $message : t('First value is identical to second value'), $group);
+ return $this->assert($first === $second, $message ? $message : t('First value is identical to second value'), $group);
}
/**
@@ -242,10 +321,10 @@ class DrupalWebTestCase {
* @param $group
* The type of assertion - examples are "Browser", "PHP".
* @return
- * The status passed in.
+ * TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') {
- return $this->_assert($first !== $second, $message ? $message : t('First value is not identical to second value'), $group);
+ return $this->assert($first !== $second, $message ? $message : t('First value is not identical to second value'), $group);
}
/**
@@ -259,7 +338,7 @@ class DrupalWebTestCase {
* TRUE.
*/
protected function pass($message = NULL, $group = 'Other') {
- return $this->_assert(TRUE, $message, $group);
+ return $this->assert(TRUE, $message, $group);
}
/**
@@ -273,7 +352,7 @@ class DrupalWebTestCase {
* FALSE.
*/
protected function fail($message = NULL, $group = 'Other') {
- return $this->_assert(FALSE, $message, $group);
+ return $this->assert(FALSE, $message, $group);
}
/**
@@ -285,15 +364,17 @@ class DrupalWebTestCase {
* The type of assertion - examples are "Browser", "PHP".
* @param $caller
* The caller of the error.
+ * @return
+ * FALSE.
*/
protected function error($message = '', $group = 'Other', $caller = NULL) {
- return $this->_assert('exception', $message, $group, $caller);
+ return $this->assert('exception', $message, $group, $caller);
}
/**
* Run all tests in this class.
*/
- function run() {
+ public function run() {
set_error_handler(array($this, 'errorHandler'));
$methods = array();
// Iterate through all the methods in this class.
@@ -319,9 +400,11 @@ class DrupalWebTestCase {
/**
* Handle errors.
*
+ * Because this is registered in set_error_handler(), it has to be public.
* @see set_error_handler
+ *
*/
- function errorHandler($severity, $message, $file = NULL, $line = NULL) {
+ public function errorHandler($severity, $message, $file = NULL, $line = NULL) {
if ($severity & error_reporting()) {
$error_map = array(
E_STRICT => 'Run-time notice',
@@ -346,7 +429,7 @@ class DrupalWebTestCase {
*
* @see set_exception_handler
*/
- function exceptionHandler($exception) {
+ protected function exceptionHandler($exception) {
$backtrace = $exception->getTrace();
// Push on top of the backtrace the call that generated the exception.
array_unshift($backtrace, array(
@@ -362,9 +445,10 @@ class DrupalWebTestCase {
* @param $settings
* An associative array of settings to change from the defaults, keys are
* node properties, for example 'body' => 'Hello, world!'.
- * @return object Created node object.
+ * @return
+ * Created node object.
*/
- function drupalCreateNode($settings = array()) {
+ protected function drupalCreateNode($settings = array()) {
// Populate defaults array
$defaults = array(
'body' => $this->randomName(32),
@@ -410,7 +494,7 @@ class DrupalWebTestCase {
* @return
* Created content type.
*/
- function drupalCreateContentType($settings = array()) {
+ protected function drupalCreateContentType($settings = array()) {
// find a non-existent random type name.
do {
$name = strtolower($this->randomName(3, 'type_'));
@@ -461,13 +545,13 @@ class DrupalWebTestCase {
* @return
* List of files that match filter.
*/
- function drupalGetTestFiles($type, $size = NULL) {
+ protected function drupalGetTestFiles($type, $size = NULL) {
$files = array();
// Make sure type is valid.
if (in_array($type, array('binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'))) {
// Use original file directory instead of one created during setUp().
- $path = $this->original_file_directory . '/simpletest';
+ $path = $this->originalFileDirectory . '/simpletest';
$files = file_scan_directory($path, '/' . $type . '\-.*/');
// If size is set then remove any files that are not of that size.
@@ -487,7 +571,7 @@ class DrupalWebTestCase {
/**
* Compare two files based on size and file name.
*/
- function drupalCompareFiles($file1, $file2) {
+ protected function drupalCompareFiles($file1, $file2) {
// Determine which file is larger.
$compare_size = (filesize($file1->filename) > filesize($file2->filename));
if (!$compare_size) {
@@ -510,7 +594,7 @@ class DrupalWebTestCase {
* @return
* Randomly generated string.
*/
- function randomName($number = 4, $prefix = 'simpletest_') {
+ public static function randomName($number = 4, $prefix = 'simpletest_') {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_';
for ($x = 0; $x < $number; $x++) {
$prefix .= $chars{mt_rand(0, strlen($chars) - 1)};
@@ -531,7 +615,7 @@ class DrupalWebTestCase {
* A fully loaded user object with pass_raw property, or FALSE if account
* creation fails.
*/
- function drupalCreateUser($permissions = NULL) {
+ protected function drupalCreateUser($permissions = NULL) {
// Create a role with the given permission set.
if (!($rid = $this->_drupalCreateRole($permissions))) {
return FALSE;
@@ -565,7 +649,7 @@ class DrupalWebTestCase {
* @return
* Role ID of newly created role, or FALSE if role creation failed.
*/
- private function _drupalCreateRole($permissions = NULL) {
+ protected function _drupalCreateRole(Array $permissions = NULL) {
// Generate string version of permissions list.
if ($permissions === NULL) {
$permissions = array('access comments', 'access content', 'post comments', 'post comments without approval');
@@ -604,7 +688,7 @@ class DrupalWebTestCase {
* @return
* TRUE or FALSE depending on whether the permissions are valid.
*/
- private function checkPermissions(array $permissions, $reset = FALSE) {
+ protected function checkPermissions(Array $permissions, $reset = FALSE) {
static $available;
if (!isset($available) || $reset) {
@@ -632,8 +716,8 @@ class DrupalWebTestCase {
* User that was logged in. Useful if no user was passed in order to retrieve
* the created user.
*/
- function drupalLogin($user = NULL) {
- if ($this->_logged_in) {
+ protected function drupalLogin($user = NULL) {
+ if ($this->isLoggedIn) {
$this->drupalLogout();
}
@@ -651,7 +735,7 @@ class DrupalWebTestCase {
$pass = $pass && $this->assertNoText(t('The username %name has been blocked.', array('%name' => $user->name)), t('No blocked message at login page'), t('User login'));
$pass = $pass && $this->assertNoText(t('The name %name is a reserved username.', array('%name' => $user->name)), t('No reserved message at login page'), t('User login'));
- $this->_logged_in = $pass;
+ $this->isLoggedIn = $pass;
return $user;
}
@@ -659,7 +743,7 @@ class DrupalWebTestCase {
/*
* Logs a user out of the internal browser, then check the login page to confirm logout.
*/
- function drupalLogout() {
+ protected function drupalLogout() {
// Make a request to the logout page.
$this->drupalGet('user/logout');
@@ -668,7 +752,7 @@ class DrupalWebTestCase {
$pass = $this->assertField('name', t('Username field found.'), t('Logout'));
$pass = $pass && $this->assertField('pass', t('Password field found.'), t('Logout'));
- $this->_logged_in = !$pass;
+ $this->isLoggedIn = !$pass;
}
/**
@@ -681,11 +765,11 @@ class DrupalWebTestCase {
* @param ...
* List of modules to enable for the duration of the test.
*/
- function setUp() {
+ protected function setUp() {
global $db_prefix;
// Store necessary current values before switching to prefixed database.
- $this->db_prefix_original = $db_prefix;
+ $this->originalPrefix = $db_prefix;
$clean_url_original = variable_get('clean_url', 0);
// Generate temporary prefixed database to ensure that tests have a clean starting point.
@@ -722,7 +806,7 @@ class DrupalWebTestCase {
variable_set('clean_url', $clean_url_original);
// Use temporary files directory with the same prefix as database.
- $this->original_file_directory = file_directory_path();
+ $this->originalFileDirectory = file_directory_path();
variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix);
$directory = file_directory_path();
file_check_directory($directory, FILE_CREATE_DIRECTORY); // Create the files directory.
@@ -740,7 +824,7 @@ class DrupalWebTestCase {
* 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.
*/
- function refreshVariables() {
+ protected function refreshVariables() {
global $conf;
cache_clear_all('variables', 'cache');
$conf = variable_init();
@@ -750,12 +834,12 @@ class DrupalWebTestCase {
* Delete created files and temporary files directory, delete the tables created by setUp(),
* and reset the database prefix.
*/
- function tearDown() {
+ protected function tearDown() {
global $db_prefix;
if (preg_match('/simpletest\d+/', $db_prefix)) {
// Delete temporary files directory and reset files directory path.
simpletest_clean_temporary_directory(file_directory_path());
- variable_set('file_directory_path', $this->original_file_directory);
+ variable_set('file_directory_path', $this->originalFileDirectory);
// Remove all prefixed tables (all the tables in the schema).
$schema = drupal_get_schema(NULL, TRUE);
@@ -765,10 +849,10 @@ class DrupalWebTestCase {
}
// Return the database prefix to the original.
- $db_prefix = $this->db_prefix_original;
+ $db_prefix = $this->originalPrefix;
// Ensure that the internal logged in variable is reset.
- $this->_logged_in = FALSE;
+ $this->isLoggedIn = FALSE;
// Reload module list and implementations to ensure that test module hooks
// aren't called after tests.
@@ -792,10 +876,10 @@ class DrupalWebTestCase {
*/
protected function curlInitialize() {
global $base_url, $db_prefix;
- if (!isset($this->ch)) {
- $this->ch = curl_init();
- $curl_options = $this->curl_options + array(
- CURLOPT_COOKIEJAR => $this->cookie_file,
+ if (!isset($this->curlHandle)) {
+ $this->curlHandle = curl_init();
+ $curl_options = $this->additionalCurlOptions + array(
+ CURLOPT_COOKIEJAR => $this->cookieFile,
CURLOPT_URL => $base_url,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
@@ -812,24 +896,24 @@ class DrupalWebTestCase {
}
$curl_options[CURLOPT_USERPWD] = $auth;
}
- curl_setopt_array($this->ch, $this->curl_options + $curl_options);
+ curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
}
}
/**
* Performs a cURL exec with the specified options after calling curlConnect().
*
- * @param
- * $curl_options Custom cURL options.
+ * @param $curl_options
+ * Custom cURL options.
* @return
* Content returned from the exec.
*/
protected function curlExec($curl_options) {
$this->curlInitialize();
- $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
- curl_setopt_array($this->ch, $this->curl_options + $curl_options);
- $this->drupalSetContent(curl_exec($this->ch), curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL));
- $this->assertTrue($this->_content !== FALSE, t('!method to !url, response is !length bytes.', array('!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), '!url' => $url, '!length' => strlen($this->_content))), t('Browser'));
+ $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
+ curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
+ $this->drupalSetContent(curl_exec($this->curlHandle), curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL));
+ $this->assertTrue($this->content !== FALSE, t('!method to !url, response is !length bytes.', array('!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), '!url' => $url, '!length' => strlen($this->content))), t('Browser'));
return $this->drupalGetContent();
}
@@ -838,10 +922,12 @@ class DrupalWebTestCase {
*
* @see _drupal_log_error().
*
- * @param $ch the cURL handler.
- * @param $header a header.
+ * @param $curlHandler
+ * The cURL handler.
+ * @param $header
+ * An header.
*/
- protected function curlHeaderCallback($ch, $header) {
+ protected function curlHeaderCallback($curlHandler, $header) {
// Errors are being sent via X-Drupal-Assertion-* headers,
// generated by _drupal_log_error() in the exact form required
// by DrupalWebTestCase::error().
@@ -857,9 +943,9 @@ class DrupalWebTestCase {
* Close the cURL handler and unset the handler.
*/
protected function curlClose() {
- if (isset($this->ch)) {
- curl_close($this->ch);
- unset($this->ch);
+ if (isset($this->curlHandle)) {
+ curl_close($this->curlHandle);
+ unset($this->curlHandle);
}
}
@@ -873,7 +959,7 @@ class DrupalWebTestCase {
if (!$this->elements) {
// DOM can load HTML soup. But, HTML soup can throw warnings, supress
// them.
- @$htmlDom = DOMDocument::loadHTML($this->_content);
+ @$htmlDom = DOMDocument::loadHTML($this->content);
if ($htmlDom) {
$this->pass(t('Valid HTML found on "@path"', array('@path' => $this->getUrl())), t('Browser'));
// It's much easier to work with simplexml than DOM, luckily enough
@@ -894,11 +980,11 @@ class DrupalWebTestCase {
* @param $path
* Drupal path or URL to load into internal browser
* @param $options
- * Options to be forwarded to url().
+ * Options to be forwarded to url().
* @return
- * The retrieved HTML string, also available as $this->drupalGetContent()
+ * The retrieved HTML string, also available as $this->drupalGetContent()
*/
- function drupalGet($path, $options = array()) {
+ protected function drupalGet($path, $options = array()) {
$options['absolute'] = TRUE;
// We re-using a CURL connection here. If that connection still has certain
@@ -946,7 +1032,7 @@ class DrupalWebTestCase {
* @param $options
* Options to be forwarded to url().
*/
- function drupalPost($path, $edit, $submit, $options = array()) {
+ protected function drupalPost($path, $edit, $submit, $options = array()) {
$submit_matches = FALSE;
if (isset($path)) {
$html = $this->drupalGet($path, $options);
@@ -1014,7 +1100,7 @@ class DrupalWebTestCase {
* @return
* Either the new page content or FALSE.
*/
- private function checkForMetaRefresh() {
+ protected function checkForMetaRefresh() {
if ($this->drupalGetContent() != '' && $this->parse()) {
$refresh = $this->xpath('//meta[@http-equiv="Refresh"]');
if (!empty($refresh)) {
@@ -1038,7 +1124,7 @@ class DrupalWebTestCase {
* @return
* The retrieved headers, also available as $this->drupalGetContent()
*/
- function drupalHead($path, $options = array()) {
+ protected function drupalHead($path, Array $options = array()) {
$options['absolute'] = TRUE;
$out = $this->curlExec(array(CURLOPT_HEADER => TRUE, CURLOPT_NOBODY => TRUE, CURLOPT_URL => url($path, $options)));
$this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up.
@@ -1186,7 +1272,7 @@ class DrupalWebTestCase {
* format and return values see the SimpleXML documentation.
* http://us.php.net/manual/function.simplexml-element-xpath.php
*/
- public function xpath($xpath) {
+ protected function xpath($xpath) {
if ($this->parse()) {
return $this->elements->xpath($xpath);
}
@@ -1201,7 +1287,7 @@ class DrupalWebTestCase {
* @return
* Option elements in select.
*/
- private function getAllOptions(SimpleXMLElement $element) {
+ protected function getAllOptions(SimpleXMLElement $element) {
$options = array();
// Add all options items.
foreach ($element->option as $option) {
@@ -1230,10 +1316,10 @@ class DrupalWebTestCase {
* @param $group
* The group this message belongs to, defaults to 'Other'.
*/
- public function assertLink($label, $index = 0, $message = '', $group = 'Other') {
+ protected function assertLink($label, $index = 0, $message = '', $group = 'Other') {
$links = $this->xpath('//a[text()="' . $label . '"]');
$message = ($message ? $message : t('Link with label "!label" found.', array('!label' => $label)));
- $this->_assert(isset($links[$index]), $message, $group);
+ $this->assert(isset($links[$index]), $message, $group);
}
/**
@@ -1248,10 +1334,10 @@ class DrupalWebTestCase {
* @param $group
* The group this message belongs to, defaults to 'Other'.
*/
- public function assertNoLink($label, $message = '', $group = 'Other') {
+ protected function assertNoLink($label, $message = '', $group = 'Other') {
$links = $this->xpath('//a[text()="' . $label . '"]');
$message = ($message ? $message : t('Link with label "!label" not found.', array('!label' => $label)));
- $this->_assert(empty($links), $message, $group);
+ $this->assert(empty($links), $message, $group);
}
/**
@@ -1269,7 +1355,7 @@ class DrupalWebTestCase {
* @return
* Page on success, or FALSE on failure.
*/
- function clickLink($label, $index = 0) {
+ protected function clickLink($label, $index = 0) {
$url_before = $this->getUrl();
$urls = $this->xpath('//a[text()="' . $label . '"]');
@@ -1294,7 +1380,7 @@ class DrupalWebTestCase {
* @return
* An absolute path.
*/
- function getAbsoluteUrl($path) {
+ protected function getAbsoluteUrl($path) {
$options = array('absolute' => TRUE);
$parts = parse_url($path);
// This is more crude than the menu_is_external but enough here.
@@ -1319,15 +1405,15 @@ class DrupalWebTestCase {
* @return
* The current url.
*/
- function getUrl() {
- return $this->_url;
+ protected function getUrl() {
+ return $this->url;
}
/**
* Gets the current raw HTML of requested page.
*/
- function drupalGetContent() {
- return $this->_content;
+ protected function drupalGetContent() {
+ return $this->content;
}
/**
@@ -1339,10 +1425,10 @@ class DrupalWebTestCase {
* the page the content can be set and page elements can be checked to ensure
* that the function worked properly.
*/
- function drupalSetContent($content, $url = 'internal:') {
- $this->_content = $content;
- $this->_url = $url;
- $this->plain_text = FALSE;
+ protected function drupalSetContent($content, $url = 'internal:') {
+ $this->content = $content;
+ $this->url = $url;
+ $this->plainTextContent = FALSE;
$this->elements = FALSE;
}
@@ -1351,7 +1437,7 @@ class DrupalWebTestCase {
* refers to the raw HTML that the page generated.
*
* @param $raw
- * Raw (HTML) string to look for.
+ * Raw (HTML) string to look for.
* @param $message
* Message to display.
* @param $group
@@ -1359,8 +1445,8 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertRaw($raw, $message = '%s found', $group = 'Other') {
- return $this->_assert(strpos($this->_content, $raw) !== FALSE, $message, $group);
+ protected function assertRaw($raw, $message = '%s found', $group = 'Other') {
+ return $this->assert(strpos($this->content, $raw) !== FALSE, $message, $group);
}
/**
@@ -1376,8 +1462,8 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertNoRaw($raw, $message = '%s found', $group = 'Other') {
- return $this->_assert(strpos($this->_content, $raw) === FALSE, $message, $group);
+ protected function assertNoRaw($raw, $message = '%s found', $group = 'Other') {
+ return $this->assert(strpos($this->content, $raw) === FALSE, $message, $group);
}
/**
@@ -1386,7 +1472,7 @@ class DrupalWebTestCase {
* In other words the HTML has been filtered out of the contents.
*
* @param $text
- * Plain text to look for.
+ * Plain text to look for.
* @param $message
* Message to display.
* @param $group
@@ -1394,7 +1480,7 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertText($text, $message = '', $group = 'Other') {
+ protected function assertText($text, $message = '', $group = 'Other') {
return $this->assertTextHelper($text, $message, $group, FALSE);
}
@@ -1412,7 +1498,7 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertNoText($text, $message = '', $group = 'Other') {
+ protected function assertNoText($text, $message = '', $group = 'Other') {
return $this->assertTextHelper($text, $message, $group, TRUE);
}
@@ -1433,13 +1519,13 @@ class DrupalWebTestCase {
* TRUE on pass, FALSE on fail.
*/
protected function assertTextHelper($text, $message, $group, $not_exists) {
- if ($this->plain_text === FALSE) {
- $this->plain_text = filter_xss($this->_content, array());
+ if ($this->plainTextContent === FALSE) {
+ $this->plainTextContent = filter_xss($this->content, array());
}
if (!$message) {
$message = '"' . $text . '"' . ($not_exists ? ' not found' : ' found');
}
- return $this->_assert($not_exists == (strpos($this->plain_text, $text) === FALSE), $message, $group);
+ return $this->assert($not_exists == (strpos($this->plainTextContent, $text) === FALSE), $message, $group);
}
/**
@@ -1454,8 +1540,8 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertPattern($pattern, $message = 'Pattern %s found', $group = 'Other') {
- return $this->_assert((bool) preg_match($pattern, $this->drupalGetContent()), $message, $group);
+ protected function assertPattern($pattern, $message = 'Pattern %s found', $group = 'Other') {
+ return $this->assert((bool) preg_match($pattern, $this->drupalGetContent()), $message, $group);
}
/**
@@ -1470,15 +1556,15 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertNoPattern($pattern, $message = 'Pattern %s not found', $group = 'Other') {
- return $this->_assert(!preg_match($pattern, $this->drupalGetContent()), $message, $group);
+ protected function assertNoPattern($pattern, $message = 'Pattern %s not found', $group = 'Other') {
+ return $this->assert(!preg_match($pattern, $this->drupalGetContent()), $message, $group);
}
/**
* Pass if the page title is the given string.
*
* @param $title
- * The string the title should be.
+ * The string the title should be.
* @param $message
* Message to display.
* @param $group
@@ -1486,8 +1572,8 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertTitle($title, $message, $group = 'Other') {
- return $this->_assert($this->xpath('//title[text()="' . $title . '"]') !== FALSE, $message, $group);
+ protected function assertTitle($title, $message, $group = 'Other') {
+ return $this->assert($this->xpath('//title[text()="' . $title . '"]') !== FALSE, $message, $group);
}
/**
@@ -1504,7 +1590,7 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertFieldByXPath($xpath, $value, $message, $group = 'Other') {
+ protected function assertFieldByXPath($xpath, $value, $message, $group = 'Other') {
$fields = $this->xpath($xpath);
// If value specified then check array for match.
@@ -1548,7 +1634,7 @@ class DrupalWebTestCase {
* @return
* The selected value or FALSE.
*/
- function getSelectedItem(SimpleXMLElement $element) {
+ protected function getSelectedItem(SimpleXMLElement $element) {
foreach ($element->children() as $item) {
if (isset($item['selected'])) {
return $item['value'];
@@ -1576,7 +1662,7 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertNoFieldByXPath($xpath, $value, $message, $group = 'Other') {
+ protected function assertNoFieldByXPath($xpath, $value, $message, $group = 'Other') {
$fields = $this->xpath($xpath);
// If value specified then check array for match.
@@ -1608,8 +1694,8 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertFieldByName($name, $value = '', $message = '') {
- return $this->assertFieldByXPath($this->_constructFieldXpath('name', $name), $value, $message ? $message : t('Found field by name @name', array('@name' => $name)), t('Browser'));
+ protected function assertFieldByName($name, $value = '', $message = '') {
+ return $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : t('Found field by name @name', array('@name' => $name)), t('Browser'));
}
/**
@@ -1626,15 +1712,15 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertNoFieldByName($name, $value = '', $message = '') {
- return $this->assertNoFieldByXPath($this->_constructFieldXpath('name', $name), $value, $message ? $message : t('Did not find field by name @name', array('@name' => $name)), t('Browser'));
+ protected function assertNoFieldByName($name, $value = '', $message = '') {
+ return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : t('Did not find field by name @name', array('@name' => $name)), t('Browser'));
}
/**
* Assert 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.
* @param $message
@@ -1644,15 +1730,15 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertFieldById($id, $value = '', $message = '') {
- return $this->assertFieldByXPath($this->_constructFieldXpath('id', $id), $value, $message ? $message : t('Found field by id @id', array('@id' => $id)), t('Browser'));
+ protected function assertFieldById($id, $value = '', $message = '') {
+ return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Found field by id @id', array('@id' => $id)), t('Browser'));
}
/**
* Assert 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.
* @param $message
@@ -1662,15 +1748,15 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertNoFieldById($id, $value = '', $message = '') {
- return $this->assertNoFieldByXPath($this->_constructFieldXpath('id', $id), $value, $message ? $message : t('Did not find field by id @id', array('@id' => $id)), t('Browser'));
+ protected function assertNoFieldById($id, $value = '', $message = '') {
+ return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Did not find field by id @id', array('@id' => $id)), t('Browser'));
}
/**
* Assert 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.
* @param $group
@@ -1678,15 +1764,15 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertField($field, $message = '', $group = 'Other') {
- return $this->assertFieldByXPath($this->_constructFieldXpath('name', $field) . '|' . $this->_constructFieldXpath('id', $field), '', $message, $group);
+ protected function assertField($field, $message = '', $group = 'Other') {
+ return $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), '', $message, $group);
}
/**
* Assert 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.
* @param $group
@@ -1694,21 +1780,21 @@ class DrupalWebTestCase {
* @return
* TRUE on pass, FALSE on fail.
*/
- function assertNoField($field, $message = '', $group = 'Other') {
- return $this->assertNoFieldByXPath($this->_constructFieldXpath('name', $field) . '|' . $this->_constructFieldXpath('id', $field), '', $message, $group);
+ protected function assertNoField($field, $message = '', $group = 'Other') {
+ return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), '', $message, $group);
}
/**
- * 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.
+ * Field attributes.
* @param $value
- * Value of field.
+ * Value of field.
* @return
- * XPath for specified values.
+ * XPath for specified values.
*/
- function _constructFieldXpath($attribute, $value) {
+ protected function constructFieldXpath($attribute, $value) {
return '//textarea[@' . $attribute . '="' . $value . '"]|//input[@' . $attribute . '="' . $value . '"]|//select[@' . $attribute . '="' . $value . '"]';
}
@@ -1723,8 +1809,8 @@ class DrupalWebTestCase {
* @return
* Assertion result.
*/
- function assertResponse($code, $message = '') {
- $curl_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
+ protected function assertResponse($code, $message = '') {
+ $curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser'));
}
diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module
index 9d1431065..6711337ba 100644
--- a/modules/simpletest/simpletest.module
+++ b/modules/simpletest/simpletest.module
@@ -60,8 +60,6 @@ function simpletest_theme() {
* Menu callback for both running tests and listing possible tests
*/
function simpletest_test_form() {
- global $db_prefix, $db_prefix_original;
-
$form = array();
// List out all tests in groups for selection.
@@ -354,7 +352,6 @@ function simpletest_test_form_submit($form, &$form_state) {
* drupal being the default.
*/
function simpletest_run_tests($test_list, $reporter = 'drupal') {
- global $db_prefix, $db_prefix_original;
cache_clear_all();
$test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute();
@@ -415,7 +412,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
$info = $test->getInfo();
// Gather results and compose the report.
- $test_results[$test_class] = $test->_results;
+ $test_results[$test_class] = $test->results;
foreach ($test_results[$test_class] as $key => $value) {
$test_results[$key] += $value;
}
@@ -526,13 +523,12 @@ function simpletest_clean_environment() {
* Removed prefixed talbes from the database that are left over from crashed tests.
*/
function simpletest_clean_database() {
- global $db_prefix;
$tables = db_find_tables(Database::getActiveConnection()->prefixTables('{simpletest}') . '%');
$schema = drupal_get_schema_unprocessed('simpletest');
$ret = array();
foreach (array_diff_key($tables, $schema) as $table) {
- // Strip $db_prefix and skip tables without digits following "simpletest",
- // e.g. {simpletest_tets_id}.
+ // Strip the prefix and skip tables without digits following "simpletest",
+ // e.g. {simpletest_test_id}.
if (preg_match('/simpletest\d+.*/', $table, $matches)) {
db_drop_table($ret, $matches[0]);
}
diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test
index 19278f23c..ce1cb2a98 100644
--- a/modules/simpletest/simpletest.test
+++ b/modules/simpletest/simpletest.test
@@ -5,7 +5,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
/**
* The results array that has been parsed by getTestResults().
*/
- protected $results;
+ protected $childTestResults;
/**
* Store the test ID from each test run for comparison, to ensure they are
@@ -100,7 +100,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
$this->drupalCreateUser(array($this->valid_permission));
$this->drupalCreateUser(array($this->invalid_permission));
- $this->pass(t('Test ID is @id.', array('@id' => $this->test_id)));
+ $this->pass(t('Test ID is @id.', array('@id' => $this->testId)));
// Generates a warning.
$i = 1 / 0;
@@ -146,7 +146,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
* Fetch the test id from the test results.
*/
function getTestIdFromResults() {
- foreach($this->results['assertions'] as $assertion) {
+ foreach($this->childTestResults['assertions'] as $assertion) {
if (preg_match('@^Test ID is ([0-9]*)\.$@', $assertion['message'], $matches)) {
return $matches[1];
}
@@ -168,7 +168,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
function assertAssertion($message, $type, $status, $file, $function) {
$message = trim(strip_tags($message));
$found = FALSE;
- foreach ($this->results['assertions'] as $assertion) {
+ foreach ($this->childTestResults['assertions'] as $assertion) {
if ((strpos($assertion['message'], $message) !== FALSE) &&
$assertion['type'] == $type &&
$assertion['status'] == $status &&
@@ -208,7 +208,7 @@ class SimpleTestTestCase extends DrupalWebTestCase {
}
}
}
- $this->results = $results;
+ $this->childTestResults = $results;
}
/**
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 60b397ebf..437f5dbd6 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -146,11 +146,11 @@ class DrupalTagsHandlingTestCase extends DrupalWebTestCase {
$original = $this->validTags;
foreach ($tags as $tag) {
$key = array_search($tag, $original);
- $this->_assert($key !== FALSE, t('Make sure tag %tag shows up in the final tags array (originally %original)', array('%tag' => $tag, '%original' => $key)));
+ $this->assertTrue($key, t('Make sure tag %tag shows up in the final tags array (originally %original)', array('%tag' => $tag, '%original' => $key)));
unset($original[$key]);
}
foreach ($original as $leftover) {
- $this->_assert(FALSE, t('Leftover tag %leftover was left over.', array('%leftover' => $leftover)));
+ $this->fail(t('Leftover tag %leftover was left over.', array('%leftover' => $leftover)));
}
}
}
@@ -238,11 +238,9 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
$auth = str_replace('http://', 'http://' . $username . ':' . $password .'@', $url);
$result = drupal_http_request($auth);
- // We use strpos directly.
- // assertRaw() cannot be used because we are getting the data
- // in a variable instead of $this->_content.
- $this->assertTrue(strpos($result->data, $username) !== FALSE, t('$_SERVER[\'PHP_AUTH_USER\'] is passed correctly.'));
- $this->assertTrue(strpos($result->data, $password) !== FALSE, t('$_SERVER[\'PHP_AUTH_PW\'] is passed correctly.'));
+ $this->drupalSetContent($result->data);
+ $this->assertRaw($username, t('$_SERVER["PHP_AUTH_USER"] is passed correctly.'));
+ $this->assertRaw($password, t('$_SERVER["PHP_AUTH_PW"] is passed correctly.'));
}
function testDrupalHTTPRequestRedirect() {
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 88b5f36d2..1319f7c19 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -2026,7 +2026,7 @@ class DatabaseTemporaryQueryTestCase extends DrupalWebTestCase {
*/
function testTemporaryQuery() {
$this->drupalGet('database_test_db_query_temporary');
- $this->assertEqual(db_query('SELECT COUNT(*) FROM {system}')->fetchField(), $this->_content, t('The temporary table exists and contains the correct amount of rows.'));
+ $this->assertEqual(db_query('SELECT COUNT(*) FROM {system}')->fetchField(), $this->drupalGetContent(), t('The temporary table exists and contains the correct amount of rows.'));
$this->assertFalse(db_table_exists('temporary'), t('The temporary table is, indeed, temporary.'));
}
}
diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test
index 4512d9cd4..082345e64 100644
--- a/modules/simpletest/tests/session.test
+++ b/modules/simpletest/tests/session.test
@@ -169,9 +169,9 @@ class SessionTestCase extends DrupalWebTestCase {
$this->curlClose();
// Change cookie file for user.
- $this->cookie_file = file_directory_temp() . '/cookie.' . $uid . '.txt';
- $this->curl_options[CURLOPT_COOKIEFILE] = $this->cookie_file;
- $this->curl_options[CURLOPT_COOKIESESSION] = TRUE;
+ $this->cookieFile = file_directory_temp() . '/cookie.' . $uid . '.txt';
+ $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'));
}
diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
index fdd455284..8066a3195 100755
--- a/scripts/run-tests.sh
+++ b/scripts/run-tests.sh
@@ -343,9 +343,9 @@ function simpletest_script_run_one_test($test_id, $test_class) {
$test->run();
$info = $test->getInfo();
- $status = ((isset($test->_results['#fail']) && $test->_results['#fail'] > 0)
- || (isset($test->_results['#exception']) && $test->_results['#exception'] > 0) ? 'fail' : 'pass');
- simpletest_script_print($info['name'] . ' ' . _simpletest_format_summary_line($test->_results) . "\n", simpletest_script_color_code($status));
+ $status = ((isset($test->results['#fail']) && $test->results['#fail'] > 0)
+ || (isset($test->results['#exception']) && $test->results['#exception'] > 0) ? 'fail' : 'pass');
+ simpletest_script_print($info['name'] . ' ' . _simpletest_format_summary_line($test->results) . "\n", simpletest_script_color_code($status));
}
/**