Changeset 24 in tests
- Timestamp:
- 09/22/2007 07:01:36 AM (17 years ago)
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-testlib/utils.php
r21 r24 16 16 17 17 return trim(join("\n", $result)); 18 } 19 20 // helper class for testing code that involves actions and filters 21 // typical use: 22 // $ma = new MockAction(); 23 // add_action('foo', array(&$ma, 'action')); 24 class MockAction { 25 var $events; 26 27 function MockAction() { 28 $this->reset(); 29 } 30 31 function reset() { 32 $this->events = array(); 33 } 34 35 function action() { 36 global $wp_actions; 37 38 $args = func_get_args(); 39 $current_action = $wp_actions[count($wp_actions)-1]; 40 $this->events[] = array('tag'=>$current_action, 'args'=>$args); 41 } 42 43 // return a count of the number of times the action was called since the last reset 44 function get_call_count($tag='') { 45 if ($hook) { 46 $count = 0; 47 foreach ($this->events as $e) 48 if ($e['action'] == $hook) 49 ++$count; 50 return $count; 51 } 52 return count($this->events); 53 } 54 55 // return an array of the tags that triggered calls to this action 56 function get_tags() { 57 $out = array(); 58 foreach ($this->events as $e) 59 $out[] = $e['tag']; 60 return $out; 61 } 62 63 // return an array of args passed in calls to this action 64 function get_args() { 65 $out = array(); 66 foreach ($this->events as $e) 67 $out[] = $e['args']; 68 return $out; 69 } 18 70 } 19 71
Note: See TracChangeset
for help on using the changeset viewer.