Changeset 41651 for trunk/tests/phpunit/tests/oembed/WpEmbed.php
- Timestamp:
- 09/30/2017 01:14:34 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/oembed/WpEmbed.php
r38762 r41651 162 162 } 163 163 164 public function test_shortcode_should_cache_data_in_post_meta_for_known_post() { 165 $GLOBALS['post'] = $this->factory()->post->create_and_get(); 164 public function test_shortcode_should_get_cached_data_from_post_meta_for_known_post() { 165 global $post; 166 167 $post = $this->factory()->post->create_and_get(); 166 168 $url = 'https://example.com/'; 167 169 $expected = '<b>Embedded content</b>'; 168 170 $key_suffix = md5( $url . serialize( wp_embed_defaults( $url ) ) ); 169 171 $cachekey = '_oembed_' . $key_suffix; 170 $cachekey_time = '_oembed_time_' . $key_suffix; 172 173 add_post_meta( $post->ID, $cachekey, $expected ); 171 174 172 175 add_filter( 'pre_oembed_result', array( $this, '_pre_oembed_result_callback' ) ); … … 174 177 remove_filter( 'pre_oembed_result', array( $this, '_pre_oembed_result_callback' ) ); 175 178 179 $actual_2 = $this->wp_embed->shortcode( array(), $url ); 180 181 $cached = get_post_meta( $post->ID, $cachekey, true ); 182 183 // Cleanup. 184 unset( $post ); 185 176 186 $this->assertEquals( $expected, $actual ); 177 178 $this->assertEquals( $expected, get_post_meta( $GLOBALS['post']->ID, $cachekey, true ) ); 179 $this->assertNotEmpty( get_post_meta( $GLOBALS['post']->ID, $cachekey_time, true ) ); 180 181 // Result should be cached. 182 $actual = $this->wp_embed->shortcode( array(), $url ); 183 $this->assertEquals( $expected, $actual ); 184 } 185 186 public function test_shortcode_should_cache_failure_in_post_meta_for_known_post() { 187 $GLOBALS['post'] = $this->factory()->post->create_and_get(); 187 $this->assertEquals( $expected, $actual_2 ); 188 $this->assertEquals( $expected, $cached ); 189 } 190 191 public function test_shortcode_should_get_cached_failure_from_post_meta_for_known_post() { 192 global $post; 193 194 $post = $this->factory()->post->create_and_get(); 188 195 $url = 'https://example.com/'; 189 196 $expected = '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>'; … … 192 199 $cachekey_time = '_oembed_time_' . $key_suffix; 193 200 201 add_post_meta( $post->ID, $cachekey, '{{unknown}}' ); 202 add_post_meta( $post->ID, $cachekey_time, 0 ); 203 194 204 add_filter( 'pre_oembed_result', '__return_empty_string' ); 195 205 $actual = $this->wp_embed->shortcode( array(), $url ); 196 206 remove_filter( 'pre_oembed_result', '__return_empty_string' ); 197 207 208 // Result should be cached. 209 $actual_2 = $this->wp_embed->shortcode( array(), $url ); 210 211 $cached = get_post_meta( $post->ID, $cachekey, true ); 212 $cached_time = get_post_meta( $post->ID, $cachekey_time, true ); 213 214 // Cleanup. 215 unset( $post ); 216 198 217 $this->assertEquals( $expected, $actual ); 199 200 $this->assertEquals( '{{unknown}}', get_post_meta( $GLOBALS['post']->ID, $cachekey, true ) ); 201 $this->assertEmpty( get_post_meta( $GLOBALS['post']->ID, $cachekey_time, true ) ); 218 $this->assertEquals( '{{unknown}}', $cached ); 219 $this->assertEmpty( $cached_time ); 220 $this->assertEquals( $expected, $actual_2 ); 221 } 222 223 /** 224 * @ticket 34115 225 */ 226 public function test_shortcode_should_cache_data_in_custom_post() { 227 $url = 'https://example.com/'; 228 $expected = '<b>Embedded content</b>'; 229 $key_suffix = md5( $url . serialize( wp_embed_defaults( $url ) ) ); 230 231 add_filter( 'pre_oembed_result', array( $this, '_pre_oembed_result_callback' ) ); 232 $actual = $this->wp_embed->shortcode( array(), $url ); 233 remove_filter( 'pre_oembed_result', array( $this, '_pre_oembed_result_callback' ) ); 234 235 $oembed_post_id = $this->wp_embed->find_oembed_post_id( $key_suffix ); 236 $post_content = get_post( $oembed_post_id )->post_content; 202 237 203 238 // Result should be cached. 204 $actual = $this->wp_embed->shortcode( array(), $url ); 239 $actual_2 = $this->wp_embed->shortcode( array(), $url ); 240 241 wp_delete_post( $oembed_post_id ); 242 243 $this->assertNotNull( $oembed_post_id ); 244 $this->assertEquals( $expected, $post_content ); 205 245 $this->assertEquals( $expected, $actual ); 246 $this->assertEquals( $expected, $actual_2 ); 247 } 248 249 /** 250 * @ticket 34115 251 */ 252 public function test_shortcode_should_cache_failure_in_custom_post() { 253 $url = 'https://example.com/'; 254 $expected = '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>'; 255 $key_suffix = md5( $url . serialize( wp_embed_defaults( $url ) ) ); 256 257 add_filter( 'pre_oembed_result', '__return_empty_string' ); 258 $actual = $this->wp_embed->shortcode( array(), $url ); 259 remove_filter( 'pre_oembed_result', '__return_empty_string' ); 260 261 $oembed_post_id = $this->wp_embed->find_oembed_post_id( $key_suffix ); 262 $post_content = get_post( $oembed_post_id )->post_content; 263 264 // Result should be cached. 265 $actual_2 = $this->wp_embed->shortcode( array(), $url ); 266 267 wp_delete_post( $oembed_post_id ); 268 269 $this->assertEquals( $expected, $actual ); 270 $this->assertEquals( $expected, $actual_2 ); 271 $this->assertNotNull( $oembed_post_id ); 272 $this->assertEquals( '{{unknown}}', $post_content ); 206 273 } 207 274
Note: See TracChangeset
for help on using the changeset viewer.