/** * Test arbitrary context actions given a context and type. * * @param string $context The context being tested. * @param string $type The subcontext being tested. */ protected function _context_action_assertions($context, $type) { $a = new MockAction(); if ($context) { add_action("fm_{$context}", array(&$a, 'action')); } if ($type) { add_action("fm_{$context}_{$type}", array(&$a, 'action')); } fm_get_context(true); fm_trigger_context_action(); if ($type) { // only two events occurred for the hook $this->assertEquals(2, $a->get_call_count()); // only our hooks were called $this->assertEquals(array("fm_{$context}_{$type}", "fm_{$context}"), $a->get_tags()); // The $type should have been passed as args $this->assertEquals(array(array($type), array($type)), $a->get_args()); } elseif ($context) { // only one event occurred for the hook $this->assertEquals(1, $a->get_call_count()); // only our hook was called $this->assertEquals(array("fm_{$context}"), $a->get_tags()); // null should have been passed as an arg $this->assertEquals(array(array(null)), $a->get_args()); } else { // No event should have fired $this->assertEquals(0, $a->get_call_count()); } }
function test_remove_all_action() { $a = new MockAction(); $tag = rand_str(); add_action('all', array(&$a, 'action')); $this->assertEquals(10, has_filter('all', array(&$a, 'action'))); do_action($tag); // make sure our hook was called correctly $this->assertEquals(1, $a->get_call_count()); $this->assertEquals(array($tag), $a->get_tags()); // now remove the action, do it again, and make sure it's not called this time remove_action('all', array(&$a, 'action')); $this->assertFalse(has_filter('all', array(&$a, 'action'))); do_action($tag); $this->assertEquals(1, $a->get_call_count()); $this->assertEquals(array($tag), $a->get_tags()); }
function test_remove_all_filter() { $a = new MockAction(); $tag = rand_str(); $val = rand_str(); add_filter('all', array($a, 'filterall')); $this->assertTrue(has_filter('all')); $this->assertEquals(10, has_filter('all', array($a, 'filterall'))); $this->assertEquals($val, apply_filters($tag, $val)); // make sure our hook was called correctly $this->assertEquals(1, $a->get_call_count()); $this->assertEquals(array($tag), $a->get_tags()); // now remove the filter, do it again, and make sure it's not called this time remove_filter('all', array($a, 'filterall')); $this->assertFalse(has_filter('all', array($a, 'filterall'))); $this->assertFalse(has_filter('all')); $this->assertEquals($val, apply_filters($tag, $val)); // call cound should remain at 1 $this->assertEquals(1, $a->get_call_count()); $this->assertEquals(array($tag), $a->get_tags()); }