1 common.test | CommonBackdropAlterTestCase::testBackdropAlter() |
File
- core/
modules/ simpletest/ tests/ common.test, line 15 - Tests for common.inc functionality.
Class
- CommonBackdropAlterTestCase
- Tests for URL generation functions.
Code
function testBackdropAlter() {
// This test depends on Bartik, so make sure that it is always the current
// active theme.
global $theme, $base_theme_info;
$theme = 'bartik';
$base_theme_info = array();
$array = array('foo' => 'bar');
$entity = new stdClass();
$entity->foo = 'bar';
// Verify alteration of a single argument.
$array_copy = $array;
$array_expected = array('foo' => 'Backdrop theme');
backdrop_alter('backdrop_alter', $array_copy);
$this->assertEqual($array_copy, $array_expected, 'Single array was altered.');
$entity_copy = clone $entity;
$entity_expected = clone $entity;
$entity_expected->foo = 'Backdrop theme';
backdrop_alter('backdrop_alter', $entity_copy);
$this->assertEqual($entity_copy, $entity_expected, 'Single object was altered.');
// Verify alteration of multiple arguments.
$array_copy = $array;
$array_expected = array('foo' => 'Backdrop theme');
$entity_copy = clone $entity;
$entity_expected = clone $entity;
$entity_expected->foo = 'Backdrop theme';
$array2_copy = $array;
$array2_expected = array('foo' => 'Backdrop theme');
backdrop_alter('backdrop_alter', $array_copy, $entity_copy, $array2_copy);
$this->assertEqual($array_copy, $array_expected, 'First argument to backdrop_alter() was altered.');
$this->assertEqual($entity_copy, $entity_expected, 'Second argument to backdrop_alter() was altered.');
$this->assertEqual($array2_copy, $array2_expected, 'Third argument to backdrop_alter() was altered.');
// Verify alteration order when passing an array of types to backdrop_alter().
// common_test_module_implements_alter() places 'block' implementation after
// other modules.
$array_copy = $array;
$array_expected = array('foo' => 'Backdrop block theme');
backdrop_alter(array('backdrop_alter', 'backdrop_alter_foo'), $array_copy);
$this->assertEqual($array_copy, $array_expected, 'hook_TYPE_alter() implementations ran in correct order.');
}