Make WordPress Core

Ticket #30970: 30970.diff

File 30970.diff, 2.1 KB (added by wonderboymusic, 11 years ago)
  • src/wp-includes/query.php

     
    46274627         * @global int             $more
    46284628         * @global int             $numpages
    46294629         *
    4630          * @param WP_Post $post Post data.
     4630         * @param WP_Post|stdClass|int $post WP_Post instace or Post ID/object, which will be converted into WP_Post.
    46314631         * @return true True when finished.
    46324632         */
    46334633        public function setup_postdata( $post ) {
    46344634                global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages;
    46354635
     4636                if ( ! ( $post instanceof WP_Post ) ) {
     4637                        $post = get_post( $post );
     4638                }
     4639
    46364640                $id = (int) $post->ID;
    46374641
    46384642                $authordata = get_userdata($post->post_author);
     
    47014705        public function reset_postdata() {
    47024706                if ( ! empty( $this->post ) ) {
    47034707                        $GLOBALS['post'] = $this->post;
    4704                         setup_postdata( $this->post );
     4708                        $this->setup_postdata( $this->post );
    47054709                }
    47064710        }
    47074711}
     
    47724776 *
    47734777 * @global WP_Query $wp_query
    47744778 *
    4775  * @param object $post Post data.
     4779 * @param WP_Post|stdClass|int $post WP_Post instace or Post ID/object, which will be converted into WP_Post.
    47764780 * @return bool True when finished.
    47774781 */
    47784782function setup_postdata( $post ) {
  • tests/phpunit/tests/query/setupPostdata.php

     
    4646                $this->assertSame( $p->ID, $GLOBALS['id'] );
    4747        }
    4848
     49        public function test_setup_by_id() {
     50                $p = $this->factory->post->create_and_get();
     51                setup_postdata( $p->ID );
     52
     53                $this->assertNotEmpty( $p->ID );
     54                $this->assertSame( $p->ID, $GLOBALS['id'] );
     55        }
     56
     57        public function test_fake_post() {
     58
     59                $fake = new stdClass;
     60                $fake->ID = 100;
     61
     62                $this->assertNotSame( $fake->ID, $GLOBALS['id'] );
     63        }
     64
    4965        public function test_authordata() {
    5066                $u = $this->factory->user->create_and_get();
    5167                $p = $this->factory->post->create_and_get( array(