Changeset 64310
- Timestamp:
- 10/12/2026 11:30:08 AM (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/icons/wpRestIconCollectionsController.php
r64224 r64310 203 203 204 204 /** 205 * Tests that getting a specific collection requires edit_posts capability. 206 * 207 * @ticket 66287 208 * 209 * @covers ::get_item_permissions_check 210 */ 211 public function test_get_item_requires_permissions() { 212 wp_set_current_user( self::$subscriber_id ); 213 214 $request = new WP_REST_Request( 'GET', '/wp/v2/icon-collections/core' ); 215 $response = rest_get_server()->dispatch( $request ); 216 217 $this->assertErrorResponse( 'rest_cannot_view', $response, 403 ); 218 } 219 220 /** 205 221 * @ticket 64847 206 222 * … … 223 239 /** 224 240 * @ticket 64847 241 * @ticket 66287 225 242 * 226 243 * @covers ::prepare_item_for_response … … 230 247 231 248 $request = new WP_REST_Request( 'GET', '/wp/v2/icon-collections' ); 232 $request->set_param( '_fields', 'slug' ); 233 $response = rest_get_server()->dispatch( $request ); 234 $data = $response->get_data(); 235 236 $this->assertSame( 200, $response->get_status() ); 249 $request->set_param( '_fields', 'slug,label' ); 250 $response = rest_get_server()->dispatch( $request ); 251 $data = $response->get_data(); 252 253 $this->assertSame( 200, $response->get_status() ); 254 $this->assertIsArray( $data ); 255 $this->assertNotEmpty( $data ); 237 256 238 257 foreach ( $data as $collection ) { 239 258 $this->assertArrayHasKey( 'slug', $collection ); 240 $this->assertArrayNotHasKey( 'label', $collection ); 259 $this->assertArrayHasKey( 'label', $collection ); 260 $this->assertArrayNotHasKey( 'description', $collection ); 241 261 } 242 262 } 243 263 244 264 /** 245 * @ticket 64847 265 * Tests that the _fields parameter filters single collection response fields. 266 * 267 * @ticket 66287 268 * 269 * @covers ::prepare_item_for_response 270 */ 271 public function test_get_item_fields_parameter() { 272 wp_set_current_user( self::$editor_id ); 273 274 $request = new WP_REST_Request( 'GET', '/wp/v2/icon-collections/core' ); 275 $request->set_param( '_fields', 'label' ); 276 $response = rest_get_server()->dispatch( $request ); 277 $data = $response->get_data(); 278 279 $this->assertSame( 200, $response->get_status() ); 280 $this->assertArrayHasKey( 'label', $data ); 281 $this->assertArrayNotHasKey( 'slug', $data ); 282 $this->assertArrayNotHasKey( 'description', $data ); 283 } 284 285 /** 286 * @ticket 64847 287 * @ticket 66287 246 288 * 247 289 * @covers ::get_item_schema … … 251 293 $response = rest_get_server()->dispatch( $request ); 252 294 $data = $response->get_data(); 253 254 $properties = $data['schema']['properties']; 295 $schema = $data['schema']; 296 297 $this->assertSame( 'icon-collection', $schema['title'] ); 298 $this->assertSame( 'object', $schema['type'] ); 299 300 $properties = $schema['properties']; 255 301 $this->assertCount( 3, $properties ); 256 302 $this->assertArrayHasKey( 'slug', $properties ); 257 303 $this->assertArrayHasKey( 'label', $properties ); 258 304 $this->assertArrayHasKey( 'description', $properties ); 305 306 $this->assertTrue( $properties['slug']['readonly'] ); 307 $this->assertTrue( $properties['label']['readonly'] ); 308 $this->assertTrue( $properties['description']['readonly'] ); 259 309 } 260 310 … … 307 357 * 308 358 * @ticket 66087 359 * @ticket 66287 309 360 * 310 361 * @covers ::get_items … … 323 374 $this->assertContains( 'rest-visibility-public', $slugs ); 324 375 $this->assertNotContains( 'rest-visibility-private', $slugs ); 376 $this->assertNotContains( 'core-admin', $slugs ); 325 377 } 326 378 … … 329 381 * 330 382 * @ticket 66087 383 * @ticket 66287 384 * 385 * @dataProvider data_non_public_collections 331 386 * 332 387 * @covers ::get_item 333 388 * @covers ::get_icon_collection 334 */ 335 public function test_get_item_returns_404_for_non_public_collection() { 389 * 390 * @param string $slug Icon collection slug. 391 */ 392 public function test_get_item_returns_404_for_non_public_collection( $slug ) { 336 393 $this->register_visibility_collections(); 337 394 338 395 wp_set_current_user( self::$editor_id ); 339 396 340 $request = new WP_REST_Request( 'GET', '/wp/v2/icon-collections/ rest-visibility-private');397 $request = new WP_REST_Request( 'GET', '/wp/v2/icon-collections/' . $slug ); 341 398 $response = rest_get_server()->dispatch( $request ); 342 399 343 400 $this->assertErrorResponse( 'rest_icon_collection_not_found', $response, 404 ); 401 } 402 403 /** 404 * Data provider of non-public collection slugs. 405 * 406 * @return array[] 407 */ 408 public function data_non_public_collections() { 409 return array( 410 'custom non-public collection' => array( 'rest-visibility-private' ), 411 'built-in core-admin' => array( 'core-admin' ), 412 ); 344 413 } 345 414 … … 377 446 $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 378 447 } 448 449 /** 450 * Tests that collection query parameters include context with view default. 451 * 452 * @ticket 66287 453 * 454 * @covers ::get_collection_params 455 */ 456 public function test_get_collection_params() { 457 $controller = new WP_REST_Icon_Collections_Controller(); 458 $params = $controller->get_collection_params(); 459 460 $this->assertArrayHasKey( 'context', $params ); 461 $this->assertSame( 'view', $params['context']['default'] ); 462 } 379 463 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)