| 1 |
<?php |
<?php |
| 2 |
// $Id: TestCase.php,v 1.5 2009/05/27 07:07:17 chop Exp $ |
// $Id: TestCase.php,v 1.4 2009/03/12 06:37:52 chop Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Defines a Test Case for all Drupal Tests. |
* Defines a Test Case for all Drupal Tests. |
| 38 |
protected $backupGlobals = FALSE; |
protected $backupGlobals = FALSE; |
| 39 |
|
|
| 40 |
/** |
/** |
| 41 |
|
* Constant name filter. |
| 42 |
|
* |
| 43 |
|
* Set this variable before using the self::_constants_filter_callback |
| 44 |
|
* method to filter an array of constants. |
| 45 |
|
* |
| 46 |
|
* @var string |
| 47 |
|
*/ |
| 48 |
|
private $_constant_name_filter = ''; |
| 49 |
|
|
| 50 |
|
/** |
| 51 |
* Set up environment for a unit test case |
* Set up environment for a unit test case |
| 52 |
* |
* |
| 53 |
* @return void |
* @return void |
| 92 |
chdir($this->currentWorkingDir); |
chdir($this->currentWorkingDir); |
| 93 |
} |
} |
| 94 |
} |
} |
| 95 |
|
|
| 96 |
|
/** |
| 97 |
|
* Array Filter callback for Channel Nine module to help filter an |
| 98 |
|
* array of constants. |
| 99 |
|
* |
| 100 |
|
* @access private |
| 101 |
|
* |
| 102 |
|
* @param string $var |
| 103 |
|
* An array item passed in by the array_filter function. |
| 104 |
|
* @return boolean |
| 105 |
|
* This is an array_filter callback, so returns TRUE if the item is |
| 106 |
|
* to be kept in the array or FALSE if the item is not to be kept. |
| 107 |
|
* @see array_filter |
| 108 |
|
* self::get_module_constants |
| 109 |
|
*/ |
| 110 |
|
private function _constants_filter_callback($var) { |
| 111 |
|
if (is_string($this->_constant_name_filter) |
| 112 |
|
&& !empty($this->_constant_name_filter) |
| 113 |
|
&& strpos($var, $this->_constant_name_filter) !== FALSE) { |
| 114 |
|
return TRUE; |
| 115 |
|
} |
| 116 |
|
else { |
| 117 |
|
return FALSE; |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
/** |
| 122 |
|
* Get the constants that are defined for a module. |
| 123 |
|
* |
| 124 |
|
* @param string $module_name |
| 125 |
|
* The name of the module whose constants you want to list. |
| 126 |
|
* @return array |
| 127 |
|
*/ |
| 128 |
|
public function get_module_constants($module_name) { |
| 129 |
|
// Define the constant name prefix we're dealing with. |
| 130 |
|
$module_name = strtoupper($module_name) .'_'; |
| 131 |
|
// Get all the constants |
| 132 |
|
$defined_constants = get_defined_constants(); |
| 133 |
|
$defined_constant_names = array_keys($defined_constants); |
| 134 |
|
$this->_constant_name_filter = $module_name; |
| 135 |
|
$constant_names = array_filter($defined_constant_names, array($this, '_constants_filter_callback')); |
| 136 |
|
$constants = array_intersect_key($defined_constants, array_flip($constant_names)); |
| 137 |
|
return $constants; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
} |
} |