@@ -10,6 +10,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
1010 */
1111 protected $ server ;
1212 protected static $ editor ;
13+ protected static $ administrator ;
1314 protected static $ subscriber ;
1415 const YOUTUBE_VIDEO_ID = 'OQSNhk5ICTI ' ;
1516 const INVALID_OEMBED_URL = 'https://www.notreallyanoembedprovider.com/watch?v=awesome-cat-video ' ;
@@ -22,6 +23,10 @@ public static function wpSetUpBeforeClass( $factory ) {
2223 'role ' => 'editor ' ,
2324 'user_email ' => 'editor@example.com ' ,
2425 ) );
26+ self ::$ administrator = $ factory ->user ->create ( array (
27+ 'role ' => 'administrator ' ,
28+ 'user_email ' => 'administrator@example.com ' ,
29+ ) );
2530 }
2631
2732 public static function wpTearDownAfterClass () {
@@ -477,14 +482,22 @@ public function test_proxy_with_invalid_type() {
477482
478483 public function test_proxy_with_valid_oembed_provider () {
479484 wp_set_current_user ( self ::$ editor );
480-
481485 $ request = new WP_REST_Request ( 'GET ' , '/oembed/1.0/proxy ' );
482486 $ request ->set_param ( 'url ' , 'https://www.youtube.com/watch?v= ' . self ::YOUTUBE_VIDEO_ID );
487+ $ request ->set_param ( '_wpnonce ' , wp_create_nonce ( 'wp_rest ' ) );
483488 $ response = $ this ->server ->dispatch ( $ request );
484489 $ this ->assertEquals ( 200 , $ response ->get_status () );
485490 $ this ->assertEquals ( 1 , $ this ->request_count );
486491
487492 // Subsequent request is cached and so it should not cause a request.
493+ $ this ->server ->dispatch ( $ request );
494+ $ this ->assertEquals ( 1 , $ this ->request_count );
495+
496+ // Rest with another user should also be cached.
497+ wp_set_current_user ( self ::$ administrator );
498+ $ request = new WP_REST_Request ( 'GET ' , '/oembed/1.0/proxy ' );
499+ $ request ->set_param ( 'url ' , 'https://www.youtube.com/watch?v= ' . self ::YOUTUBE_VIDEO_ID );
500+ $ request ->set_param ( '_wpnonce ' , wp_create_nonce ( 'wp_rest ' ) );
488501 $ response = $ this ->server ->dispatch ( $ request );
489502 $ this ->assertEquals ( 1 , $ this ->request_count );
490503
0 commit comments