/[drupal]/contributions/modules/phpunit/lib/DrupalTest/TestCase.php
ViewVC logotype

Diff of /contributions/modules/phpunit/lib/DrupalTest/TestCase.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3.2.1, Wed May 27 07:56:07 2009 UTC revision 1.3.2.2, Mon Jun 1 04:59:18 2009 UTC
# Line 1  Line 1 
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.
# Line 38  class DrupalTest_TestCase extends PHPUni Line 38  class DrupalTest_TestCase extends PHPUni
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
# Line 82  class DrupalTest_TestCase extends PHPUni Line 92  class DrupalTest_TestCase extends PHPUni
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  }  }

Legend:
Removed from v.1.3.2.1  
changed lines
  Added in v.1.3.2.2

  ViewVC Help
Powered by ViewVC 1.1.2