Make WordPress Core


Ignore:
Timestamp:
09/12/2015 08:57:06 PM (10 years ago)
Author:
boonebgorges
Message:

Allow setup_postdata() to accept a post ID.

Previously, it accepted only a full post object.

Props sc0ttclark, mordauk, wonderboymusic.
Fixes #30970.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/setupPostdata.php

    r30976 r34089  
    4545        $this->assertNotEmpty( $p->ID );
    4646        $this->assertSame( $p->ID, $GLOBALS['id'] );
     47    }
     48
     49    /**
     50     * @ticket 30970
     51     */
     52    public function test_setup_by_id() {
     53        $p = $this->factory->post->create_and_get();
     54        setup_postdata( $p->ID );
     55
     56        $this->assertSame( $p->ID, $GLOBALS['id'] );
     57    }
     58
     59    /**
     60     * @ticket 30970
     61     */
     62    public function test_setup_by_fake_post() {
     63        $fake = new stdClass;
     64        $fake->ID = 98765;
     65        setup_postdata( $fake->ID );
     66
     67        // Fails because there's no post with this ID.
     68        $this->assertNotSame( $fake->ID, $GLOBALS['id'] );
     69    }
     70
     71    /**
     72     * @ticket 30970
     73     */
     74    public function test_setup_by_postish_object() {
     75        $p = $this->factory->post->create();
     76
     77        $post = new stdClass();
     78        $post->ID = $p;
     79        setup_postdata( $p );
     80
     81        $this->assertSame( $p, $GLOBALS['id'] );
    4782    }
    4883
Note: See TracChangeset for help on using the changeset viewer.