Ticket #39265: o_folders.patch
File o_folders.patch, 63.0 KB (added by , 4 years ago) |
---|
-
oembed/controller.php
173 173 $this->oembed_result_filter_count++; 174 174 return $data; 175 175 } 176 176 177 /** 178 * @covers ::wp_oembed_ensure_format 179 */ 177 180 function test_wp_oembed_ensure_format() { 178 181 $this->assertSame( 'json', wp_oembed_ensure_format( 'json' ) ); 179 182 $this->assertSame( 'xml', wp_oembed_ensure_format( 'xml' ) ); … … 181 184 $this->assertSame( 'json', wp_oembed_ensure_format( 'random' ) ); 182 185 $this->assertSame( 'json', wp_oembed_ensure_format( array() ) ); 183 186 } 184 187 188 /** 189 * @covers ::_oembed_create_xml 190 */ 185 191 function test_oembed_create_xml() { 186 192 $actual = _oembed_create_xml( 187 193 array( … … 238 244 239 245 $this->assertStringEndsWith( $expected, trim( $actual ) ); 240 246 } 241 247 248 /** 249 * @covers WP_REST_Server::get_routes 250 */ 242 251 public function test_route_availability() { 243 252 // Check the route was registered correctly. 244 253 $filtered_routes = rest_get_server()->get_routes(); … … 258 267 $this->assertArrayHasKey( 'methods', $proxy_route[0] ); 259 268 $this->assertArrayHasKey( 'args', $proxy_route[0] ); 260 269 } 261 270 271 /** 272 * @covers WP_REST_Server::dispatch 273 * @covers WP_HTTP_Requests_Response::get_data 274 */ 262 275 function test_request_with_wrong_method() { 263 276 $request = new WP_REST_Request( 'POST', '/oembed/1.0/embed' ); 264 277 … … 267 280 268 281 $this->assertSame( 'rest_no_route', $data['code'] ); 269 282 } 270 283 284 /** 285 * @covers WP_REST_Server::dispatch 286 * @covers WP_HTTP_Requests_Response::get_data 287 */ 271 288 function test_request_without_url_param() { 272 289 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 273 290 … … 277 294 $this->assertSame( 'rest_missing_callback_param', $data['code'] ); 278 295 $this->assertSame( 'url', $data['data']['params'][0] ); 279 296 } 280 297 298 /** 299 * @covers WP_REST_Server::dispatch 300 * @covers WP_HTTP_Requests_Response::get_data 301 */ 281 302 function test_request_with_bad_url() { 282 303 $request = new WP_REST_Request( 'GET', '/oembed/1.0/embed' ); 283 304 $request->set_param( 'url', 'http://google.com/' ); … … 287 308 288 309 $this->assertSame( 'oembed_invalid_url', $data['code'] ); 289 310 } 290 311 312 /** 313 * @covers WP_REST_Server::dispatch 314 * @covers WP_HTTP_Requests_Response::get_data 315 */ 291 316 function test_request_invalid_format() { 292 317 $post_id = $this->factory()->post->create(); 293 318 … … 301 326 $this->assertInternalType( 'array', $data ); 302 327 $this->assertNotEmpty( $data ); 303 328 } 304 329 330 /** 331 * @covers WP_REST_Server::dispatch 332 * @covers WP_HTTP_Requests_Response::get_data 333 */ 305 334 function test_request_json() { 306 335 $user = self::factory()->user->create_and_get( 307 336 array( … … 346 375 347 376 /** 348 377 * @ticket 34971 378 * @covers WP_REST_Server::dispatch 379 * @covers WP_HTTP_Requests_Response::get_data 349 380 */ 350 381 function test_request_static_front_page() { 351 382 $post = self::factory()->post->create_and_get( … … 388 419 389 420 update_option( 'show_on_front', 'posts' ); 390 421 } 391 422 423 /** 424 * @covers WP_REST_Server::dispatch 425 * @covers WP_HTTP_Requests_Response::get_data 426 */ 392 427 function test_request_xml() { 393 428 $user = self::factory()->user->create_and_get( 394 429 array( … … 435 470 /** 436 471 * @group multisite 437 472 * @group ms-required 473 * 474 * @covers WP_REST_Server::dispatch 475 * @covers WP_HTTP_Requests_Response::get_data 438 476 */ 439 477 function test_request_ms_child_in_root_blog() { 440 478 $child = self::factory()->blog->create(); … … 458 496 459 497 restore_current_blog(); 460 498 } 461 499 500 /** 501 * @covers ::_oembed_rest_pre_serve_request 502 */ 462 503 function test_rest_pre_serve_request() { 463 504 $user = $this->factory()->user->create_and_get( 464 505 array( … … 482 523 $xml = simplexml_load_string( $output ); 483 524 $this->assertInstanceOf( 'SimpleXMLElement', $xml ); 484 525 } 485 526 527 /** 528 * @covers ::_oembed_rest_pre_serve_request 529 */ 486 530 function test_rest_pre_serve_request_wrong_format() { 487 531 $post = $this->factory()->post->create_and_get(); 488 532 … … 494 538 495 539 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) ); 496 540 } 497 541 542 /** 543 * @covers ::_oembed_rest_pre_serve_request 544 */ 498 545 function test_rest_pre_serve_request_wrong_method() { 499 546 $post = $this->factory()->post->create_and_get(); 500 547 … … 506 553 507 554 $this->assertTrue( _oembed_rest_pre_serve_request( true, $response, $request, rest_get_server() ) ); 508 555 } 509 556 557 /** 558 * @covers ::get_oembed_endpoint_url 559 */ 510 560 function test_get_oembed_endpoint_url() { 511 561 $this->assertSame( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url() ); 512 562 $this->assertSame( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'json' ) ); … … 519 569 $this->assertSame( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded, get_oembed_endpoint_url( $url ) ); 520 570 $this->assertSame( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) ); 521 571 } 522 572 573 /** 574 * @covers ::get_oembed_endpoint_url 575 */ 523 576 function test_get_oembed_endpoint_url_pretty_permalinks() { 524 577 update_option( 'permalink_structure', '/%postname%' ); 525 578 … … 535 588 536 589 update_option( 'permalink_structure', '' ); 537 590 } 538 591 592 /** 593 * @covers WP_REST_Server::dispatch 594 * @covers WP_HTTP_Requests_Response::get_data 595 */ 539 596 public function test_proxy_without_permission() { 540 597 // Test without a login. 541 598 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); … … 553 610 $data = $response->get_data(); 554 611 $this->assertSame( $data['code'], 'rest_forbidden' ); 555 612 } 556 613 614 /** 615 * @covers WP_REST_Server::dispatch 616 * @covers WP_HTTP_Requests_Response::get_data 617 */ 557 618 public function test_proxy_with_invalid_oembed_provider() { 558 619 wp_set_current_user( self::$editor ); 559 620 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); … … 563 624 $data = $response->get_data(); 564 625 $this->assertSame( 'oembed_invalid_url', $data['code'] ); 565 626 } 566 627 628 /** 629 * @covers WP_REST_Server::dispatch 630 * @covers WP_HTTP_Requests_Response::get_status 631 */ 567 632 public function test_proxy_with_invalid_type() { 568 633 wp_set_current_user( self::$editor ); 569 634 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); … … 572 637 573 638 $this->assertSame( 400, $response->get_status() ); 574 639 } 575 640 641 /** 642 * @covers WP_REST_Server::dispatch 643 * @covers WP_HTTP_Requests_Response::get_status 644 * @covers WP_HTTP_Requests_Response::get_data 645 */ 576 646 public function test_proxy_with_valid_oembed_provider() { 577 647 wp_set_current_user( self::$editor ); 578 648 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); … … 613 683 * @ticket 45447 614 684 * 615 685 * @see wp_maybe_load_embeds() 686 * 687 * @covers WP_REST_Server::dispatch 688 * @covers WP_HTTP_Requests_Response::get_status 689 * @covers WP_HTTP_Requests_Response::get_data 616 690 */ 617 691 public function test_proxy_with_classic_embed_provider() { 618 692 wp_set_current_user( self::$editor ); … … 633 707 $this->assertInternalType( 'string', $data->html ); 634 708 $this->assertInternalType( 'array', $data->scripts ); 635 709 } 636 710 711 /** 712 * @covers WP_REST_Server::dispatch 713 * @covers WP_HTTP_Requests_Response::get_status 714 */ 637 715 public function test_proxy_with_invalid_oembed_provider_no_discovery() { 638 716 wp_set_current_user( self::$editor ); 639 717 … … 645 723 $this->assertSame( 404, $response->get_status() ); 646 724 $this->assertSame( 0, $this->request_count ); 647 725 } 648 726 727 /** 728 * @covers WP_REST_Server::dispatch 729 * @covers WP_HTTP_Requests_Response::get_status 730 */ 649 731 public function test_proxy_with_invalid_oembed_provider_with_default_discover_param() { 650 732 wp_set_current_user( self::$editor ); 651 733 … … 656 738 $this->assertSame( 404, $response->get_status() ); 657 739 $this->assertSame( 1, $this->request_count ); 658 740 } 659 741 742 /** 743 * @covers WP_REST_Server::dispatch 744 * @covers WP_HTTP_Requests_Response::get_status 745 * @covers WP_HTTP_Requests_Response::get_data 746 */ 660 747 public function test_proxy_with_invalid_discover_param() { 661 748 wp_set_current_user( self::$editor ); 662 749 $request = new WP_REST_Request( 'GET', '/oembed/1.0/proxy' ); … … 672 759 673 760 /** 674 761 * @ticket 45142 762 * 763 * @covers WP_REST_Server::dispatch 764 * @covers WP_HTTP_Requests_Response::get_data 675 765 */ 676 766 function test_proxy_with_internal_url() { 677 767 wp_set_current_user( self::$editor ); … … 720 810 721 811 /** 722 812 * @ticket 45142 813 * 814 * @covers WP_REST_Server::dispatch 815 * @covers WP_HTTP_Requests_Response::get_data 723 816 */ 724 817 function test_proxy_with_static_front_page_url() { 725 818 wp_set_current_user( self::$editor ); … … 771 864 772 865 /** 773 866 * @ticket 45142 867 * 868 * @covers WP_REST_Server::dispatch 869 * @covers WP_HTTP_Requests_Response::get_data 774 870 */ 775 871 public function test_proxy_filters_result_of_untrusted_oembed_provider() { 776 872 wp_set_current_user( self::$editor ); … … 794 890 795 891 /** 796 892 * @ticket 45142 893 * 894 * @covers WP_REST_Server::dispatch 895 * @covers WP_HTTP_Requests_Response::get_data 797 896 */ 798 897 public function test_proxy_does_not_filter_result_of_trusted_oembed_provider() { 799 898 wp_set_current_user( self::$editor ); -
oembed/discovery.php
4 4 * @group oembed 5 5 */ 6 6 class Tests_oEmbed_Discovery extends WP_UnitTestCase { 7 8 /** 9 * @ticket 34971 10 * @covers ::wp_oembed_add_discovery_links 11 */ 7 12 function test_add_oembed_discovery_links_non_singular() { 8 13 $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) ); 9 14 } 10 15 16 /** 17 * @covers ::wp_oembed_add_discovery_links 18 */ 11 19 function test_add_oembed_discovery_links_front_page() { 12 20 $this->go_to( home_url() ); 13 21 $this->assertSame( '', get_echo( 'wp_oembed_add_discovery_links' ) ); … … 16 24 17 25 /** 18 26 * @ticket 34971 27 * @covers ::wp_oembed_add_discovery_links 19 28 */ 20 29 function test_add_oembed_discovery_links_static_front_page() { 21 30 update_option( 'show_on_front', 'page' ); … … 40 49 update_option( 'show_on_front', 'posts' ); 41 50 } 42 51 52 /** 53 * @covers ::wp_oembed_add_discovery_links 54 */ 43 55 function test_add_oembed_discovery_links_to_post() { 44 56 $post_id = self::factory()->post->create(); 45 57 $this->go_to( get_permalink( $post_id ) ); … … 50 62 51 63 $this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) ); 52 64 } 53 65 66 /** 67 * @covers ::wp_oembed_add_discovery_links 68 */ 54 69 function test_add_oembed_discovery_links_to_page() { 55 70 $post_id = self::factory()->post->create( 56 71 array( … … 65 80 66 81 $this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) ); 67 82 } 68 83 84 /** 85 * @covers ::wp_oembed_add_discovery_links 86 */ 69 87 function test_add_oembed_discovery_links_to_attachment() { 70 88 $post_id = self::factory()->post->create(); 71 89 $file = DIR_TESTDATA . '/images/canola.jpg'; -
oembed/filterResult.php
4 4 * @group oembed 5 5 */ 6 6 class Tests_Filter_oEmbed_Result extends WP_UnitTestCase { 7 8 /** 9 * @covers ::wp_filter_oembed_result 10 */ 7 11 function test_filter_oembed_result_trusted_malicious_iframe() { 8 12 $html = '<p></p><iframe onload="alert(1)"></iframe>'; 9 13 … … 11 15 12 16 $this->assertSame( $html, $actual ); 13 17 } 14 18 19 /** 20 * @covers ::wp_filter_oembed_result 21 */ 15 22 function test_filter_oembed_result_with_untrusted_provider() { 16 23 $html = '<p></p><iframe onload="alert(1)" src="http://example.com/sample-page/"></iframe>'; 17 24 $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), 'http://example.com/sample-page/' ); … … 23 30 $this->assertTrue( isset( $matches[2] ) ); 24 31 $this->assertSame( $matches[1], $matches[2] ); 25 32 } 26 33 34 /** 35 * @covers ::wp_filter_oembed_result 36 */ 27 37 function test_filter_oembed_result_only_one_iframe_is_allowed() { 28 38 $html = '<div><iframe></iframe><iframe></iframe><p></p></div>'; 29 39 $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ); … … 43 53 44 54 $this->assertSame( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"></iframe>', $actual ); 45 55 } 46 56 57 /** 58 * @covers ::wp_filter_oembed_result 59 */ 47 60 function test_filter_oembed_result_without_iframe() { 48 61 $html = '<span>Hello</span><p>World</p>'; 49 62 $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ); … … 55 68 56 69 $this->assertFalse( $actual ); 57 70 } 58 71 72 /** 73 * @covers ::wp_filter_oembed_result 74 */ 59 75 function test_filter_oembed_result_secret_param_available() { 60 76 $html = '<iframe src="https://wordpress.org"></iframe>'; 61 77 $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ); … … 67 83 $this->assertTrue( isset( $matches[2] ) ); 68 84 $this->assertSame( $matches[1], $matches[2] ); 69 85 } 70 86 87 /** 88 * @covers ::wp_filter_oembed_result 89 */ 71 90 function test_filter_oembed_result_wrong_type_provided() { 72 91 $actual = wp_filter_oembed_result( 'some string', (object) array( 'type' => 'link' ), '' ); 73 92 74 93 $this->assertSame( 'some string', $actual ); 75 94 } 76 95 96 /** 97 * @covers ::wp_filter_oembed_result 98 */ 77 99 function test_filter_oembed_result_invalid_result() { 78 100 $this->assertFalse( wp_filter_oembed_result( false, (object) array( 'type' => 'rich' ), '' ) ); 79 101 $this->assertFalse( wp_filter_oembed_result( '', (object) array( 'type' => 'rich' ), '' ) ); 80 102 } 81 103 104 /** 105 * @covers ::wp_filter_oembed_result 106 */ 82 107 function test_filter_oembed_result_blockquote_adds_style_to_iframe() { 83 108 $html = '<blockquote></blockquote><iframe></iframe>'; 84 109 $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ); … … 85 110 86 111 $this->assertSame( '<blockquote class="wp-embedded-content"></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual ); 87 112 } 88 113 114 /** 115 * @covers ::wp_filter_oembed_result 116 */ 89 117 function test_filter_oembed_result_allowed_html() { 90 118 $html = '<blockquote class="foo" id="bar"><strong><a href="" target=""></a></strong></blockquote><iframe></iframe>'; 91 119 $actual = wp_filter_oembed_result( $html, (object) array( 'type' => 'rich' ), '' ); … … 92 120 93 121 $this->assertSame( '<blockquote class="wp-embedded-content"><a href=""></a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"></iframe>', $actual ); 94 122 } 95 123 96 124 public function _data_oembed_test_strings() { 97 125 return array( 98 126 array( … … 115 143 } 116 144 117 145 /** 118 * @dataProvider _data_oembed_test_strings 146 * @dataProvider 147 * 148 * @covers ::_wp_oembed_get_object 149 * @covers WP_oEmbed::data2html 119 150 */ 120 151 public function test_wp_filter_pre_oembed_custom_result( $html, $expected ) { 121 152 $data = (object) array( … … 129 160 130 161 /** 131 162 * @group feed 163 * 164 * @covers ::_oembed_filter_feed_content 165 * @covers ::wp_filter_oembed_result 132 166 */ 133 167 function test_filter_feed_content() { 134 168 $html = '<blockquote></blockquote><iframe></iframe>'; -
oembed/filterTitleAttributes.php
63 63 64 64 /** 65 65 * @dataProvider data_filter_oembed_iframe_title_attribute 66 * 67 * @covers ::wp_filter_oembed_iframe_title_attribute 66 68 */ 67 69 public function test_oembed_iframe_title_attribute( $html, $oembed_data, $url, $expected ) { 68 70 $actual = wp_filter_oembed_iframe_title_attribute( $html, (object) $oembed_data, $url ); … … 69 71 70 72 $this->assertSame( $expected, $actual ); 71 73 } 72 74 75 /** 76 * @covers ::wp_filter_oembed_iframe_title_attribute 77 */ 73 78 public function test_filter_oembed_iframe_title_attribute() { 74 79 add_filter( 'oembed_iframe_title_attribute', array( $this, '_filter_oembed_iframe_title_attribute' ) ); 75 80 … … 86 91 87 92 $this->assertSame( '<iframe title="Baz" src=""></iframe>', $actual ); 88 93 } 89 94 95 /** 96 * @covers ::wp_filter_oembed_iframe_title_attribute 97 */ 90 98 public function test_filter_oembed_iframe_title_attribute_does_not_modify_other_tags() { 91 99 add_filter( 'oembed_iframe_title_attribute', array( $this, '_filter_oembed_iframe_title_attribute' ) ); 92 100 -
oembed/getResponseData.php
4 4 * @group oembed 5 5 */ 6 6 class Tests_oEmbed_Response_Data extends WP_UnitTestCase { 7 8 /** 9 * @covers ::get_oembed_response_data 10 */ 7 11 function test_get_oembed_response_data_non_existent_post() { 8 12 $this->assertFalse( get_oembed_response_data( 0, 100 ) ); 9 13 } 10 14 15 /** 16 * @covers ::get_oembed_response_data 17 * @covers ::get_post_embed_html 18 */ 11 19 function test_get_oembed_response_data() { 12 20 $post = self::factory()->post->create_and_get( 13 21 array( … … 36 44 37 45 /** 38 46 * Test get_oembed_response_data with an author. 47 * 48 * @covers ::get_oembed_response_data 49 * @covers ::get_post_embed_html 39 50 */ 40 51 function test_get_oembed_response_data_author() { 41 52 $user_id = self::factory()->user->create( … … 69 80 $data 70 81 ); 71 82 } 72 83 84 /** 85 * @covers ::get_oembed_response_data 86 */ 73 87 function test_get_oembed_response_link() { 74 88 remove_filter( 'oembed_response_data', 'get_oembed_response_data_rich' ); 75 89 … … 96 110 97 111 add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 ); 98 112 } 99 113 114 /** 115 * @covers ::get_oembed_response_data 116 */ 100 117 function test_get_oembed_response_data_with_draft_post() { 101 118 $post = self::factory()->post->create_and_get( 102 119 array( … … 106 123 107 124 $this->assertFalse( get_oembed_response_data( $post, 100 ) ); 108 125 } 109 126 127 /** 128 * @covers ::get_oembed_response_data 129 */ 110 130 function test_get_oembed_response_data_with_scheduled_post() { 111 131 $post = self::factory()->post->create_and_get( 112 132 array( … … 117 137 118 138 $this->assertFalse( get_oembed_response_data( $post, 100 ) ); 119 139 } 120 140 141 /** 142 * @covers ::get_oembed_response_data 143 */ 121 144 function test_get_oembed_response_data_with_private_post() { 122 145 $post = self::factory()->post->create_and_get( 123 146 array( … … 127 150 128 151 $this->assertFalse( get_oembed_response_data( $post, 100 ) ); 129 152 } 130 153 154 /** 155 * @covers ::get_oembed_response_data 156 */ 131 157 function test_get_oembed_response_data_maxwidth_too_high() { 132 158 $post = self::factory()->post->create_and_get(); 133 159 … … 136 162 $this->assertSame( 600, $data['width'] ); 137 163 $this->assertSame( 338, $data['height'] ); 138 164 } 139 165 166 /** 167 * @covers ::get_oembed_response_data 168 */ 140 169 function test_get_oembed_response_data_maxwidth_too_low() { 141 170 $post = self::factory()->post->create_and_get(); 142 171 … … 145 174 $this->assertSame( 200, $data['width'] ); 146 175 $this->assertSame( 200, $data['height'] ); 147 176 } 148 177 178 /** 179 * @covers ::get_oembed_response_data 180 */ 149 181 function test_get_oembed_response_data_maxwidth_invalid() { 150 182 $post = self::factory()->post->create_and_get(); 151 183 … … 159 191 $this->assertSame( 200, $data['width'] ); 160 192 $this->assertSame( 200, $data['height'] ); 161 193 } 162 194 195 /** 196 * @covers ::get_oembed_response_data 197 */ 163 198 function test_get_oembed_response_data_with_thumbnail() { 164 199 $post = self::factory()->post->create_and_get(); 165 200 $file = DIR_TESTDATA . '/images/canola.jpg'; … … 179 214 $this->assertArrayHasKey( 'thumbnail_height', $data ); 180 215 $this->assertTrue( 400 >= $data['thumbnail_width'] ); 181 216 } 182 217 218 /** 219 * @covers ::get_oembed_response_data 220 */ 183 221 function test_get_oembed_response_data_for_attachment() { 184 222 $parent = self::factory()->post->create(); 185 223 $file = DIR_TESTDATA . '/images/canola.jpg'; -
oembed/headers.php
11 11 12 12 /** 13 13 * @requires function xdebug_get_headers 14 * 15 * @covers WP_REST_Request 16 * @covers WP_REST_Server::dispatch 14 17 */ 15 18 function test_rest_pre_serve_request_headers() { 16 19 $post = $this->factory()->post->create_and_get( -
oembed/postEmbedUrl.php
4 4 * @group oembed 5 5 */ 6 6 class Tests_Post_Embed_URL extends WP_UnitTestCase { 7 8 /** 9 * @covers ::get_post_embed_url 10 */ 7 11 function test_non_existent_post() { 8 12 $embed_url = get_post_embed_url( 0 ); 9 13 $this->assertFalse( $embed_url ); 10 14 } 11 15 16 /** 17 * @uses ::get_permalink 18 * @covers ::get_post_embed_url 19 */ 12 20 function test_with_pretty_permalinks() { 13 21 $this->set_permalink_structure( '/%postname%' ); 14 22 … … 18 26 19 27 $this->assertSame( $permalink . '/embed', $embed_url ); 20 28 } 21 29 30 /** 31 * @covers ::get_post_embed_url 32 */ 22 33 function test_with_ugly_permalinks() { 23 34 $post_id = self::factory()->post->create(); 24 35 $permalink = get_permalink( $post_id ); … … 29 40 30 41 /** 31 42 * @ticket 34971 43 * 44 * @covers ::get_post_embed_url 32 45 */ 33 46 function test_static_front_page() { 34 47 $this->set_permalink_structure( '/%postname%/' ); … … 47 60 48 61 /** 49 62 * @ticket 34971 63 * 64 * @covers ::get_post_embed_url 50 65 */ 51 66 function test_static_front_page_with_ugly_permalinks() { 52 67 $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); … … 63 78 64 79 /** 65 80 * @ticket 34971 81 * 82 * @covers ::get_post_embed_url 66 83 */ 67 84 function test_page_conflicts_with_embed_slug() { 68 85 $this->set_permalink_structure( '/%postname%/' ); … … 85 102 86 103 /** 87 104 * @ticket 34971 105 * 106 * @covers ::get_post_embed_url 88 107 */ 89 108 function test_static_front_page_conflicts_with_embed_slug() { 90 109 $this->set_permalink_structure( '/%postname%/' ); -
oembed/template.php
4 4 * @group oembed 5 5 */ 6 6 class Tests_Embed_Template extends WP_UnitTestCase { 7 8 /** 9 * @covers ::get_post_embed_url 10 */ 7 11 function test_oembed_output_post() { 8 12 $user = self::factory()->user->create_and_get( 9 13 array( … … 32 36 $this->assertFalse( strpos( $actual, 'That embed can’t be found.' ) ); 33 37 $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); 34 38 } 35 39 40 /** 41 * @covers ::get_post_embed_url 42 */ 36 43 function test_oembed_output_post_with_thumbnail() { 37 44 $post_id = self::factory()->post->create( 38 45 array( … … 65 72 $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); 66 73 $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) ); 67 74 } 68 75 76 /** 77 * @covers ::get_post_embed_url 78 */ 69 79 function test_oembed_output_404() { 70 80 $this->go_to( home_url( '/?p=123&embed=true' ) ); 71 81 $GLOBALS['wp_query']->query_vars['embed'] = true; … … 109 119 $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); 110 120 $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) ); 111 121 } 112 122 123 /** 124 * @covers ::get_post_embed_url 125 */ 113 126 function test_oembed_output_draft_post() { 114 127 $post_id = self::factory()->post->create( 115 128 array( … … 132 145 $this->assertTrue( $doc->loadHTML( $actual ) ); 133 146 $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); 134 147 } 135 148 149 /** 150 * @covers ::get_post_embed_url 151 */ 136 152 function test_oembed_output_scheduled_post() { 137 153 $post_id = self::factory()->post->create( 138 154 array( … … 156 172 $this->assertTrue( $doc->loadHTML( $actual ) ); 157 173 $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); 158 174 } 159 175 176 /** 177 * @covers ::get_post_embed_url 178 */ 160 179 function test_oembed_output_private_post() { 161 180 $post_id = self::factory()->post->create( 162 181 array( … … 179 198 $this->assertTrue( $doc->loadHTML( $actual ) ); 180 199 $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); 181 200 } 182 201 202 /** 203 * @covers ::get_post_embed_url 204 */ 183 205 function test_oembed_output_private_post_with_permissions() { 184 206 $user_id = self::factory()->user->create( array( 'role' => 'editor' ) ); 185 207 wp_set_current_user( $user_id ); … … 207 229 $this->assertFalse( strpos( $actual, 'That embed can’t be found.' ) ); 208 230 $this->assertNotFalse( strpos( $actual, 'Hello World' ) ); 209 231 } 210 232 233 /** 234 * @covers ::wp_embed_excerpt_more 235 */ 211 236 function test_wp_embed_excerpt_more_no_embed() { 212 237 $GLOBALS['wp_query'] = new WP_Query(); 213 238 214 239 $this->assertSame( 'foo bar', wp_embed_excerpt_more( 'foo bar' ) ); 215 240 } 216 241 242 /** 243 * @covers ::wp_embed_excerpt_more 244 * @covers ::get_post_embed_url 245 */ 217 246 function test_wp_embed_excerpt_more() { 218 247 $post_id = self::factory()->post->create( 219 248 array( … … 235 264 236 265 $this->assertSame( $expected, $actual ); 237 266 } 238 267 268 /** 269 * @covers ::is_embed 270 * @covers ::get_post_embed_url 271 */ 239 272 function test_is_embed_post() { 240 273 $this->assertFalse( is_embed() ); 241 274 … … 243 276 $this->go_to( get_post_embed_url( $post_id ) ); 244 277 $this->assertTrue( is_embed() ); 245 278 } 246 279 280 /** 281 * @covers ::is_embed 282 * @covers ::get_post_embed_url 283 */ 247 284 function test_is_embed_attachment() { 248 285 $post_id = self::factory()->post->create(); 249 286 $file = DIR_TESTDATA . '/images/canola.jpg'; … … 257 294 $this->go_to( get_post_embed_url( $attachment_id ) ); 258 295 $this->assertTrue( is_embed() ); 259 296 } 260 297 298 /** 299 * @uses ::home_url 300 * @covers ::is_embed 301 */ 261 302 function test_is_embed_404() { 262 303 $this->go_to( home_url( '/?p=12345&embed=true' ) ); 263 304 $this->assertTrue( is_embed() ); 264 305 } 265 306 307 /** 308 * @covers ::get_post_embed_html 309 */ 266 310 function test_get_post_embed_html_non_existent_post() { 267 311 $this->assertFalse( get_post_embed_html( 200, 200, 0 ) ); 268 312 $this->assertFalse( get_post_embed_html( 200, 200 ) ); 269 313 } 270 314 315 /** 316 * @covers ::get_post_embed_url 317 * @covers ::get_post_embed_html 318 */ 271 319 function test_get_post_embed_html() { 272 320 $post_id = self::factory()->post->create(); 273 321 $title = esc_attr( … … 282 330 283 331 $this->assertStringEndsWith( $expected, get_post_embed_html( 200, 200, $post_id ) ); 284 332 } 285 333 334 /** 335 * @covers ::wp_oembed_add_host_js 336 */ 286 337 function test_add_host_js() { 287 338 wp_oembed_add_host_js(); 288 339 -
oembed/WpEmbed.php
21 21 public function _pre_oembed_result_callback() { 22 22 return '<b>Embedded content</b>'; 23 23 } 24 24 25 /** 26 * @covers WP_Embed::maybe_run_ajax_cache 27 */ 25 28 public function test_maybe_run_ajax_cache_should_return_nothing_if_there_is_no_post() { 26 29 $this->expectOutputString( '' ); 27 30 $this->wp_embed->maybe_run_ajax_cache(); 28 31 } 29 32 33 /** 34 * @covers WP_Embed::maybe_run_ajax_cache 35 */ 30 36 public function test_maybe_run_ajax_cache_should_return_nothing_if_there_is_no_message() { 31 37 $GLOBALS['post'] = $this->factory()->post->create_and_get( 32 38 array( … … 39 45 $this->wp_embed->maybe_run_ajax_cache(); 40 46 unset( $GLOBALS['post'] ); 41 47 } 42 48 49 /** 50 * @covers WP_Embed::maybe_run_ajax_cache 51 */ 43 52 public function test_maybe_run_ajax_cache_should_return_javascript() { 44 53 $GLOBALS['post'] = $this->factory()->post->create_and_get( 45 54 array( … … 91 100 92 101 $this->assertContains( $expected, $actual ); 93 102 } 94 103 95 104 public function test_wp_embed_unregister_handler() { 96 105 $this->assertArrayHasKey( 'youtube_embed_url', $GLOBALS['wp_embed']->handlers[10] ); 97 106 … … 104 113 105 114 $this->assertArrayNotHasKey( 'youtube_embed_url', $handlers ); 106 115 } 107 116 117 /** 118 * @covers WP_Embed::autoembed 119 */ 108 120 public function test_autoembed_should_do_nothing_without_matching_handler() { 109 121 $content = "\nhttp://example.com/embed/foo\n"; 110 122 … … 111 123 $actual = $this->wp_embed->autoembed( $content ); 112 124 $this->assertSame( $content, $actual ); 113 125 } 114 126 127 /** 128 * @covers WP_Embed::autoembed 129 */ 115 130 public function test_autoembed_should_return_modified_content() { 116 131 $handle = __FUNCTION__; 117 132 $regex = '#https?://example\.com/embed/([^/]+)#i'; … … 126 141 127 142 $this->assertSame( "\nEmbedded http://example.com/embed/foo\n", $actual ); 128 143 } 129 144 145 /** 146 * @covers WP_Embed::delete_oembed_caches 147 */ 130 148 public function test_delete_oembed_caches() { 131 149 $post_id = $this->factory()->post->create(); 132 150 … … 139 157 $this->assertSame( array(), get_post_meta( $post_id, '_oembed_foo' ) ); 140 158 $this->assertSame( array(), get_post_meta( $post_id, '_oembed_baz' ) ); 141 159 } 142 160 161 /** 162 * @covers WP_Embed::cache_oembed 163 */ 143 164 public function test_cache_oembed_invalid_post_type() { 144 165 $post_id = $this->factory()->post->create( array( 'post_type' => 'nav_menu_item' ) ); 145 166 … … 146 167 $this->wp_embed->cache_oembed( $post_id ); 147 168 $this->assertNotSame( $post_id, $this->wp_embed->post_ID ); 148 169 } 149 170 171 /** 172 * @covers WP_Embed::cache_oembed 173 */ 150 174 public function test_cache_oembed_empty_content() { 151 175 $post_id = $this->factory()->post->create( array( 'post_content' => '' ) ); 152 176 … … 153 177 $this->wp_embed->cache_oembed( $post_id ); 154 178 $this->assertNotSame( $post_id, $this->wp_embed->post_ID ); 155 179 } 156 180 181 /** 182 * @covers WP_Embed::cache_oembed 183 */ 157 184 public function test_cache_oembed_for_post() { 158 185 $url = 'https://example.com/'; 159 186 $expected = '<b>Embedded content</b>'; … … 171 198 $this->assertSame( $expected, get_post_meta( $post_id, $cachekey, true ) ); 172 199 $this->assertNotEmpty( get_post_meta( $post_id, $cachekey_time, true ) ); 173 200 } 174 201 202 /** 203 * @covers WP_Embed::shortcode 204 */ 175 205 public function test_shortcode_should_get_cached_data_from_post_meta_for_known_post() { 176 206 global $post; 177 207 … … 198 228 $this->assertSame( $expected, $actual_2 ); 199 229 $this->assertSame( $expected, $cached ); 200 230 } 201 231 232 /** 233 * @covers WP_Embed::shortcode 234 */ 202 235 public function test_shortcode_should_get_cached_failure_from_post_meta_for_known_post() { 203 236 global $post; 204 237 … … 233 266 234 267 /** 235 268 * @ticket 34115 269 * 270 * @covers WP_Embed::shortcode 236 271 */ 237 272 public function test_shortcode_should_cache_data_in_custom_post() { 238 273 $url = 'https://example.com/'; … … 259 294 260 295 /** 261 296 * @ticket 34115 297 * 298 * @covers WP_Embed::shortcode 299 * @covers WP_Embed::find_oembed_post_id 262 300 */ 263 301 public function test_shortcode_should_cache_failure_in_custom_post() { 264 302 $url = 'https://example.com/'; … … 287 325 * Test that parsing an embed shortcode should cause oembed_cache to be updated. 288 326 * 289 327 * @ticket 42310 328 * 329 * @covers WP_Embed::shortcode 330 * @covers WP_Embed::find_oembed_post_id 290 331 */ 291 332 public function test_shortcode_should_update_custom_post() { 292 333 add_filter( 'oembed_ttl', '__return_zero' ); … … 316 357 $this->wp_embed->usecache = $previous_usecache; 317 358 remove_filter( 'oembed_ttl', '__return_zero' ); 318 359 } 319 360 361 /** 362 * @covers WP_Embed::shortcode 363 */ 320 364 public function test_shortcode_should_get_url_from_src_attribute() { 321 365 $url = 'http://example.com/embed/foo'; 322 366 $actual = $this->wp_embed->shortcode( array( 'src' => $url ) ); … … 323 367 324 368 $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual ); 325 369 } 326 370 371 /** 372 * @covers WP_Embed::shortcode 373 */ 327 374 public function test_shortcode_should_return_empty_string_for_missing_url() { 328 375 $this->assertEmpty( $this->wp_embed->shortcode( array() ) ); 329 376 } 330 377 378 /** 379 * @covers WP_Embed::shortcode 380 */ 331 381 public function test_shortcode_should_make_link_for_unknown_url() { 332 382 $url = 'http://example.com/embed/foo'; 333 383 $actual = $this->wp_embed->shortcode( array(), $url ); … … 334 384 335 385 $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual ); 336 386 } 337 387 388 /** 389 * @covers WP_Embed::run_shortcode 390 */ 338 391 public function test_run_shortcode_url_only() { 339 392 $url = 'http://example.com/embed/foo'; 340 393 $actual = $this->wp_embed->run_shortcode( '[embed]' . $url . '[/embed]' ); 341 394 $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual ); 342 395 } 343 396 397 /** 398 * @covers WP_Embed::maybe_make_link 399 */ 344 400 public function test_maybe_make_link() { 345 401 $url = 'http://example.com/embed/foo'; 346 402 $actual = $this->wp_embed->maybe_make_link( $url ); … … 347 403 348 404 $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual ); 349 405 } 350 406 407 /** 408 * @covers WP_Embed::maybe_make_link 409 */ 351 410 public function test_maybe_make_link_return_false_on_fail() { 352 411 $this->wp_embed->return_false_on_fail = true; 353 412 $this->assertFalse( $this->wp_embed->maybe_make_link( 'http://example.com/' ) ); 354 413 } 355 414 415 /** 416 * @covers WP_Embed::maybe_make_link 417 */ 356 418 public function test_maybe_make_link_do_not_link_if_unknown() { 357 419 $url = 'http://example.com/'; 358 420 -
oembed/wpOembed.php
27 27 // Return false to prevent HTTP requests during tests. 28 28 return $result ? $result : false; 29 29 } 30 30 31 /** 32 * @covers WP_oEmbed::get_html 33 */ 31 34 public function test_wp_filter_pre_oembed_result_prevents_http_request_for_internal_permalinks() { 32 35 $post_id = self::factory()->post->create(); 33 36 $permalink = get_permalink( $post_id ); … … 39 42 $this->assertNotFalse( $this->pre_oembed_result_filtered ); 40 43 $this->assertSame( $this->pre_oembed_result_filtered, $actual ); 41 44 } 42 45 46 /** 47 * @covers WP_oEmbed::get_html 48 */ 43 49 public function test_wp_filter_pre_oembed_result_prevents_http_request_when_viewing_the_post() { 44 50 $post_id = self::factory()->post->create(); 45 51 $permalink = get_permalink( $post_id ); … … 54 60 $this->assertNotFalse( $this->pre_oembed_result_filtered ); 55 61 $this->assertSame( $this->pre_oembed_result_filtered, $actual ); 56 62 } 57 63 64 /** 65 * @covers WP_oEmbed::get_html 66 */ 58 67 public function test_wp_filter_pre_oembed_result_non_existent_post() { 59 68 $post_id = self::factory()->post->create(); 60 69 $permalink = get_permalink( $post_id ); … … 74 83 * @ticket 40673 75 84 * @group multisite 76 85 * @group ms-required 86 * 87 * @covers WP_oEmbed::get_html 77 88 */ 78 89 public function test_wp_filter_pre_oembed_result_multisite_root_root() { 79 90 $post_id = self::factory()->post->create(); … … 91 102 * @ticket 40673 92 103 * @group multisite 93 104 * @group ms-required 105 * 106 * @covers WP_oEmbed::get_html 94 107 */ 95 108 public function test_wp_filter_pre_oembed_result_multisite_sub_samesub() { 96 109 $user_id = self::factory()->user->create(); … … 120 133 * @ticket 40673 121 134 * @group multisite 122 135 * @group ms-required 136 * 137 * @covers WP_oEmbed::get_html 123 138 */ 124 139 public function test_wp_filter_pre_oembed_result_multisite_sub_othersub() { 125 140 $user_id = self::factory()->user->create(); … … 157 172 * @ticket 40673 158 173 * @group multisite 159 174 * @group ms-required 175 * 176 * @covers WP_oEmbed::get_html 160 177 */ 161 178 public function test_wp_filter_pre_oembed_result_multisite_sub_main() { 162 179 $post_id = self::factory()->post->create(); … … 184 201 * @ticket 40673 185 202 * @group multisite 186 203 * @group ms-required 204 * 205 * @covers WP_oEmbed::get_html 187 206 */ 188 207 public function test_wp_filter_pre_oembed_result_multisite_preserves_switched_state() { 189 208 $user_id = self::factory()->user->create(); … … 213 232 * @ticket 40673 214 233 * @group multisite 215 234 * @group ms-required 235 * 236 * @covers WP_oEmbed::get_html 216 237 */ 217 238 public function test_wp_filter_pre_oembed_result_multisite_restores_state_if_no_post_is_found() { 218 239 $current_blog_id = get_current_blog_id(); -
option/multisite.php
23 23 $wpdb->suppress_errors( $this->suppress ); 24 24 parent::tearDown(); 25 25 } 26 26 27 /** 28 * @covers ::get_blog_option 29 * @covers ::get_option 30 * @covers ::add_blog_option 31 * @covers ::update_blog_option 32 * @covers ::delete_blog_option 33 */ 27 34 function test_from_same_site() { 28 35 $key = __FUNCTION__ . '_1'; 29 36 $key2 = __FUNCTION__ . '_2'; … … 60 67 $this->assertFalse( get_blog_option( 1, $key2 ) ); 61 68 $this->assertFalse( get_option( $key2 ) ); // Check get_option(). 62 69 } 63 70 71 /** 72 * @covers ::get_blog_option 73 * @covers ::get_option 74 * @covers ::add_blog_option 75 * @covers ::update_blog_option 76 * @covers ::delete_blog_option 77 */ 64 78 function test_from_same_site_with_null_blog_id() { 65 79 $key = __FUNCTION__ . '_1'; 66 80 $key2 = __FUNCTION__ . '_2'; … … 96 110 $this->assertFalse( get_blog_option( null, $key2 ) ); 97 111 $this->assertFalse( get_option( $key2 ) ); // Check get_option(). 98 112 } 99 113 114 /** 115 * @covers ::get_blog_option 116 * @covers ::get_option 117 * @covers ::add_blog_option 118 * @covers ::update_blog_option 119 * @covers ::delete_blog_option 120 */ 100 121 function test_with_another_site() { 101 122 $user_id = self::factory()->user->create(); 102 123 $this->assertInternalType( 'integer', $user_id ); … … 146 167 147 168 /** 148 169 * @group multisite 170 * 171 * @covers ::get_site_option 149 172 */ 150 173 function test_site_notoptions() { 151 174 $network_id = get_current_network_id(); … … 163 186 $notoptions1 = wp_cache_get( $notoptions_key, 'site-options' ); 164 187 $this->assertNotEmpty( $notoptions1 ); 165 188 } 166 189 190 /** 191 * @covers ::users_can_register_signup_filter 192 * @covers ::get_site_option 193 */ 167 194 function test_users_can_register_signup_filter() { 168 195 169 196 $registration = get_site_option( 'registration' ); … … 181 208 182 209 /** 183 210 * @dataProvider data_illegal_names 211 * 212 * @covers ::update_site_option 213 * @covers ::get_site_option 184 214 */ 185 215 function test_sanitize_network_option_illegal_names( $option_value, $sanitized_option_value ) { 186 216 update_site_option( 'illegal_names', $option_value ); … … 200 230 * 201 231 * @param $option_value 202 232 * @param $sanitized_option_value 233 * 234 * @covers ::update_site_option 235 * @covers ::get_site_option 203 236 */ 204 237 function test_sanitize_network_option_limited_email_domains( $option_value, $sanitized_option_value ) { 205 238 update_site_option( 'limited_email_domains', $option_value ); … … 211 244 * 212 245 * @param $option_value 213 246 * @param $sanitized_option_value 247 * 248 * @covers ::update_site_option 249 * @covers ::get_site_option 214 250 */ 215 251 function test_sanitize_network_option_banned_email_domains( $option_value, $sanitized_option_value ) { 216 252 update_site_option( 'banned_email_domains', $option_value ); -
option/networkOption.php
14 14 15 15 /** 16 16 * @group ms-required 17 * 18 * @covers ::add_site_option 17 19 */ 18 20 function test_add_network_option_not_available_on_other_network() { 19 21 $id = self::factory()->network->create(); … … 26 28 27 29 /** 28 30 * @group ms-required 31 * 32 * @covers ::add_network_option 29 33 */ 30 34 function test_add_network_option_available_on_same_network() { 31 35 $id = self::factory()->network->create(); … … 38 42 39 43 /** 40 44 * @group ms-required 45 * 46 * @covers ::delete_site_option 41 47 */ 42 48 function test_delete_network_option_on_only_one_network() { 43 49 $id = self::factory()->network->create(); … … 53 59 /** 54 60 * @ticket 22846 55 61 * @group ms-excluded 62 * 63 * @covers ::add_network_option 56 64 */ 57 65 public function test_add_network_option_is_not_stored_as_autoload_option() { 58 66 $key = __FUNCTION__; … … 67 75 /** 68 76 * @ticket 22846 69 77 * @group ms-excluded 78 * 79 * @covers ::update_network_option 70 80 */ 71 81 public function test_update_network_option_is_not_stored_as_autoload_option() { 72 82 $key = __FUNCTION__; … … 83 93 * 84 94 * @param $network_id 85 95 * @param $expected_response 96 * 97 * @covers ::add_network_option 86 98 */ 87 99 function test_add_network_option_network_id_parameter( $network_id, $expected_response ) { 88 100 $option = rand_str(); … … 96 108 * 97 109 * @param $network_id 98 110 * @param $expected_response 111 * 112 * @covers ::get_network_option 99 113 */ 100 114 function test_get_network_option_network_id_parameter( $network_id, $expected_response ) { 101 115 $option = rand_str(); … … 125 139 /** 126 140 * @ticket 43506 127 141 * @group ms-required 142 * 143 * @covers ::get_network_option 144 * @covers ::wp_cache_get 145 * @covers ::wp_cache_delete 128 146 */ 129 147 public function test_get_network_option_sets_notoptions_if_option_found() { 130 148 $network_id = get_current_network_id(); … … 149 167 /** 150 168 * @ticket 43506 151 169 * @group ms-required 170 * 171 * @covers ::get_network_option 172 * @covers ::wp_cache_get 152 173 */ 153 174 public function test_get_network_option_sets_notoptions_if_option_not_found() { 154 175 $network_id = get_current_network_id(); … … 174 195 * Ensure updating network options containing an object do not result in unneeded database calls. 175 196 * 176 197 * @ticket 44956 198 * 199 * @covers ::update_network_option 177 200 */ 178 201 public function test_update_network_option_array_with_object() { 179 202 $array_w_object = array( -
option/option.php
8 8 function __return_foo() { 9 9 return 'foo'; 10 10 } 11 11 12 /** 13 * @covers ::get_option 14 * @covers ::add_option 15 * @covers ::update_option 16 * @covers ::delete_option 17 */ 12 18 function test_the_basics() { 13 19 $key = 'key1'; 14 20 $key2 = 'key2'; … … 33 39 $this->assertTrue( delete_option( $key2 ) ); 34 40 $this->assertFalse( get_option( $key2 ) ); 35 41 } 36 42 43 /** 44 * @covers ::get_option 45 * @covers ::add_option 46 * @covers ::delete_option 47 */ 37 48 function test_default_filter() { 38 49 $value = 'value'; 39 50 … … 61 72 62 73 /** 63 74 * @ticket 31047 75 * 76 * @covers ::get_option 77 * @covers ::add_option 64 78 */ 65 79 public function test_add_option_should_respect_default_option_filter() { 66 80 add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) ); … … 70 84 $this->assertTrue( $added ); 71 85 $this->assertSame( 'bar', get_option( 'doesnotexist' ) ); 72 86 } 73 87 88 /** 89 * @covers ::get_option 90 * @covers ::add_option 91 * @covers ::delete_option 92 * @covers ::update_option 93 */ 74 94 function test_serialized_data() { 75 95 $key = __FUNCTION__; 76 96 $value = array( … … 89 109 90 110 /** 91 111 * @ticket 23289 112 * 113 * @covers ::get_option 114 * @covers ::add_option 115 * @covers ::delete_option 116 * @covers ::update_option 92 117 */ 93 118 function test_bad_option_names() { 94 119 foreach ( array( '', '0', ' ', 0, false, null ) as $empty ) { … … 101 126 102 127 /** 103 128 * @ticket 23289 129 * 130 * @covers ::delete_option 104 131 */ 105 132 function test_special_option_name_alloption() { 106 133 $this->expectException( 'WPDieException' ); … … 109 136 110 137 /** 111 138 * @ticket 23289 139 * 140 * @covers ::delete_option 112 141 */ 113 142 function test_special_option_name_notoptions() { 114 143 $this->expectException( 'WPDieException' ); … … 131 160 * 132 161 * @ticket 31119 133 162 * @dataProvider data_option_autoloading 163 * 164 * @covers ::add_option 134 165 */ 135 166 function test_option_autoloading( $name, $autoload_value, $expected ) { 136 167 global $wpdb; -
option/registration.php
4 4 * @group option 5 5 */ 6 6 class Tests_Option_Registration extends WP_UnitTestCase { 7 8 /** 9 * @covers ::get_registered_settings 10 */ 7 11 public function test_register() { 8 12 register_setting( 'test_group', 'test_option' ); 9 13 … … 18 22 $this->assertFalse( $args['show_in_rest'] ); 19 23 $this->assertSame( '', $args['description'] ); 20 24 } 21 25 26 /** 27 * @covers ::register_setting 28 * @covers ::apply_filters 29 */ 22 30 public function test_register_with_callback() { 23 31 register_setting( 'test_group', 'test_option', array( $this, 'filter_registered_setting' ) ); 24 32 … … 25 33 $filtered = apply_filters( 'sanitize_option_test_option', 'smart', 'test_option', 'smart' ); 26 34 $this->assertSame( 'S-M-R-T', $filtered ); 27 35 } 28 36 37 /** 38 * @covers ::register_setting 39 * @covers WP_REST_Settings_Controller::sanitize_callback 40 * @covers ::apply_filters 41 */ 29 42 public function test_register_with_array() { 30 43 register_setting( 31 44 'test_group', … … 45 58 46 59 /** 47 60 * @ticket 38176 61 * 62 * @covers ::register_setting 48 63 */ 49 64 public function test_register_with_default() { 50 65 register_setting( … … 60 75 61 76 /** 62 77 * @ticket 38176 78 * 79 * @covers ::register_setting 63 80 */ 64 81 public function test_register_with_default_override() { 65 82 register_setting( … … 77 94 78 95 /** 79 96 * @ticket 38930 97 * 98 * @covers ::register_setting 80 99 */ 81 100 public function test_add_option_with_no_options_cache() { 82 101 register_setting( … … 93 112 94 113 /** 95 114 * @expectedDeprecated register_setting 115 * 116 * @covers ::register_setting 96 117 */ 97 118 public function test_register_deprecated_group_misc() { 98 119 register_setting( 'misc', 'test_option' ); … … 100 121 101 122 /** 102 123 * @expectedDeprecated register_setting 124 * 125 * @covers ::register_setting 103 126 */ 104 127 public function test_register_deprecated_group_privacy() { 105 128 register_setting( 'privacy', 'test_option' ); … … 107 130 108 131 /** 109 132 * @ticket 43207 133 * 134 * @covers ::register_setting 135 * @covers ::unregister_setting 110 136 */ 111 137 public function test_unregister_setting_removes_default() { 112 138 register_setting( -
option/sanitize-option.php
81 81 82 82 /** 83 83 * @dataProvider sanitize_option_provider 84 * 85 * @covers ::sanitize_option 84 86 */ 85 87 public function test_sanitize_option( $option_name, $sanitized, $original ) { 86 88 $this->assertSame( $sanitized, sanitize_option( $option_name, $original ) ); … … 97 99 98 100 /** 99 101 * @dataProvider upload_path_provider 102 * 103 * @covers ::sanitize_option 100 104 */ 101 105 public function test_sanitize_option_upload_path( $provided, $expected ) { 102 106 $this->assertSame( $expected, sanitize_option( 'upload_path', $provided ) ); … … 104 108 105 109 /** 106 110 * @ticket 36122 111 * 112 * @covers ::sanitize_option 107 113 */ 108 114 public function test_emoji_in_blogname_and_description() { 109 115 global $wpdb; … … 122 128 123 129 /** 124 130 * @dataProvider permalink_structure_provider 131 * 132 * @covers ::sanitize_option 133 * @covers ::get_settings_errors 125 134 */ 126 135 public function test_sanitize_permalink_structure( $provided, $expected, $valid ) { 127 136 global $wp_settings_errors; -
option/siteOption.php
7 7 function __return_foo() { 8 8 return 'foo'; 9 9 } 10 10 11 /** 12 * @covers ::get_site_option 13 */ 11 14 function test_get_site_option_returns_false_if_option_does_not_exist() { 12 15 $this->assertFalse( get_site_option( 'doesnotexist' ) ); 13 16 } 14 17 18 /** 19 * @covers ::add_site_option 20 * @covers ::delete_site_option 21 * @covers ::get_site_option 22 */ 15 23 function test_get_site_option_returns_false_after_deletion() { 16 24 $key = __FUNCTION__; 17 25 $value = __FUNCTION__; … … 19 27 delete_site_option( $key ); 20 28 $this->assertFalse( get_site_option( $key ) ); 21 29 } 22 30 31 /** 32 * @covers ::add_site_option 33 * @covers ::get_site_option 34 */ 23 35 function test_get_site_option_returns_value() { 24 36 $key = __FUNCTION__; 25 37 $value = __FUNCTION__; … … 26 38 add_site_option( $key, $value ); 27 39 $this->assertSame( $value, get_site_option( $key ) ); 28 40 } 29 41 42 /** 43 * @covers ::add_site_option 44 * @covers ::update_site_option 45 * @covers ::get_site_option 46 */ 30 47 function test_get_site_option_returns_updated_value() { 31 48 $key = __FUNCTION__; 32 49 $value = __FUNCTION__ . '_1'; … … 35 52 update_site_option( $key, $new_value ); 36 53 $this->assertSame( $new_value, get_site_option( $key ) ); 37 54 } 38 55 56 /** 57 * @covers ::add_filter 58 * @covers ::get_site_option 59 * @covers ::remove_filter 60 */ 39 61 function test_get_site_option_does_not_exist_returns_filtered_default_with_no_default_provided() { 40 62 add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) ); 41 63 $site_option = get_site_option( 'doesnotexist' ); … … 42 64 remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) ); 43 65 $this->assertSame( 'foo', $site_option ); 44 66 } 45 67 68 /** 69 * @covers ::add_filter 70 * @covers ::get_site_option 71 * @covers ::remove_filter 72 */ 46 73 function test_get_site_option_does_not_exist_returns_filtered_default_with_default_provided() { 47 74 add_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) ); 48 75 $site_option = get_site_option( 'doesnotexist', 'bar' ); … … 49 76 remove_filter( 'default_site_option_doesnotexist', array( $this, '__return_foo' ) ); 50 77 $this->assertSame( 'foo', $site_option ); 51 78 } 52 79 80 /** 81 * @covers ::get_site_option 82 */ 53 83 function test_get_site_option_does_not_exist_returns_provided_default() { 54 84 $this->assertSame( 'bar', get_site_option( 'doesnotexist', 'bar' ) ); 55 85 } 56 86 87 /** 88 * @covers ::add_site_option 89 * @covers ::get_site_option 90 */ 57 91 function test_get_site_option_exists_does_not_return_provided_default() { 58 92 $key = __FUNCTION__; 59 93 $value = __FUNCTION__; … … 60 94 add_site_option( $key, $value ); 61 95 $this->assertSame( $value, get_site_option( $key, 'foo' ) ); 62 96 } 63 97 98 /** 99 * @covers ::add_site_option 100 * @covers ::add_filter 101 * @covers ::get_site_option 102 * @covers ::remove_filter 103 */ 64 104 function test_get_site_option_exists_does_not_return_filtered_default() { 65 105 $key = __FUNCTION__; 66 106 $value = __FUNCTION__; … … 70 110 remove_filter( 'default_site_option_' . $key, array( $this, '__return_foo' ) ); 71 111 $this->assertSame( $value, $site_option ); 72 112 } 73 113 114 /** 115 * @covers ::add_site_option 116 */ 74 117 function test_add_site_option_returns_true_for_new_option() { 75 118 $key = __FUNCTION__; 76 119 $value = __FUNCTION__; 77 120 $this->assertTrue( add_site_option( $key, $value ) ); 78 121 } 79 122 123 /** 124 * @covers ::add_site_option 125 */ 80 126 function test_add_site_option_returns_false_for_existing_option() { 81 127 $key = __FUNCTION__; 82 128 $value = __FUNCTION__; … … 83 129 add_site_option( $key, $value ); 84 130 $this->assertFalse( add_site_option( $key, $value ) ); 85 131 } 86 132 133 /** 134 * @covers ::add_site_option 135 * @covers ::update_site_option 136 */ 87 137 function test_update_site_option_returns_false_for_same_value() { 88 138 $key = __FUNCTION__; 89 139 $value = __FUNCTION__; … … 90 140 add_site_option( $key, $value ); 91 141 $this->assertFalse( update_site_option( $key, $value ) ); 92 142 } 93 143 144 /** 145 * @covers ::add_site_option 146 * @covers ::update_site_option 147 */ 94 148 function test_update_site_option_returns_true_for_new_value() { 95 149 $key = 'key'; 96 150 $value = 'value1'; … … 98 152 add_site_option( $key, $value ); 99 153 $this->assertTrue( update_site_option( $key, $new_value ) ); 100 154 } 101 155 156 /** 157 * @covers ::add_site_option 158 * @covers ::delete_site_option 159 */ 102 160 function test_delete_site_option_returns_true_if_option_exists() { 103 161 $key = __FUNCTION__; 104 162 $value = __FUNCTION__; … … 105 163 add_site_option( $key, $value ); 106 164 $this->assertTrue( delete_site_option( $key ) ); 107 165 } 108 166 167 /** 168 * @covers ::add_site_option 169 * @covers ::delete_site_option 170 */ 109 171 function test_delete_site_option_returns_false_if_option_does_not_exist() { 110 172 $key = __FUNCTION__; 111 173 $value = __FUNCTION__; … … 113 175 delete_site_option( $key ); 114 176 $this->assertFalse( delete_site_option( $key ) ); 115 177 } 116 178 179 /** 180 * @covers ::add_site_option 181 * @covers ::get_site_option 182 */ 117 183 function test_site_option_add_and_get_serialized_array() { 118 184 $key = __FUNCTION__; 119 185 $value = array( … … 123 189 add_site_option( $key, $value ); 124 190 $this->assertSame( $value, get_site_option( $key ) ); 125 191 } 126 192 193 /** 194 * @covers ::add_site_option 195 * @covers ::get_site_option 196 */ 127 197 function test_site_option_add_and_get_serialized_object() { 128 198 $key = __FUNCTION__; 129 199 $value = new stdClass(); … … 137 207 * Ensure update_site_option() will add options with false-y values. 138 208 * 139 209 * @ticket 15497 210 * 211 * @covers ::update_site_option 212 * @covers ::flush_cache 213 * @covers ::get_site_option 140 214 */ 141 215 function test_update_adds_falsey_value() { 142 216 $key = __FUNCTION__; … … 152 226 * Ensure get_site_option() doesn't cache the default value for non-existent options. 153 227 * 154 228 * @ticket 18955 229 * 230 * @covers ::get_site_option 155 231 */ 156 232 function test_get_doesnt_cache_default_value() { 157 233 $option = __FUNCTION__; -
option/siteTransient.php
12 12 $this->markTestSkipped( 'Not testable with an external object cache.' ); 13 13 } 14 14 } 15 15 16 /** 17 * @covers ::get_site_transient 18 * @covers ::set_site_transient 19 * @covers ::delete_site_transient 20 */ 16 21 function test_the_basics() { 17 22 $key = 'key1'; 18 23 $value = 'value1'; … … 28 33 $this->assertFalse( get_site_transient( $key ) ); 29 34 $this->assertFalse( delete_site_transient( $key ) ); 30 35 } 31 36 37 /** 38 * @covers ::get_site_transient 39 * @covers ::set_site_transient 40 * @covers ::delete_site_transient 41 */ 32 42 function test_serialized_data() { 33 43 $key = __FUNCTION__; 34 44 $value = array( … … 48 58 /** 49 59 * @ticket 22846 50 60 * @group ms-excluded 61 * 62 * @covers ::set_site_transient 63 * @covers ::wp_load_alloptions 51 64 */ 52 65 public function test_set_site_transient_is_not_stored_as_autoload_option() { 53 66 $key = 'not_autoloaded'; -
option/slashes.php
23 23 24 24 /** 25 25 * Tests the model function that expects un-slashed data 26 * 27 * @covers ::add_option 28 * @covers ::get_option 26 29 */ 27 30 function test_add_option() { 28 31 add_option( 'slash_test_1', $this->slash_1 ); … … 38 41 39 42 /** 40 43 * Tests the model function that expects un-slashed data 44 * 45 * @covers ::add_option 46 * @covers ::update_option 47 * @covers ::get_option 41 48 */ 42 49 function test_update_option() { 43 50 add_option( 'slash_test_5', 'foo' ); -
option/themeMods.php
4 4 * @group option 5 5 */ 6 6 class Tests_Option_Theme_Mods extends WP_UnitTestCase { 7 7 8 /** 9 * @covers ::get_theme_mod 10 */ 8 11 function test_theme_mod_default() { 9 12 $this->assertFalse( get_theme_mod( 'non_existent' ) ); 10 13 } 11 14 15 /** 16 * @covers ::get_theme_mod 17 */ 12 18 function test_theme_mod_defined_default() { 13 19 $this->assertSame( 'default', get_theme_mod( 'non_existent', 'default' ) ); 14 20 } 15 21 22 /** 23 * @covers ::get_theme_mod 24 */ 16 25 function test_theme_mod_set() { 17 26 $expected = 'value'; 18 27 set_theme_mod( 'test_name', $expected ); 19 28 $this->assertSame( $expected, get_theme_mod( 'test_name' ) ); 20 29 } 21 30 31 /** 32 * @covers ::get_theme_mod 33 * @covers ::set_theme_mod 34 */ 22 35 function test_theme_mod_update() { 23 36 set_theme_mod( 'test_update', 'first_value' ); 24 37 $expected = 'updated_value'; … … 25 38 set_theme_mod( 'test_update', $expected ); 26 39 $this->assertSame( $expected, get_theme_mod( 'test_update' ) ); 27 40 } 28 41 42 /** 43 * @covers ::set_theme_mod 44 * @covers ::remove_theme_mod 45 * @covers ::get_theme_mod 46 */ 29 47 function test_theme_mod_remove() { 30 48 set_theme_mod( 'test_remove', 'value' ); 31 49 remove_theme_mod( 'test_remove' ); … … 36 54 * @ticket 34290 37 55 * 38 56 * @dataProvider data_theme_mod_default_value_with_percent_symbols 57 * 58 * @covers ::get_theme_mod 39 59 */ 40 60 function test_theme_mod_default_value_with_percent_symbols( $default, $expected ) { 41 61 $this->assertSame( $expected, get_theme_mod( 'test_name', $default ) ); -
option/transient.php
12 12 $this->markTestSkipped( 'Not testable with an external object cache.' ); 13 13 } 14 14 } 15 15 16 /** 17 * @covers ::get_transient 18 * @covers ::set_transient 19 * @covers ::delete_transient 20 */ 16 21 function test_the_basics() { 17 22 $key = 'key1'; 18 23 $value = 'value1'; … … 28 33 $this->assertFalse( get_transient( $key ) ); 29 34 $this->assertFalse( delete_transient( $key ) ); 30 35 } 31 36 37 /** 38 * @covers ::get_transient 39 * @covers ::set_transient 40 * @covers ::delete_transient 41 */ 32 42 function test_serialized_data() { 33 43 $key = rand_str(); 34 44 $value = array( … … 47 57 48 58 /** 49 59 * @ticket 22807 60 * 61 * @covers ::get_option 62 * @covers ::set_transient 63 * @covers ::update_option 50 64 */ 51 65 function test_transient_data_with_timeout() { 52 66 $key = rand_str(); … … 68 82 69 83 /** 70 84 * @ticket 22807 85 * 86 * @covers ::set_transient 87 * @covers ::get_transient 88 * @covers ::get_option 89 * @covers ::update_option 71 90 */ 72 91 function test_transient_add_timeout() { 73 92 $key = rand_str(); … … 91 110 * If get_option( $transient_timeout ) returns false, don't bother trying to delete the transient. 92 111 * 93 112 * @ticket 30380 113 * 114 * @covers ::set_transient 115 * @covers ::get_transient 94 116 */ 95 117 function test_nonexistent_key_dont_delete_if_false() { 96 118 // Create a bogus a transient. … … 119 141 120 142 /** 121 143 * @ticket 30380 144 * 145 * @covers ::set_transient 146 * @covers ::get_transient 122 147 */ 123 148 function test_nonexistent_key_old_timeout() { 124 149 // Create a transient. -
option/updateOption.php
6 6 class Tests_Option_UpdateOption extends WP_UnitTestCase { 7 7 /** 8 8 * @ticket 31047 9 * 10 * @covers ::add_filter 11 * @covers ::update_option 12 * @covers ::remove_filter 9 13 */ 10 14 public function test_should_respect_default_option_filter_when_option_does_not_yet_exist_in_database() { 11 15 add_filter( 'default_option_doesnotexist', array( $this, '__return_foo' ) ); … … 18 22 19 23 /** 20 24 * @ticket 26394 25 * 26 * @covers ::update_option 27 * @covers ::wp_load_alloptions 28 * @covers ::get_option 21 29 */ 22 30 public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_missing() { 23 31 global $wpdb; … … 38 46 39 47 /** 40 48 * @ticket 26394 49 * 50 * @covers ::update_option 51 * @covers ::wp_load_alloptions 52 * @covers ::get_option 41 53 */ 42 54 public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_yes() { 43 55 global $wpdb; … … 58 70 59 71 /** 60 72 * @ticket 26394 73 * 74 * @covers ::update_option 75 * @covers ::wp_load_alloptions 76 * @covers ::get_option 61 77 */ 62 78 public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_no() { 63 79 global $wpdb; … … 79 95 80 96 /** 81 97 * @ticket 26394 98 * 99 * @covers ::update_option 100 * @covers ::wp_load_alloptions 101 * @covers ::get_option 82 102 */ 83 103 public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_false() { 84 104 global $wpdb; … … 100 120 101 121 /** 102 122 * @ticket 26394 123 * 124 * @covers ::update_option 125 * @covers ::wp_load_alloptions 126 * @covers ::get_option 103 127 */ 104 128 public function test_autoload_should_be_updated_for_existing_option_when_value_is_changed() { 105 129 global $wpdb; … … 121 145 122 146 /** 123 147 * @ticket 26394 148 * 149 * @covers ::update_option 150 * @covers ::wp_load_alloptions 151 * @covers ::get_option 124 152 */ 125 153 public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_unchanged() { 126 154 global $wpdb; … … 143 171 144 172 /** 145 173 * @ticket 26394 174 * 175 * @covers ::update_option 176 * @covers ::wp_load_alloptions 177 * @covers ::get_option 146 178 */ 147 179 public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_changed_but_no_value_of_autoload_is_provided() { 148 180 global $wpdb; … … 167 199 168 200 /** 169 201 * @ticket 38903 202 * 203 * @covers ::add_option 204 * @covers ::get_num_queries 205 * @covers ::update_option 170 206 */ 171 207 public function test_update_option_array_with_object() { 172 208 $array_w_object = array( -
option/userSettings.php
19 19 20 20 parent::tearDown(); 21 21 } 22 22 23 /** 24 * @covers ::get_user_setting 25 * @covers ::get_all_user_settings 26 * @covers ::wp_set_all_user_settings 27 */ 23 28 function test_set_user_setting() { 24 29 $foo = get_user_setting( 'foo' ); 25 30 … … 29 34 30 35 $this->assertSame( 'bar', get_user_setting( 'foo' ) ); 31 36 } 32 37 38 /** 39 * @covers ::get_user_setting 40 * @covers ::wp_set_all_user_settings 41 */ 33 42 function test_set_user_setting_dashes() { 34 43 $foo = get_user_setting( 'foo' ); 35 44 … … 39 48 40 49 $this->assertSame( 'foo-bar-baz', get_user_setting( 'foo' ) ); 41 50 } 42 51 52 /** 53 * @covers ::get_user_setting 54 * @covers ::wp_set_all_user_settings 55 */ 43 56 function test_set_user_setting_strip_asterisks() { 44 57 $foo = get_user_setting( 'foo' ); 45 58 -
option/wpLoadAllOptions.php
11 11 $this->alloptions = null; 12 12 parent::tearDown(); 13 13 } 14 14 15 /** 16 * @covers ::wp_cache_get 17 */ 15 18 function test_if_alloptions_is_cached() { 16 19 $this->assertNotEmpty( wp_cache_get( 'alloptions', 'options' ) ); 17 20 } … … 18 21 19 22 /** 20 23 * @depends test_if_alloptions_is_cached 24 * 25 * @covers ::wp_cache_delete 21 26 */ 22 27 function test_if_cached_alloptions_is_deleted() { 23 28 $this->assertTrue( wp_cache_delete( 'alloptions', 'options' ) ); … … 25 30 26 31 /** 27 32 * @depends test_if_alloptions_is_cached 33 * 34 * @covers ::wp_load_alloptions 28 35 */ 29 36 function test_if_alloptions_are_retrieved_from_cache() { 30 37 global $wpdb; … … 38 45 39 46 /** 40 47 * @depends test_if_cached_alloptions_is_deleted 48 * 49 * @covers ::wp_load_alloptions 41 50 */ 42 51 function test_if_alloptions_are_retrieved_from_database() { 43 52 global $wpdb; … … 55 64 56 65 /** 57 66 * @depends test_if_cached_alloptions_is_deleted 67 * 68 * @covers ::wp_load_alloptions 58 69 */ 59 70 function test_filter_pre_cache_alloptions_is_called() { 60 71 $temp = wp_installing(); … … 81 92 82 93 /** 83 94 * @depends test_if_alloptions_is_cached 95 * 96 * @covers ::wp_load_alloptions 84 97 */ 85 98 function test_filter_pre_cache_alloptions_is_not_called() { 86 99 $temp = wp_installing();