Skip to content

Commit

Permalink
[+]: "add unit tests for Hooks" - mistic100/PHP-Hooks@e1040da
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Moelleken committed Jan 28, 2015
1 parent 08925d2 commit aab9da0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/voku/helper/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ public function has_filter($tag, $function_to_check = false)
*
* Call the functions added to a filter hook.
*
* Info: Additional variables passed to the functions hooked to <tt>$tag</tt>.
*
* @param string $tag The name of the filter hook.
* @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
*
* @internal param mixed $var Additional variables passed to the functions hooked to <tt>$tag</tt>.
*
* @return mixed The filtered value after all hooked functions are applied to it.
* @access public
* @since 1.0.0
Expand Down
22 changes: 22 additions & 0 deletions tests/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ public function testHooks()
$this->assertEquals($lall, $this->testString_1 . $this->testString_2);
}


public function testAction()
{
$done = false;

$this->hooks->add_action('bar', function() use(&$done) {
$done = !$done;
});

$this->hooks->do_action('bar');
$this->assertTrue($done);
}

public function testFilter()
{
$this->hooks->add_filter('foo', function($content) {
return '<b>' . $content . '</b>';
});

$this->assertEquals('<b>Hello world</b>', $this->hooks->apply_filters('foo', 'Hello world'));
}

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
Expand Down

0 comments on commit aab9da0

Please sign in to comment.