Skip to content

Commit

Permalink
Improves existing site icon tests.
Browse files Browse the repository at this point in the history
* Adds assertions for the other site_* fields.
* Adds unhappy path test for when no site icon is set.
* Adds assertion for "site_icon_url" value.
* Adds covers annotation.
* Renames test method to include the method name "get_index".
  • Loading branch information
hellofromtonya committed Nov 29, 2023
1 parent 0cf81db commit a3ffe5c
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/phpunit/tests/rest-api/rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,17 +1187,41 @@ public function test_index_includes_link_to_active_theme_if_authenticated() {

/**
* @ticket 52321
* @ticket 59935
*
* @covers WP_REST_Server::get_index
*/
public function test_index_includes_site_icon() {
$server = new WP_REST_Server();
public function test_get_index_should_include_site_icon() {
update_option( 'site_icon', self::$icon_id );

$server = new WP_REST_Server();
$request = new WP_REST_Request( 'GET', '/' );
$index = $server->dispatch( $request );
$data = $index->get_data();

$this->assertArrayHasKey( 'site_icon', $data );
$this->assertSame( self::$icon_id, $data['site_icon'] );
$this->assertArrayHasKey( 'site_logo', $data, 'The "site_logo" field is missing in the response.' );
$this->assertArrayHasKey( 'site_icon', $data, 'The "site_icon" field is missing in the response.' );
$this->assertArrayHasKey( 'site_icon_url', $data, 'The "site_icon_url" field is missing in the response.' );
$this->assertSame( self::$icon_id, $data['site_icon'], 'The response "site_icon" ID does not match.' );
$this->assertStringContainsString( 'test-image-large', $data['site_icon_url'], 'The "site_icon_url" should contain the expected image.' );
}
/**
* @ticket 52321
* @ticket 59935
*
* @covers WP_REST_Server::get_index
*/
public function test_get_index_should_not_include_site_icon() {
$server = new WP_REST_Server();
$request = new WP_REST_Request( 'GET', '/' );
$index = $server->dispatch( $request );
$data = $index->get_data();

$this->assertArrayHasKey( 'site_logo', $data, 'The "site_logo" field is missing in the response.' );
$this->assertArrayHasKey( 'site_icon', $data, 'The "site_icon" field is missing in the response.' );
$this->assertArrayHasKey( 'site_icon_url', $data, 'The "site_icon_url" field is missing in the response.' );
$this->assertSame( 0, $data['site_icon'], 'Response "site_icon" should be 0.' );
$this->assertSame( '', $data['site_icon_url'], 'Response "site_icon_url" should be an empty string.' );
}

/**
Expand Down

0 comments on commit a3ffe5c

Please sign in to comment.