- Timestamp:
- 08/24/2022 01:09:03 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r53813 r53935 26 26 protected $forbidden_cat; 27 27 protected $posts_clauses; 28 29 private $attachments_created = false; 28 30 29 31 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { … … 114 116 add_filter( 'rest_pre_dispatch', array( $this, 'wpSetUpBeforeRequest' ), 10, 3 ); 115 117 add_filter( 'posts_clauses', array( $this, 'save_posts_clauses' ), 10, 2 ); 118 } 119 120 public function tear_down() { 121 if ( true === $this->attachments_created ) { 122 $this->remove_added_uploads(); 123 $this->attachments_created = false; 124 } 125 126 parent::tear_down(); 116 127 } 117 128 … … 2772 2783 public function test_create_update_post_with_featured_media() { 2773 2784 2774 $file 2775 $ this->attachment_id = $this->factory->attachment->create_object(2785 $file = DIR_TESTDATA . '/images/canola.jpg'; 2786 $attachment_id = $this->factory->attachment->create_object( 2776 2787 $file, 2777 2788 0, … … 2782 2793 ); 2783 2794 2795 $this->attachments_created = true; 2796 2784 2797 wp_set_current_user( self::$editor_id ); 2785 2798 … … 2787 2800 $params = $this->set_post_data( 2788 2801 array( 2789 'featured_media' => $ this->attachment_id,2802 'featured_media' => $attachment_id, 2790 2803 ) 2791 2804 ); … … 2794 2807 $data = $response->get_data(); 2795 2808 $new_post = get_post( $data['id'] ); 2796 $this->assertSame( $ this->attachment_id, $data['featured_media'] );2797 $this->assertSame( $ this->attachment_id, (int) get_post_thumbnail_id( $new_post->ID ) );2809 $this->assertSame( $attachment_id, $data['featured_media'] ); 2810 $this->assertSame( $attachment_id, (int) get_post_thumbnail_id( $new_post->ID ) ); 2798 2811 2799 2812 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . $new_post->ID ); … … 5278 5291 } 5279 5292 5280 public function tear_down() {5281 if ( isset( $this->attachment_id ) ) {5282 $this->remove_added_uploads();5283 }5284 5285 parent::tear_down();5286 }5287 5288 5293 /** 5289 5294 * Internal function used to disable an insert query which
Note: See TracChangeset
for help on using the changeset viewer.