Changeset 61856
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
r61429 r61856 198 198 $themes = array(); 199 199 200 $active_themes = wp_get_themes();201 200 $current_theme = wp_get_theme(); 202 201 $status = $request['status']; 203 202 204 foreach ( $active_themes as $theme ) { 205 $theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive'; 206 if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) { 207 continue; 208 } 209 210 $prepared = $this->prepare_item_for_response( $theme, $request ); 203 if ( array( 'active' ) === $status ) { 204 $prepared = $this->prepare_item_for_response( $current_theme, $request ); 211 205 $themes[] = $this->prepare_response_for_collection( $prepared ); 206 } else { 207 foreach ( wp_get_themes() as $theme ) { 208 $theme_status = ( $this->is_same_theme( $theme, $current_theme ) ) ? 'active' : 'inactive'; 209 if ( is_array( $status ) && ! in_array( $theme_status, $status, true ) ) { 210 continue; 211 } 212 213 $prepared = $this->prepare_item_for_response( $theme, $request ); 214 $themes[] = $this->prepare_response_for_collection( $prepared ); 215 } 212 216 } 213 217 -
trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php
r59965 r61856 164 164 * @ticket 45016 165 165 * @ticket 61021 166 * @ticket 62574 .166 * @ticket 62574 167 167 */ 168 168 public function test_get_items() { 169 wp_set_current_user( self::$admin_id ); 170 $request = new WP_REST_Request( 'GET', self::$themes_route ); 171 172 $response = rest_get_server()->dispatch( $request ); 173 174 $this->assertSame( 200, $response->get_status() ); 175 $data = $response->get_data(); 176 177 $fields = array( 178 '_links', 179 'author', 180 'author_uri', 181 'description', 182 'is_block_theme', 183 'name', 184 'requires_php', 185 'requires_wp', 186 'screenshot', 187 'status', 188 'stylesheet', 189 'stylesheet_uri', 190 'tags', 191 'template', 192 'template_uri', 193 'textdomain', 194 'theme_uri', 195 'version', 196 ); 197 $this->assertIsArray( $data ); 198 $this->assertNotEmpty( $data ); 199 $this->assertSameSets( $fields, array_keys( $data[0] ) ); 200 201 $this->assertContains( 'twentytwenty', wp_list_pluck( $data, 'stylesheet' ) ); 202 $this->assertContains( get_stylesheet(), wp_list_pluck( $data, 'stylesheet' ) ); 203 } 204 205 /** 206 * Test retrieving a collection of active themes. 207 * 208 * @ticket 64719 209 */ 210 public function test_get_items_active() { 211 wp_set_current_user( self::$admin_id ); 212 169 213 $response = self::perform_active_theme_request(); 170 214 … … 197 241 ); 198 242 $this->assertIsArray( $data ); 199 $this->assert NotEmpty($data );243 $this->assertCount( 1, $data ); 200 244 $this->assertSameSets( $fields, array_keys( $data[0] ) ); 245 $this->assertEquals( array( 'rest-api' ), wp_list_pluck( $data, 'stylesheet' ) ); 201 246 } 202 247
Note: See TracChangeset
for help on using the changeset viewer.