Changeset 48937 for trunk/tests/phpunit/tests/actions.php
- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/actions.php
r47122 r48937 16 16 17 17 // Only one event occurred for the hook, with empty args. 18 $this->assert Equals( 1, $a->get_call_count() );18 $this->assertSame( 1, $a->get_call_count() ); 19 19 // Only our hook was called. 20 $this->assert Equals( array( $tag ), $a->get_tags() );20 $this->assertSame( array( $tag ), $a->get_tags() ); 21 21 22 22 $argsvar = $a->get_args(); 23 23 $args = array_pop( $argsvar ); 24 $this->assert Equals( array( '' ), $args );24 $this->assertSame( array( '' ), $args ); 25 25 } 26 26 … … 33 33 34 34 // Make sure our hook was called correctly. 35 $this->assert Equals( 1, $a->get_call_count() );36 $this->assert Equals( array( $tag ), $a->get_tags() );35 $this->assertSame( 1, $a->get_call_count() ); 36 $this->assertSame( array( $tag ), $a->get_tags() ); 37 37 38 38 // Now remove the action, do it again, and make sure it's not called this time. 39 39 remove_action( $tag, array( &$a, 'action' ) ); 40 40 do_action( $tag ); 41 $this->assert Equals( 1, $a->get_call_count() );42 $this->assert Equals( array( $tag ), $a->get_tags() );41 $this->assertSame( 1, $a->get_call_count() ); 42 $this->assertSame( array( $tag ), $a->get_tags() ); 43 43 44 44 } … … 51 51 $this->assertFalse( has_action( $tag ) ); 52 52 add_action( $tag, $func ); 53 $this->assert Equals( 10, has_action( $tag, $func ) );53 $this->assertSame( 10, has_action( $tag, $func ) ); 54 54 $this->assertTrue( has_action( $tag ) ); 55 55 remove_action( $tag, $func ); … … 71 71 72 72 // Both actions called once each. 73 $this->assert Equals( 1, $a1->get_call_count() );74 $this->assert Equals( 1, $a2->get_call_count() );73 $this->assertSame( 1, $a1->get_call_count() ); 74 $this->assertSame( 1, $a2->get_call_count() ); 75 75 } 76 76 … … 85 85 86 86 $call_count = $a->get_call_count(); 87 $this->assert Equals( 1, $call_count );87 $this->assertSame( 1, $call_count ); 88 88 $argsvar = $a->get_args(); 89 $this->assert Equals( array( $val ), array_pop( $argsvar ) );89 $this->assertSame( array( $val ), array_pop( $argsvar ) ); 90 90 } 91 91 … … 105 105 $call_count = $a1->get_call_count(); 106 106 // $a1 should be called with both args. 107 $this->assert Equals( 1, $call_count );107 $this->assertSame( 1, $call_count ); 108 108 $argsvar1 = $a1->get_args(); 109 $this->assert Equals( array( $val1, $val2 ), array_pop( $argsvar1 ) );109 $this->assertSame( array( $val1, $val2 ), array_pop( $argsvar1 ) ); 110 110 111 111 // $a2 should be called with one only. 112 $this->assert Equals( 1, $a2->get_call_count() );112 $this->assertSame( 1, $a2->get_call_count() ); 113 113 $argsvar2 = $a2->get_args(); 114 $this->assert Equals( array( $val1 ), array_pop( $argsvar2 ) );114 $this->assertSame( array( $val1 ), array_pop( $argsvar2 ) ); 115 115 } 116 116 … … 139 139 $call_count = $a1->get_call_count(); 140 140 // $a1 should be called with both args. 141 $this->assert Equals( 1, $call_count );141 $this->assertSame( 1, $call_count ); 142 142 $argsvar1 = $a1->get_args(); 143 $this->assert Equals( array( $val1, $val2 ), array_pop( $argsvar1 ) );143 $this->assertSame( array( $val1, $val2 ), array_pop( $argsvar1 ) ); 144 144 145 145 // $a2 should be called with one only. 146 $this->assert Equals( 1, $a2->get_call_count() );146 $this->assertSame( 1, $a2->get_call_count() ); 147 147 $argsvar2 = $a2->get_args(); 148 $this->assert Equals( array( $val1 ), array_pop( $argsvar2 ) );148 $this->assertSame( array( $val1 ), array_pop( $argsvar2 ) ); 149 149 150 150 // $a3 should be called with both args. 151 $this->assert Equals( 1, $a3->get_call_count() );151 $this->assertSame( 1, $a3->get_call_count() ); 152 152 $argsvar3 = $a3->get_args(); 153 $this->assert Equals( array( $val1, $val2 ), array_pop( $argsvar3 ) );153 $this->assertSame( array( $val1, $val2 ), array_pop( $argsvar3 ) ); 154 154 } 155 155 … … 182 182 183 183 // Two events, one per action. 184 $this->assert Equals( 2, $a->get_call_count() );184 $this->assertSame( 2, $a->get_call_count() ); 185 185 186 186 $expected = array( … … 199 199 ); 200 200 201 $this->assert Equals( $expected, $a->get_events() );201 $this->assertSame( $expected, $a->get_events() ); 202 202 } 203 203 … … 208 208 // Do action $tag1 but not $tag2. 209 209 do_action( $tag1 ); 210 $this->assert Equals( 1, did_action( $tag1 ) );211 $this->assert Equals( 0, did_action( $tag2 ) );210 $this->assertSame( 1, did_action( $tag1 ) ); 211 $this->assertSame( 0, did_action( $tag2 ) ); 212 212 213 213 // Do action $tag2 a random number of times. … … 218 218 219 219 // $tag1's count hasn't changed, $tag2 should be correct. 220 $this->assert Equals( 1, did_action( $tag1 ) );221 $this->assert Equals( $count, did_action( $tag2 ) );220 $this->assertSame( 1, did_action( $tag1 ) ); 221 $this->assertSame( $count, did_action( $tag2 ) ); 222 222 223 223 } … … 230 230 // Add an 'all' action. 231 231 add_action( 'all', array( &$a, 'action' ) ); 232 $this->assert Equals( 10, has_filter( 'all', array( &$a, 'action' ) ) );232 $this->assertSame( 10, has_filter( 'all', array( &$a, 'action' ) ) ); 233 233 // Do some actions. 234 234 do_action( $tag1 ); … … 238 238 239 239 // Our action should have been called once for each tag. 240 $this->assert Equals( 4, $a->get_call_count() );240 $this->assertSame( 4, $a->get_call_count() ); 241 241 // Only our hook was called. 242 $this->assert Equals( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() );242 $this->assertSame( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() ); 243 243 244 244 remove_action( 'all', array( &$a, 'action' ) ); … … 252 252 253 253 add_action( 'all', array( &$a, 'action' ) ); 254 $this->assert Equals( 10, has_filter( 'all', array( &$a, 'action' ) ) );254 $this->assertSame( 10, has_filter( 'all', array( &$a, 'action' ) ) ); 255 255 do_action( $tag ); 256 256 257 257 // Make sure our hook was called correctly. 258 $this->assert Equals( 1, $a->get_call_count() );259 $this->assert Equals( array( $tag ), $a->get_tags() );258 $this->assertSame( 1, $a->get_call_count() ); 259 $this->assertSame( array( $tag ), $a->get_tags() ); 260 260 261 261 // Now remove the action, do it again, and make sure it's not called this time. … … 263 263 $this->assertFalse( has_filter( 'all', array( &$a, 'action' ) ) ); 264 264 do_action( $tag ); 265 $this->assert Equals( 1, $a->get_call_count() );266 $this->assert Equals( array( $tag ), $a->get_tags() );265 $this->assertSame( 1, $a->get_call_count() ); 266 $this->assertSame( array( $tag ), $a->get_tags() ); 267 267 } 268 268 … … 313 313 add_action( 'test_action_self_removal', array( $this, 'action_self_removal' ) ); 314 314 do_action( 'test_action_self_removal' ); 315 $this->assert Equals( 1, did_action( 'test_action_self_removal' ) );315 $this->assertSame( 1, did_action( 'test_action_self_removal' ) ); 316 316 } 317 317 … … 333 333 do_action( $tag, $tag ); 334 334 335 $this->assert Equals( 2, $a->get_call_count(), 'recursive actions should call all callbacks with earlier priority' );336 $this->assert Equals( 2, $b->get_call_count(), 'recursive actions should call callbacks with later priority' );335 $this->assertSame( 2, $a->get_call_count(), 'recursive actions should call all callbacks with earlier priority' ); 336 $this->assertSame( 2, $b->get_call_count(), 'recursive actions should call callbacks with later priority' ); 337 337 } 338 338 … … 365 365 do_action( $tag, $tag, array( $a, $b, $c, $d, $e ) ); 366 366 367 $this->assert Equals( 2, $a->get_call_count(), 'callbacks should run unless otherwise instructed' );368 $this->assert Equals( 1, $b->get_call_count(), 'callback removed by same priority callback should still get called' );369 $this->assert Equals( 1, $c->get_call_count(), 'callback added by same priority callback should not get called' );370 $this->assert Equals( 2, $d->get_call_count(), 'callback added by earlier priority callback should get called' );371 $this->assert Equals( 1, $e->get_call_count(), 'callback added by later priority callback should not get called' );367 $this->assertSame( 2, $a->get_call_count(), 'callbacks should run unless otherwise instructed' ); 368 $this->assertSame( 1, $b->get_call_count(), 'callback removed by same priority callback should still get called' ); 369 $this->assertSame( 1, $c->get_call_count(), 'callback added by same priority callback should not get called' ); 370 $this->assertSame( 2, $d->get_call_count(), 'callback added by earlier priority callback should get called' ); 371 $this->assertSame( 1, $e->get_call_count(), 'callback added by later priority callback should not get called' ); 372 372 } 373 373 … … 436 436 ), 437 437 ); 438 $this->assert Equals( 11, has_action( $tag, '__return_null' ) );438 $this->assertSame( 11, has_action( $tag, '__return_null' ) ); 439 439 } 440 440 … … 449 449 $wp_current_filter[] = 'second'; // Let's say a second action was invoked. 450 450 451 $this->assert Equals( 'second', current_action() );451 $this->assertSame( 'second', current_action() ); 452 452 } 453 453 … … 499 499 add_filter( 'testing', array( $this, 'apply_testing_filter' ) ); 500 500 $this->assertTrue( has_action( 'testing' ) ); 501 $this->assert Equals( 10, has_action( 'testing', array( $this, 'apply_testing_filter' ) ) );501 $this->assertSame( 10, has_action( 'testing', array( $this, 'apply_testing_filter' ) ) ); 502 502 503 503 apply_filters( 'testing', '' ); … … 520 520 add_filter( 'testing_nested', array( $this, 'apply_testing_nested_filter' ) ); 521 521 $this->assertTrue( has_action( 'testing_nested' ) ); 522 $this->assert Equals( 10, has_action( 'testing_nested', array( $this, 'apply_testing_nested_filter' ) ) );522 $this->assertSame( 10, has_action( 'testing_nested', array( $this, 'apply_testing_nested_filter' ) ) ); 523 523 524 524 apply_filters( 'testing_nested', '' );
Note: See TracChangeset
for help on using the changeset viewer.