- Timestamp:
- 09/20/2022 09:19:10 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php
r54058 r54269 57 57 * @covers WP_REST_Templates_Controller::register_routes 58 58 * @ticket 54596 59 * @ticket 56467 59 60 */ 60 61 public function test_register_routes() { … … 69 70 $routes, 70 71 'Single template based on the given ID route does not exist' 72 ); 73 $this->assertArrayHasKey( 74 '/wp/v2/templates/lookup', 75 $routes, 76 'Get template fallback content route does not exist' 71 77 ); 72 78 } … … 679 685 } 680 686 687 /** 688 * @dataProvider data_create_item_with_is_wp_suggestion 689 * @ticket 56467 690 * @covers WP_REST_Templates_Controller::create_item 691 * 692 * @param array $body_params Data set to test. 693 * @param array $expected Expected results. 694 */ 695 public function test_create_item_with_is_wp_suggestion( array $body_params, array $expected ) { 696 // Set up the user. 697 $body_params['author'] = self::$admin_id; 698 $expected['author'] = self::$admin_id; 699 wp_set_current_user( self::$admin_id ); 700 701 $request = new WP_REST_Request( 'POST', '/wp/v2/templates' ); 702 $request->set_body_params( $body_params ); 703 $response = rest_get_server()->dispatch( $request ); 704 $data = $response->get_data(); 705 unset( $data['_links'] ); 706 unset( $data['wp_id'] ); 707 708 $this->assertSame( $expected, $data ); 709 } 710 711 /** 712 * Data provider. 713 * 714 * @return array 715 */ 716 public function data_create_item_with_is_wp_suggestion() { 717 $expected = array( 718 'id' => 'default//page-rigas', 719 'theme' => 'default', 720 'content' => array( 721 'raw' => 'Content', 722 ), 723 'slug' => 'page-rigas', 724 'source' => 'custom', 725 'origin' => null, 726 'type' => 'wp_template', 727 'description' => 'Just a description', 728 'title' => array( 729 'raw' => 'My Template', 730 'rendered' => 'My Template', 731 ), 732 'status' => 'publish', 733 'has_theme_file' => false, 734 'is_custom' => false, 735 'author' => null, 736 ); 737 738 return array( 739 'is_wp_suggestion: true' => array( 740 'body_params' => array( 741 'slug' => 'page-rigas', 742 'description' => 'Just a description', 743 'title' => 'My Template', 744 'content' => 'Content', 745 'is_wp_suggestion' => true, 746 'author' => null, 747 ), 748 'expected' => $expected, 749 ), 750 'is_wp_suggestion: false' => array( 751 'body_params' => array( 752 'slug' => 'page-hi', 753 'description' => 'Just a description', 754 'title' => 'My Template', 755 'content' => 'Content', 756 'is_wp_suggestion' => false, 757 'author' => null, 758 ), 759 'expected' => array_merge( 760 $expected, 761 array( 762 'id' => 'default//page-hi', 763 'slug' => 'page-hi', 764 'is_custom' => true, 765 ) 766 ), 767 ), 768 ); 769 } 770 771 /** 772 * @ticket 56467 773 * @covers WP_REST_Templates_Controller::get_template_fallback 774 */ 775 public function test_get_template_fallback() { 776 wp_set_current_user( self::$admin_id ); 777 switch_theme( 'block-theme' ); 778 $request = new WP_REST_Request( 'GET', '/wp/v2/templates/lookup' ); 779 // Should fallback to `index.html`. 780 $request->set_param( 'slug', 'tag-status' ); 781 $request->set_param( 'is_custom', false ); 782 $request->set_param( 'template_prefix', 'tag' ); 783 $response = rest_get_server()->dispatch( $request ); 784 $this->assertSame( 'index', $response->get_data()['slug'], 'Should fallback to `index.html`.' ); 785 // Should fallback to `page.html`. 786 $request->set_param( 'slug', 'page-hello' ); 787 $request->set_param( 'is_custom', false ); 788 $request->set_param( 'template_prefix', 'page' ); 789 $response = rest_get_server()->dispatch( $request ); 790 $this->assertSame( 'page', $response->get_data()['slug'], 'Should fallback to `page.html`.' ); 791 } 681 792 }
Note: See TracChangeset
for help on using the changeset viewer.