From 2cd907dd632f318615357bae6bfe83b9b7f7a30e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 15 Dec 2021 18:06:15 +0000 Subject: [PATCH] Tests: Add an assertion to test the `WP_REST_Server::add_site_logo_to_index()` method. Additionally: * Move the test for `WP_REST_Server::add_active_theme_link_to_index()` to a more logical place. * Replace `assertEquals()` with `assertSame()` in site icon test to also check the type of the value. * Use a more consistent pattern for the tests. Follow-up to [51241], [52080]. Props ignatggeorgiev, desrosj, SergeyBiryukov. Fixes #53516. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@52381 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/rest-api/rest-server.php | 30 +++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 33e1f70506..6c453c051c 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -1025,14 +1025,28 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertArrayHasKey( 'help', $index->get_links() ); $this->assertArrayNotHasKey( 'wp:active-theme', $index->get_links() ); - // Check site icon. + // Check site logo and icon. + $this->assertArrayHasKey( 'site_logo', $data ); $this->assertArrayHasKey( 'site_icon', $data ); } + /** + * @ticket 50152 + */ + public function test_index_includes_link_to_active_theme_if_authenticated() { + $server = new WP_REST_Server(); + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); + + $request = new WP_REST_Request( 'GET', '/' ); + $index = $server->dispatch( $request ); + + $this->assertArrayHasKey( 'https://api.w.org/active-theme', $index->get_links() ); + } + /** * @ticket 52321 */ - public function test_get_index_with_site_icon() { + public function test_index_includes_site_icon() { $server = new WP_REST_Server(); update_option( 'site_icon', self::$icon_id ); @@ -1041,7 +1055,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $data = $index->get_data(); $this->assertArrayHasKey( 'site_icon', $data ); - $this->assertEquals( self::$icon_id, $data['site_icon'] ); + $this->assertSame( self::$icon_id, $data['site_icon'] ); } public function test_get_namespace_index() { @@ -2079,16 +2093,6 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertSameSetsWithIndex( $expected, $args['param'] ); } - /** - * @ticket 50152 - */ - public function test_index_includes_link_to_active_theme_if_authenticated() { - wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); - - $index = rest_do_request( '/' ); - $this->assertArrayHasKey( 'https://api.w.org/active-theme', $index->get_links() ); - } - /** * @ticket 53056 */