Make WordPress Core


Ignore:
Timestamp:
09/06/2022 10:09:49 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use the factory method instead of the property.

This replaces all references to the WP_UnitTestCase_Base::$factory property with static function calls to the WP_UnitTestCase_Base::factory() method.

This is a consistency improvement for the test suite.

Follow up to [35225], [35242], [49603], [54087], [54088].

Props jrf.
See #55652.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php

    r54058 r54090  
    5252        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    5353        // Single.
    54         $page_id  = $this->factory->post->create( array( 'post_type' => 'page' ) );
     54        $page_id  = self::factory()->post->create( array( 'post_type' => 'page' ) );
    5555        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages/' . $page_id );
    5656        $response = rest_get_server()->dispatch( $request );
     
    9595
    9696    public function test_get_items() {
    97         $id1      = $this->factory->post->create(
    98             array(
    99                 'post_status' => 'publish',
    100                 'post_type'   => 'page',
    101             )
    102         );
    103         $id2      = $this->factory->post->create(
     97        $id1      = self::factory()->post->create(
     98            array(
     99                'post_status' => 'publish',
     100                'post_type'   => 'page',
     101            )
     102        );
     103        $id2      = self::factory()->post->create(
    104104            array(
    105105                'post_status' => 'draft',
     
    115115
    116116    public function test_get_items_parent_query() {
    117         $id1 = $this->factory->post->create(
    118             array(
    119                 'post_status' => 'publish',
    120                 'post_type'   => 'page',
    121             )
    122         );
    123         $id2 = $this->factory->post->create(
     117        $id1 = self::factory()->post->create(
     118            array(
     119                'post_status' => 'publish',
     120                'post_type'   => 'page',
     121            )
     122        );
     123        $id2 = self::factory()->post->create(
    124124            array(
    125125                'post_status' => 'publish',
     
    149149
    150150    public function test_get_items_parents_query() {
    151         $id1 = $this->factory->post->create(
    152             array(
    153                 'post_status' => 'publish',
    154                 'post_type'   => 'page',
    155             )
    156         );
    157         $id2 = $this->factory->post->create(
     151        $id1 = self::factory()->post->create(
     152            array(
     153                'post_status' => 'publish',
     154                'post_type'   => 'page',
     155            )
     156        );
     157        $id2 = self::factory()->post->create(
    158158            array(
    159159                'post_status' => 'publish',
     
    162162            )
    163163        );
    164         $id3 = $this->factory->post->create(
    165             array(
    166                 'post_status' => 'publish',
    167                 'post_type'   => 'page',
    168             )
    169         );
    170         $id4 = $this->factory->post->create(
     164        $id3 = self::factory()->post->create(
     165            array(
     166                'post_status' => 'publish',
     167                'post_type'   => 'page',
     168            )
     169        );
     170        $id4 = self::factory()->post->create(
    171171            array(
    172172                'post_status' => 'publish',
     
    191191
    192192    public function test_get_items_parent_exclude_query() {
    193         $id1 = $this->factory->post->create(
    194             array(
    195                 'post_status' => 'publish',
    196                 'post_type'   => 'page',
    197             )
    198         );
    199         $this->factory->post->create(
     193        $id1 = self::factory()->post->create(
     194            array(
     195                'post_status' => 'publish',
     196                'post_type'   => 'page',
     197            )
     198        );
     199        self::factory()->post->create(
    200200            array(
    201201                'post_status' => 'publish',
     
    225225
    226226    public function test_get_items_menu_order_query() {
    227         $id1 = $this->factory->post->create(
    228             array(
    229                 'post_status' => 'publish',
    230                 'post_type'   => 'page',
    231             )
    232         );
    233         $id2 = $this->factory->post->create(
     227        $id1 = self::factory()->post->create(
     228            array(
     229                'post_status' => 'publish',
     230                'post_type'   => 'page',
     231            )
     232        );
     233        $id2 = self::factory()->post->create(
    234234            array(
    235235                'post_status' => 'publish',
     
    238238            )
    239239        );
    240         $id3 = $this->factory->post->create(
     240        $id3 = self::factory()->post->create(
    241241            array(
    242242                'post_status' => 'publish',
     
    245245            )
    246246        );
    247         $id4 = $this->factory->post->create(
     247        $id4 = self::factory()->post->create(
    248248            array(
    249249                'post_status' => 'publish',
     
    303303        // Private query vars inaccessible to unauthorized users.
    304304        wp_set_current_user( 0 );
    305         $page_id  = $this->factory->post->create(
    306             array(
    307                 'post_status' => 'publish',
    308                 'post_type'   => 'page',
    309             )
    310         );
    311         $draft_id = $this->factory->post->create(
     305        $page_id  = self::factory()->post->create(
     306            array(
     307                'post_status' => 'publish',
     308                'post_type'   => 'page',
     309            )
     310        );
     311        $draft_id = self::factory()->post->create(
    312312            array(
    313313                'post_status' => 'draft',
     
    337337
    338338    public function test_get_items_valid_date() {
    339         $post1   = $this->factory->post->create(
     339        $post1   = self::factory()->post->create(
    340340            array(
    341341                'post_date' => '2016-01-15T00:00:00Z',
     
    343343            )
    344344        );
    345         $post2   = $this->factory->post->create(
     345        $post2   = self::factory()->post->create(
    346346            array(
    347347                'post_date' => '2016-01-16T00:00:00Z',
     
    349349            )
    350350        );
    351         $post3   = $this->factory->post->create(
     351        $post3   = self::factory()->post->create(
    352352            array(
    353353                'post_date' => '2016-01-17T00:00:00Z',
     
    379379     */
    380380    public function test_get_items_valid_modified_date() {
    381         $post1 = $this->factory->post->create(
     381        $post1 = self::factory()->post->create(
    382382            array(
    383383                'post_date' => '2016-01-01 00:00:00',
     
    385385            )
    386386        );
    387         $post2 = $this->factory->post->create(
     387        $post2 = self::factory()->post->create(
    388388            array(
    389389                'post_date' => '2016-01-02 00:00:00',
     
    391391            )
    392392        );
    393         $post3 = $this->factory->post->create(
     393        $post3 = self::factory()->post->create(
    394394            array(
    395395                'post_date' => '2016-01-03 00:00:00',
     
    417417
    418418    public function test_get_item_invalid_post_type() {
    419         $post_id  = $this->factory->post->create();
     419        $post_id  = self::factory()->post->create();
    420420        $request  = new WP_REST_Request( 'GET', '/wp/v2/pages/' . $post_id );
    421421        $response = rest_get_server()->dispatch( $request );
     
    449449
    450450    public function test_create_page_with_parent() {
    451         $page_id = $this->factory->post->create(
     451        $page_id = self::factory()->post->create(
    452452            array(
    453453                'type' => 'page',
     
    499499
    500500    public function test_delete_item() {
    501         $page_id = $this->factory->post->create(
     501        $page_id = self::factory()->post->create(
    502502            array(
    503503                'post_type'  => 'page',
     
    526526    public function test_prepare_item_limit_fields() {
    527527        wp_set_current_user( self::$editor_id );
    528         $page_id  = $this->factory->post->create(
     528        $page_id  = self::factory()->post->create(
    529529            array(
    530530                'post_status' => 'publish',
     
    548548
    549549    public function test_get_pages_params() {
    550         $this->factory->post->create_many(
     550        self::factory()->post->create_many(
    551551            8,
    552552            array(
     
    579579    public function test_update_page_menu_order() {
    580580
    581         $page_id = $this->factory->post->create(
     581        $page_id = self::factory()->post->create(
    582582            array(
    583583                'post_type' => 'page',
     
    602602    public function test_update_page_menu_order_to_zero() {
    603603
    604         $page_id = $this->factory->post->create(
     604        $page_id = self::factory()->post->create(
    605605            array(
    606606                'post_type'  => 'page',
     
    625625
    626626    public function test_update_page_parent_non_zero() {
    627         $page_id1 = $this->factory->post->create(
    628             array(
    629                 'post_type' => 'page',
    630             )
    631         );
    632         $page_id2 = $this->factory->post->create(
     627        $page_id1 = self::factory()->post->create(
     628            array(
     629                'post_type' => 'page',
     630            )
     631        );
     632        $page_id2 = self::factory()->post->create(
    633633            array(
    634634                'post_type' => 'page',
     
    648648
    649649    public function test_update_page_parent_zero() {
    650         $page_id1 = $this->factory->post->create(
    651             array(
    652                 'post_type' => 'page',
    653             )
    654         );
    655         $page_id2 = $this->factory->post->create(
     650        $page_id1 = self::factory()->post->create(
     651            array(
     652                'post_type' => 'page',
     653            )
     654        );
     655        $page_id2 = self::factory()->post->create(
    656656            array(
    657657                'post_type'   => 'page',
     
    672672
    673673    public function test_get_page_with_password() {
    674         $page_id = $this->factory->post->create(
     674        $page_id = self::factory()->post->create(
    675675            array(
    676676                'post_type'     => 'page',
     
    690690
    691691    public function test_get_page_with_password_using_password() {
    692         $page_id = $this->factory->post->create(
     692        $page_id = self::factory()->post->create(
    693693            array(
    694694                'post_type'     => 'page',
     
    712712
    713713    public function test_get_page_with_password_using_incorrect_password() {
    714         $page_id = $this->factory->post->create(
     714        $page_id = self::factory()->post->create(
    715715            array(
    716716                'post_type'     => 'page',
     
    728728
    729729    public function test_get_page_with_password_without_permission() {
    730         $page_id  = $this->factory->post->create(
     730        $page_id  = self::factory()->post->create(
    731731            array(
    732732                'post_type'     => 'page',
Note: See TracChangeset for help on using the changeset viewer.