- Timestamp:
- 09/20/2024 02:05:50 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php
r58227 r59073 530 530 531 531 /** 532 * Tests that get_item() returns plugin-registered templates. 533 * 534 * @ticket 61804 535 * 536 * @covers WP_REST_Templates_Controller::get_item 537 */ 538 public function test_get_item_from_registry() { 539 wp_set_current_user( self::$admin_id ); 540 541 $template_name = 'test-plugin//test-template'; 542 $args = array( 543 'content' => 'Template content', 544 'title' => 'Test Template', 545 'description' => 'Description of test template', 546 'post_types' => array( 'post', 'page' ), 547 ); 548 549 wp_register_block_template( $template_name, $args ); 550 551 $request = new WP_REST_Request( 'GET', '/wp/v2/templates/test-plugin//test-template' ); 552 $response = rest_get_server()->dispatch( $request ); 553 554 $this->assertNotWPError( $response, "Fetching a registered template shouldn't cause an error." ); 555 556 $data = $response->get_data(); 557 558 $this->assertSame( 'default//test-template', $data['id'], 'Template ID mismatch.' ); 559 $this->assertSame( 'default', $data['theme'], 'Template theme mismatch.' ); 560 $this->assertSame( 'Template content', $data['content']['raw'], 'Template content mismatch.' ); 561 $this->assertSame( 'test-template', $data['slug'], 'Template slug mismatch.' ); 562 $this->assertSame( 'plugin', $data['source'], "Template source should be 'plugin'." ); 563 $this->assertSame( 'plugin', $data['origin'], "Template origin should be 'plugin'." ); 564 $this->assertSame( 'test-plugin', $data['author_text'], 'Template author text mismatch.' ); 565 $this->assertSame( 'Description of test template', $data['description'], 'Template description mismatch.' ); 566 $this->assertSame( 'Test Template', $data['title']['rendered'], 'Template title mismatch.' ); 567 $this->assertSame( 'test-plugin', $data['plugin'], 'Plugin name mismatch.' ); 568 569 wp_unregister_block_template( $template_name ); 570 571 $request = new WP_REST_Request( 'GET', '/wp/v2/templates/test-plugin//test-template' ); 572 $response = rest_get_server()->dispatch( $request ); 573 574 $this->assertNotWPError( $response, "Fetching an unregistered template shouldn't cause an error." ); 575 $this->assertSame( 404, $response->get_status(), 'Fetching an unregistered template should return 404.' ); 576 } 577 578 /** 532 579 * @ticket 54507 533 580 * @dataProvider data_sanitize_template_id … … 864 911 $data = $response->get_data(); 865 912 $properties = $data['schema']['properties']; 866 $this->assertCount( 1 7, $properties );913 $this->assertCount( 18, $properties ); 867 914 $this->assertArrayHasKey( 'id', $properties ); 868 915 $this->assertArrayHasKey( 'description', $properties ); … … 883 930 $this->assertArrayHasKey( 'author_text', $properties ); 884 931 $this->assertArrayHasKey( 'original_source', $properties ); 932 $this->assertArrayHasKey( 'plugin', $properties ); 885 933 } 886 934
Note: See TracChangeset
for help on using the changeset viewer.