summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/common.test53
-rw-r--r--modules/simpletest/tests/common_test.module32
2 files changed, 84 insertions, 1 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 53d493210..55b4b4332 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -2,6 +2,59 @@
// $Id$
/**
+ * @file
+ * Tests for common.inc functionality.
+ */
+
+/**
+ * Tests for URL generation functions.
+ */
+class DrupalAlterTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'drupal_alter() tests',
+ 'description' => 'Confirm that alteration of arguments passed to drupal_alter() works correctly.',
+ 'group' => 'System',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('common_test');
+ }
+
+ function testDrupalAlter() {
+ $array = array('foo' => 'bar');
+ $object = new stdClass;
+ $object->foo = 'bar';
+
+ // Verify alteration of a single argument.
+ $array_copy = $array;
+ $array_expected = array('foo' => 'Drupal');
+ drupal_alter('drupal_alter', $array_copy);
+ $this->assertEqual($array_copy, $array_expected, t('Single array was altered.'));
+
+ $object_copy = clone $object;
+ $object_expected = clone $object;
+ $object_expected->foo = 'Drupal';
+ drupal_alter('drupal_alter', $object_copy);
+ $this->assertEqual($object_copy, $object_expected, t('Single object was altered.'));
+
+ // Verify alteration of multiple arguments.
+ $array_copy = $array;
+ $array_expected = array('foo' => 'Drupal');
+ $object_copy = clone $object;
+ $object_expected = clone $object;
+ $object_expected->foo = 'Drupal';
+ $array2_copy = $array;
+ $array2_expected = array('foo' => 'Drupal');
+ drupal_alter('drupal_alter', $array_copy, $object_copy, $array2_copy);
+ $this->assertEqual($array_copy, $array_expected, t('First argument to drupal_alter() was altered.'));
+ $this->assertEqual($object_copy, $object_expected, t('Second argument to drupal_alter() was altered.'));
+ $this->assertEqual($array2_copy, $array2_expected, t('Third argument to drupal_alter() was altered.'));
+ }
+}
+
+/**
* Tests for URL generation functions.
*/
class CommonURLUnitTest extends DrupalUnitTestCase {
diff --git a/modules/simpletest/tests/common_test.module b/modules/simpletest/tests/common_test.module
index f7abf51b6..74866f098 100644
--- a/modules/simpletest/tests/common_test.module
+++ b/modules/simpletest/tests/common_test.module
@@ -10,7 +10,6 @@
* Implement hook_menu().
*/
function common_test_menu() {
- $items = array();
$items['common-test/drupal_goto'] = array(
'title' => 'Drupal Goto',
'page callback' => 'common_test_drupal_goto_land',
@@ -71,6 +70,37 @@ function common_test_drupal_goto_alter(&$args) {
}
/**
+ * Implement hook_TYPE_alter().
+ */
+function common_test_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {
+ // Alter first argument.
+ if (is_array($data)) {
+ $data['foo'] = 'Drupal';
+ }
+ elseif (is_object($data)) {
+ $data->foo = 'Drupal';
+ }
+ // Alter second argument, if present.
+ if (isset($arg2)) {
+ if (is_array($arg2)) {
+ $arg2['foo'] = 'Drupal';
+ }
+ elseif (is_object($arg2)) {
+ $arg2->foo = 'Drupal';
+ }
+ }
+ // Try to alter third argument, if present.
+ if (isset($arg3)) {
+ if (is_array($arg3)) {
+ $arg3['foo'] = 'Drupal';
+ }
+ elseif (is_object($arg3)) {
+ $arg3->foo = 'Drupal';
+ }
+ }
+}
+
+/**
* Implement hook_theme().
*/
function common_test_theme() {