Make WordPress Core


Ignore:
Timestamp:
10/17/2015 06:02:16 PM (11 years ago)
Author:
wonderboymusic
Message:

Unit Tests: after [35225], make factory a method/getter on WP_UnitTestCase and add magic methods for BC for every plugin that is extending WP_UnitTestCase and accessing the $factory instance prop.

Props nerrad, wonderboymusic.
See #30017, #33968.

File:
1 edited

Legend:

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

    r35225 r35242  
    4040
    4141        public function test_id() {
    42                 $p = self::$factory->post->create_and_get();
     42                $p = self::factory()->post->create_and_get();
    4343                setup_postdata( $p );
    4444
    … …  
    5151         */
    5252        public function test_setup_by_id() {
    53                 $p = self::$factory->post->create_and_get();
     53                $p = self::factory()->post->create_and_get();
    5454                setup_postdata( $p->ID );
    5555
    … …  
    7373         */
    7474        public function test_setup_by_postish_object() {
    75                 $p = self::$factory->post->create();
     75                $p = self::factory()->post->create();
    7676
    7777                $post = new stdClass();
    … …  
    8383
    8484        public function test_authordata() {
    85                 $u = self::$factory->user->create_and_get();
    86                 $p = self::$factory->post->create_and_get( array(
     85                $u = self::factory()->user->create_and_get();
     86                $p = self::factory()->post->create_and_get( array(
    8787                        'post_author' => $u->ID,
    8888                ) );
    … …  
    9494
    9595        public function test_currentday() {
    96                 $p = self::$factory->post->create_and_get( array(
     96                $p = self::factory()->post->create_and_get( array(
    9797                        'post_date' => '1980-09-09 06:30:00',
    9898                ) );
    … …  
    103103
    104104        public function test_currentmonth() {
    105                 $p = self::$factory->post->create_and_get( array(
     105                $p = self::factory()->post->create_and_get( array(
    106106                        'post_date' => '1980-09-09 06:30:00',
    107107                ) );
    … …  
    112112
    113113        public function test_secondary_query_post_vars() {
    114                 $users = self::$factory->user->create_many( 2 );
    115 
    116                 $post1 = self::$factory->post->create_and_get( array(
     114                $users = self::factory()->user->create_many( 2 );
     115
     116                $post1 = self::factory()->post->create_and_get( array(
    117117                        'post_author' => $users[0],
    118118                        'post_date' => '2012-02-02 02:00:00',
    119119                ) );
    120120
    121                 $post2 = self::$factory->post->create_and_get( array(
     121                $post2 = self::factory()->post->create_and_get( array(
    122122                        'post_author' => $users[1],
    123123                        'post_date' => '2013-03-03 03:00:00',
    … …  
    158158
    159159        public function test_single_page() {
    160                 $post = self::$factory->post->create_and_get( array(
     160                $post = self::factory()->post->create_and_get( array(
    161161                        'post_content' => 'Page 0',
    162162                ) );
    … …  
    169169
    170170        public function test_multi_page() {
    171                 $post = self::$factory->post->create_and_get( array(
     171                $post = self::factory()->post->create_and_get( array(
    172172                        'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
    173173                ) );
    … …  
    183183         */
    184184        public function test_nextpage_at_start_of_content() {
    185                 $post = self::$factory->post->create_and_get( array(
     185                $post = self::factory()->post->create_and_get( array(
    186186                        'post_content' => '<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
    187187                ) );
    … …  
    194194
    195195        public function test_trim_nextpage_linebreaks() {
    196                 $post = self::$factory->post->create_and_get( array(
     196                $post = self::factory()->post->create_and_get( array(
    197197                        'post_content' => "Page 0\n<!--nextpage-->\nPage 1\nhas a line break\n<!--nextpage-->Page 2<!--nextpage-->\n\nPage 3",
    198198                ) );
    … …  
    206206         */
    207207        public function test_secondary_query_nextpage() {
    208                 $post1 = self::$factory->post->create( array(
     208                $post1 = self::factory()->post->create( array(
    209209                        'post_content' => 'Post 1 Page 1<!--nextpage-->Post 1 Page 2',
    210210                ) );
    211                 $post2 = self::$factory->post->create( array(
     211                $post2 = self::factory()->post->create( array(
    212212                        'post_content' => 'Post 2 Page 1<!--nextpage-->Post 2 Page 2',
    213213                ) );
    … …  
    238238
    239239        public function test_page_from_wp_query() {
    240                 $page = self::$factory->post->create_and_get( array(
     240                $page = self::factory()->post->create_and_get( array(
    241241                        'post_type' => 'page',
    242242                ) );
    … …  
    251251
    252252        public function test_page_when_on_page() {
    253                 $page = self::$factory->post->create_and_get( array(
     253                $page = self::factory()->post->create_and_get( array(
    254254                        'post_type' => 'page',
    255255                ) );
    … …  
    264264         */
    265265        public function test_secondary_query_page() {
    266                 $post = self::$factory->post->create_and_get();
     266                $post = self::factory()->post->create_and_get();
    267267                $this->go_to( '/?page=3' );
    268268                setup_postdata( $post );
    … …  
    272272
    273273                // Secondary loop.
    274                 $posts = self::$factory->post->create_many( 5 );
     274                $posts = self::factory()->post->create_many( 5 );
    275275                $q = new WP_Query( array(
    276276                        'page' => 4,
    … …  
    295295         */
    296296        public function test_more_when_on_setup_post() {
    297                 $post = self::$factory->post->create_and_get();
     297                $post = self::factory()->post->create_and_get();
    298298                $this->go_to( get_permalink( $post ) );
    299299                setup_postdata( $post );
    … …  
    308308         */
    309309        public function test_more_when_on_single() {
    310                 $post1 = self::$factory->post->create_and_get();
    311                 $post2 = self::$factory->post->create_and_get();
     310                $post1 = self::factory()->post->create_and_get();
     311                $post2 = self::factory()->post->create_and_get();
    312312                $this->go_to( get_permalink( $post1 ) );
    313313                setup_postdata( $post2 );
    … …  
    322322         */
    323323        public function test_more_when_on_page() {
    324                 $post = self::$factory->post->create_and_get();
    325                 $page = self::$factory->post->create_and_get( array(
     324                $post = self::factory()->post->create_and_get();
     325                $page = self::factory()->post->create_and_get( array(
    326326                        'post_type' => 'page',
    327327                ) );
    … …  
    336336         */
    337337        public function test_more_when_on_feed() {
    338                 $post = self::$factory->post->create_and_get();
     338                $post = self::factory()->post->create_and_get();
    339339                $this->go_to( '/?feed=rss' );
    340340                setup_postdata( $post );
    … …  
    348348         */
    349349        public function test_secondary_query_more() {
    350                 $post = self::$factory->post->create_and_get();
     350                $post = self::factory()->post->create_and_get();
    351351                $this->go_to( get_permalink( $post ) );
    352352                setup_postdata( $post );
    … …  
    380380         */
    381381        function test_setup_postdata_loop() {
    382                 $post_id = self::$factory->post->create( array( 'post_content' => 'global post' ) );
     382                $post_id = self::factory()->post->create( array( 'post_content' => 'global post' ) );
    383383                $GLOBALS['wp_query']->post = $GLOBALS['post'] = get_post( $post_id );
    384384
    385                 $ids = self::$factory->post->create_many(5);
     385                $ids = self::factory()->post->create_many(5);
    386386                foreach ( $ids as $id ) {
    387387                        $page = get_post( $id );
Note: See TracChangeset for help on using the changeset viewer.