Changeset 47122 for trunk/tests/phpunit/tests/filters.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/filters.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/filters.php
r46689 r47122 16 16 $this->assertEquals( $val, apply_filters( $tag, $val ) ); 17 17 18 // only one event occurred for the hook, with empty args19 $this->assertEquals( 1, $a->get_call_count() ); 20 // only our hook was called18 // Only one event occurred for the hook, with empty args. 19 $this->assertEquals( 1, $a->get_call_count() ); 20 // Only our hook was called. 21 21 $this->assertEquals( array( $tag ), $a->get_tags() ); 22 22 … … 34 34 $this->assertEquals( $val, apply_filters( $tag, $val ) ); 35 35 36 // make sure our hook was called correctly37 $this->assertEquals( 1, $a->get_call_count() ); 38 $this->assertEquals( array( $tag ), $a->get_tags() ); 39 40 // now remove the filter, do it again, and make sure it's not called this time36 // Make sure our hook was called correctly. 37 $this->assertEquals( 1, $a->get_call_count() ); 38 $this->assertEquals( array( $tag ), $a->get_tags() ); 39 40 // Now remove the filter, do it again, and make sure it's not called this time. 41 41 remove_filter( $tag, array( $a, 'filter' ) ); 42 42 $this->assertEquals( $val, apply_filters( $tag, $val ) ); … … 60 60 } 61 61 62 // one tag with multiple filters62 // One tag with multiple filters. 63 63 function test_multiple_filters() { 64 64 $a1 = new MockAction(); … … 67 67 $val = __FUNCTION__ . '_val'; 68 68 69 // add both filters to the hook69 // Add both filters to the hook. 70 70 add_filter( $tag, array( $a1, 'filter' ) ); 71 71 add_filter( $tag, array( $a2, 'filter' ) ); … … 73 73 $this->assertEquals( $val, apply_filters( $tag, $val ) ); 74 74 75 // both filters called once each75 // Both filters called once each. 76 76 $this->assertEquals( 1, $a1->get_call_count() ); 77 77 $this->assertEquals( 1, $a2->get_call_count() ); … … 85 85 86 86 add_filter( $tag, array( $a, 'filter' ), 10, 2 ); 87 // call the filter with a single argument87 // Call the filter with a single argument. 88 88 $this->assertEquals( $val, apply_filters( $tag, $val, $arg1 ) ); 89 89 … … 101 101 $arg2 = __FUNCTION__ . '_arg2'; 102 102 103 // a1 accepts two arguments, a2 doesn't103 // $a1 accepts two arguments, $a2 doesn't. 104 104 add_filter( $tag, array( $a1, 'filter' ), 10, 3 ); 105 105 add_filter( $tag, array( $a2, 'filter' ) ); 106 // call the filter with two arguments106 // Call the filter with two arguments. 107 107 $this->assertEquals( $val, apply_filters( $tag, $val, $arg1, $arg2 ) ); 108 108 109 // a1 should be called with both args109 // $a1 should be called with both args. 110 110 $this->assertEquals( 1, $a1->get_call_count() ); 111 111 $argsvar1 = $a1->get_args(); 112 112 $this->assertEquals( array( $val, $arg1, $arg2 ), array_pop( $argsvar1 ) ); 113 113 114 // a2 should be called with one only114 // $a2 should be called with one only. 115 115 $this->assertEquals( 1, $a2->get_call_count() ); 116 116 $argsvar2 = $a2->get_args(); … … 123 123 $val = __FUNCTION__ . '_val'; 124 124 125 // make two filters with different priorities125 // Make two filters with different priorities. 126 126 add_filter( $tag, array( $a, 'filter' ), 10 ); 127 127 add_filter( $tag, array( $a, 'filter2' ), 9 ); 128 128 $this->assertEquals( $val, apply_filters( $tag, $val ) ); 129 129 130 // there should be two events, one per filter130 // There should be two events, one per filter. 131 131 $this->assertEquals( 2, $a->get_call_count() ); 132 132 133 133 $expected = array( 134 // filter2 is called first because it has priority 9134 // 'filter2' is called first because it has priority 9. 135 135 array( 136 136 'filter' => 'filter2', … … 138 138 'args' => array( $val ), 139 139 ), 140 // filter 1 is called second140 // 'filter' is called second. 141 141 array( 142 142 'filter' => 'filter', … … 155 155 $val = __FUNCTION__ . '_val'; 156 156 157 // add an 'all' filter157 // Add an 'all' filter. 158 158 add_filter( 'all', array( $a, 'filterall' ) ); 159 // do some filters159 // Apply some filters. 160 160 $this->assertEquals( $val, apply_filters( $tag1, $val ) ); 161 161 $this->assertEquals( $val, apply_filters( $tag2, $val ) ); … … 163 163 $this->assertEquals( $val, apply_filters( $tag1, $val ) ); 164 164 165 // our filter should have been called once for each apply_filters call165 // Our filter should have been called once for each apply_filters call. 166 166 $this->assertEquals( 4, $a->get_call_count() ); 167 // the right hooks should have been called in order167 // The right hooks should have been called in order. 168 168 $this->assertEquals( array( $tag1, $tag2, $tag1, $tag1 ), $a->get_tags() ); 169 169 … … 183 183 $this->assertEquals( $val, apply_filters( $tag, $val ) ); 184 184 185 // make sure our hook was called correctly186 $this->assertEquals( 1, $a->get_call_count() ); 187 $this->assertEquals( array( $tag ), $a->get_tags() ); 188 189 // now remove the filter, do it again, and make sure it's not called this time185 // Make sure our hook was called correctly. 186 $this->assertEquals( 1, $a->get_call_count() ); 187 $this->assertEquals( array( $tag ), $a->get_tags() ); 188 189 // Now remove the filter, do it again, and make sure it's not called this time. 190 190 remove_filter( 'all', array( $a, 'filterall' ) ); 191 191 $this->assertFalse( has_filter( 'all', array( $a, 'filterall' ) ) ); 192 192 $this->assertFalse( has_filter( 'all' ) ); 193 193 $this->assertEquals( $val, apply_filters( $tag, $val ) ); 194 // call cound should remain at 1194 // Call cound should remain at 1. 195 195 $this->assertEquals( 1, $a->get_call_count() ); 196 196 $this->assertEquals( array( $tag ), $a->get_tags() ); … … 230 230 $args = $a->get_args(); 231 231 $this->assertSame( $args[0][0], $obj ); 232 // just in case we don't trust assertSame232 // Just in case we don't trust assertSame(). 233 233 $obj->foo = true; 234 234 $this->assertFalse( empty( $args[0][0]->foo ) ); … … 253 253 $args = $a->get_args(); 254 254 $this->assertSame( $args[0][1], $obj ); 255 // just in case we don't trust assertSame255 // Just in case we don't trust assertSame(). 256 256 $obj->foo = true; 257 257 $this->assertFalse( empty( $args[0][1]->foo ) ); … … 259 259 $args = $b->get_args(); 260 260 $this->assertSame( $args[0][1], $obj ); 261 // just in case we don't trust assertSame261 // Just in case we don't trust assertSame(). 262 262 $obj->foo = true; 263 263 $this->assertFalse( empty( $args[0][1]->foo ) ); … … 278 278 $val = __FUNCTION__ . '_val'; 279 279 280 // No priority 280 // No priority. 281 281 add_filter( $tag, array( $a, 'filter' ), 11 ); 282 282 add_filter( $tag, array( $a, 'filter' ), 12 ); … … 286 286 $this->assertFalse( has_filter( $tag ) ); 287 287 288 // Remove priorities one at a time 288 // Remove priorities one at a time. 289 289 add_filter( $tag, array( $a, 'filter' ), 11 ); 290 290 add_filter( $tag, array( $a, 'filter' ), 12 );
Note: See TracChangeset
for help on using the changeset viewer.