123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * Test the has_filter method of WP_Hook
- *
- * @group hooks
- * @covers WP_Hook::has_filter
- */
- class Tests_Hooks_HasFilter extends WP_UnitTestCase {
- public function test_has_filter_with_function() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
- }
- public function test_has_filter_with_object() {
- $a = new MockAction();
- $callback = array( $a, 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
- }
- public function test_has_filter_with_static_method() {
- $callback = array( 'MockAction', 'action' );
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertSame( $priority, $hook->has_filter( $tag, $callback ) );
- }
- public function test_has_filter_without_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertTrue( $hook->has_filter() );
- }
- public function test_not_has_filter_without_callback() {
- $hook = new WP_Hook();
- $this->assertFalse( $hook->has_filter() );
- }
- public function test_not_has_filter_with_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $this->assertFalse( $hook->has_filter( $tag, $callback ) );
- }
- public function test_has_filter_with_wrong_callback() {
- $callback = '__return_null';
- $hook = new WP_Hook();
- $tag = __FUNCTION__;
- $priority = rand( 1, 100 );
- $accepted_args = rand( 1, 100 );
- $hook->add_filter( $tag, $callback, $priority, $accepted_args );
- $this->assertFalse( $hook->has_filter( $tag, '__return_false' ) );
- }
- }
|