| 157 | |
| 158 | /** |
| 159 | * @ticket 24686 |
| 160 | */ |
| 161 | function test_getted_transient_filter() { |
| 162 | |
| 163 | $key = 'test_getted_transient'; |
| 164 | set_transient( $key, 'test_value', MINUTE_IN_SECONDS ); |
| 165 | |
| 166 | $transient = get_transient( $key ); |
| 167 | |
| 168 | $this->assertSame( 'test_value', $transient ); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * @ticket 24686 |
| 173 | */ |
| 174 | function test_getted_transient_return_false() { |
| 175 | |
| 176 | $key = 'test_getted_transient'; |
| 177 | set_transient( $key, 'test_value', MINUTE_IN_SECONDS ); |
| 178 | |
| 179 | add_filter( 'getted_transient', '__return_false' ); |
| 180 | |
| 181 | $transient = get_transient( $key ); |
| 182 | |
| 183 | remove_filter( 'getted_transient', '__return_false' ); |
| 184 | |
| 185 | $this->assertSame( false, $transient ); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * @ticket 24686 |
| 190 | */ |
| 191 | function test_getted_transient_bypass_single_transient() { |
| 192 | $key1 = 'test_getted_transient_1'; |
| 193 | $key2 = 'test_getted_transient_2'; |
| 194 | set_transient( $key1, 'test_value_1', MINUTE_IN_SECONDS ); |
| 195 | set_transient( $key2, 'test_value_2', MINUTE_IN_SECONDS ); |
| 196 | |
| 197 | add_filter( 'getted_transient', array( $this, 'bypass_first_transient_only' ), 10, 2 ); |
| 198 | |
| 199 | $transient_1 = get_transient( $key1 ); |
| 200 | $transient_2 = get_transient( $key2 ); |
| 201 | |
| 202 | remove_filter( 'getted_transient', array( $this, 'bypass_first_transient_only' ) ); |
| 203 | |
| 204 | $this->assertSame( false, $transient_1 ); |
| 205 | $this->assertSame( 'test_value_2', $transient_2 ); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Callback for the test above. |
| 210 | * |
| 211 | * @param string $value The value of the transient. |
| 212 | * @param string $transient The name of the transient. |
| 213 | * |
| 214 | * @return bool|string|mixed |
| 215 | */ |
| 216 | function bypass_first_transient_only( $value, $transient ) { |
| 217 | if ( 'test_getted_transient_1' === $transient ) { |
| 218 | $value = false; |
| 219 | } |
| 220 | return $value; |
| 221 | } |
| 222 | |