summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2008-11-08 04:02:56 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2008-11-08 04:02:56 +0000
commitee6ca83959481cec94c775c9ecc09a6a4fc8bc58 (patch)
treefb8f7d081124a6416d24d51a09ef18a191042861 /modules/simpletest
parent2aabcb6aaf85bcbda0f04a9297109b93ae279b32 (diff)
downloadbrdo-ee6ca83959481cec94c775c9ecc09a6a4fc8bc58.tar.gz
brdo-ee6ca83959481cec94c775c9ecc09a6a4fc8bc58.tar.bz2
#329226 by drewish and c960657: Remove ugly GLOBALS from file tests to fix file tests.
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/tests/file.test4
-rw-r--r--modules/simpletest/tests/file_test.module121
2 files changed, 91 insertions, 34 deletions
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index ae8d35882..97014962e 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -1018,14 +1018,14 @@ class FileValidateTest extends FileHookTestCase {
// Use the file_test.module's test validator to ensure that passing tests
// return correctly.
file_test_reset();
- $GLOBALS['file_test_hook_return']['validate'] = array();
+ file_test_set_return('validate', array());
$passing = array('file_test_validator' => array(array()));
$this->assertEqual(file_validate($file, $passing), array(), t('Validating passes.'));
$this->assertFileHookCalled('validate', 1);
// Now test for failures in validators passed in and by hook_validate.
file_test_reset();
- $GLOBALS['file_test_hook_return']['validate'] = array('Epic fail');
+ file_test_set_return('validate', array('Epic fail'));
$failing = array('file_test_validator' => array(array('Failed', 'Badly')));
$this->assertEqual(file_validate($file, $failing), array('Failed', 'Badly', 'Epic fail'), t('Validating returns errors.'));
$this->assertFileHookCalled('validate', 1);
diff --git a/modules/simpletest/tests/file_test.module b/modules/simpletest/tests/file_test.module
index fd2109485..142748e9a 100644
--- a/modules/simpletest/tests/file_test.module
+++ b/modules/simpletest/tests/file_test.module
@@ -4,6 +4,9 @@
/**
* @file
* Helper module for the file tests.
+ *
+ * The caller is must call file_test_reset() to initializing this module before
+ * calling file_test_get_calls() or file_test_set_return().
*/
/**
@@ -54,10 +57,12 @@ function _file_test_form_submit(&$form, &$form_state) {
/**
* Reset/initialize the history of calls to the file_* hooks.
+ *
+ * @see the getter/setter functions file_test_get_calls() and file_test_reset().
*/
function file_test_reset() {
// Keep track of calls to these hooks
- $GLOBALS['file_test_results'] = array(
+ $results = array(
'load' => array(),
'validate' => array(),
'download' => array(),
@@ -69,30 +74,83 @@ function file_test_reset() {
'move' => array(),
'delete' => array(),
);
+ variable_set('file_test_results', $results);
- // These hooks will return these values.
- $GLOBALS['file_test_hook_return'] = array(
- 'validate' => NULL,
+ // These hooks will return these values, @see file_test_set_return().
+ $return = array(
+ 'validate' => array(),
'download' => NULL,
'references' => NULL,
);
+ variable_set('file_test_return', $return);
}
/**
- * Get the values passed to a the hook calls for a given operation.
+ * Get the arguments passed to invocation of a given hook since
+ * file_test_reset() was last called.
*
- * @param $op One of the hook_file_* operations.
- * @returns Array of the parameters passed to each call.
+ * @param $op
+ * One of the hook_file_* operations: 'load', 'validate', 'download',
+ * 'references', 'status', 'insert', 'update', 'copy', 'move', 'delete'.
+ * @returns
+ * Array of the parameters passed to each call.
+ * @see _file_test_log_call() and file_test_reset()
*/
function file_test_get_calls($op) {
- return $GLOBALS['file_test_results'][$op];
+ $results = variable_get('file_test_results', array());
+ return $results[$op];
+}
+
+/**
+ * Store the values passed to a hook invocation.
+ *
+ * @param $op
+ * One of the hook_file_* operations: 'load', 'validate', 'download',
+ * 'references', 'status', 'insert', 'update', 'copy', 'move', 'delete'.
+ * @param $args
+ * Values passed to hook.
+ * @see file_test_get_calls() and file_test_reset()
+ */
+function _file_test_log_call($op, $args) {
+ $results = variable_get('file_test_results', array());
+ $results[$op][] = $args;
+ variable_set('file_test_results', $results);
+}
+
+/**
+ * Load the appropriate return value.
+ *
+ * @param $op
+ * One of the hook_file_[validate,download,references] operations.
+ * @return
+ * Value set by file_test_set_return().
+* @see file_test_set_return() and file_test_reset().
+ */
+function _file_test_get_return($op) {
+ $return = variable_get('file_test_return', array($op => NULL));
+ return $return[$op];
+}
+
+/**
+ * Assign a return value for a given operation.
+ *
+ * @param $op
+ * One of the hook_file_[validate,download,references] operations.
+ * @param $value
+ * Value for the hook to return.
+ * @see _file_test_get_return() and file_test_reset().
+ */
+function file_test_set_return($op, $value) {
+ $return = variable_get('file_test_return', array());
+ $return[$op] = $value;
+ variable_set('file_test_return', $return);
}
/**
* Implementation of hook_file_load().
*/
-function file_test_file_load(&$file) {
- $GLOBALS['file_test_results']['load'][] = func_get_args();
+function file_test_file_load($file) {
+ _file_test_log_call('load', array($file));
// Assign a value on the object so that we can test that the $file is passed
// by reference.
$file->file_test['loaded'] = TRUE;
@@ -101,66 +159,65 @@ function file_test_file_load(&$file) {
/**
* Implementation of hook_file_validate().
*/
-function file_test_file_validate(&$file) {
- $GLOBALS['file_test_results']['validate'][] = func_get_args();
- return $GLOBALS['file_test_hook_return']['validate'];
+function file_test_file_validate($file) {
+ _file_test_log_call('validate', array($file));
+ return _file_test_get_return('validate');
}
/**
* Implementation of hook_file_status().
*/
-function file_test_file_status(&$file) {
- $GLOBALS['file_test_results']['status'][] = func_get_args();
+function file_test_file_status($file) {
+ _file_test_log_call('status', array($file));
}
/**
* Implementation of hook_file_download().
*/
-function file_test_file_download(&$file) {
- $GLOBALS['file_test_results']['download'][] = func_get_args();
- return $GLOBALS['file_test_hook_return']['download'];
+function file_test_file_download($file) {
+ _file_test_log_call('download', array($file));
+ return _file_test_get_return('download');
}
/**
* Implementation of hook_file_references().
*/
-function file_test_file_references(&$file) {
- $GLOBALS['file_test_results']['references'][] = func_get_args();
- return $GLOBALS['file_test_hook_return']['references'];
+function file_test_file_references($file) {
+ _file_test_log_call('references', array($file));
+ return _file_test_get_return('references');
}
/**
* Implementation of hook_file_insert().
*/
-function file_test_file_insert(&$file) {
- $GLOBALS['file_test_results']['insert'][] = func_get_args();
+function file_test_file_insert($file) {
+ _file_test_log_call('insert', array($file));
}
/**
* Implementation of hook_file_update().
*/
-function file_test_file_update(&$file) {
- $GLOBALS['file_test_results']['update'][] = func_get_args();
+function file_test_file_update($file) {
+ _file_test_log_call('update', array($file));
}
/**
* Implemenation of hook_file_copy().
*/
-function file_test_file_copy(&$file, &$source) {
- $GLOBALS['file_test_results']['copy'][] = func_get_args();
+function file_test_file_copy($file, $source) {
+ _file_test_log_call('copy', array($file, $source));
}
/**
* Implemenation of hook_file_move().
*/
-function file_test_file_move(&$file, &$source) {
- $GLOBALS['file_test_results']['move'][] = func_get_args();
+function file_test_file_move($file, $source) {
+ _file_test_log_call('move', array($file, $source));
}
/**
* Implementation of hook_file_delete().
*/
-function file_test_file_delete(&$file) {
- $GLOBALS['file_test_results']['delete'][] = func_get_args();
+function file_test_file_delete($file) {
+ _file_test_log_call('delete', array($file));
}
-