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-categories-controller.php

    r53909 r54090  
    122122        $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    123123        // Single.
    124         $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) );
     124        $category1 = self::factory()->category->create( array( 'name' => 'Season 5' ) );
    125125        $request   = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 );
    126126        $response  = rest_get_server()->dispatch( $request );
     
    173173
    174174    public function test_get_items_hide_empty_arg() {
    175         $post_id   = $this->factory->post->create();
    176         $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) );
    177         $category2 = $this->factory->category->create( array( 'name' => 'The Be Sharps' ) );
     175        $post_id   = self::factory()->post->create();
     176        $category1 = self::factory()->category->create( array( 'name' => 'Season 5' ) );
     177        $category2 = self::factory()->category->create( array( 'name' => 'The Be Sharps' ) );
    178178
    179179        $total_categories = self::$total_categories + 2;
     
    198198
    199199    public function test_get_items_parent_zero_arg() {
    200         $parent1 = $this->factory->category->create( array( 'name' => 'Homer' ) );
    201         $parent2 = $this->factory->category->create( array( 'name' => 'Marge' ) );
    202         $this->factory->category->create(
     200        $parent1 = self::factory()->category->create( array( 'name' => 'Homer' ) );
     201        $parent2 = self::factory()->category->create( array( 'name' => 'Marge' ) );
     202        self::factory()->category->create(
    203203            array(
    204204                'name'   => 'Bart',
     
    206206            )
    207207        );
    208         $this->factory->category->create(
     208        self::factory()->category->create(
    209209            array(
    210210                'name'   => 'Lisa',
     
    230230
    231231    public function test_get_items_parent_zero_arg_string() {
    232         $parent1 = $this->factory->category->create( array( 'name' => 'Homer' ) );
    233         $parent2 = $this->factory->category->create( array( 'name' => 'Marge' ) );
    234         $this->factory->category->create(
     232        $parent1 = self::factory()->category->create( array( 'name' => 'Homer' ) );
     233        $parent2 = self::factory()->category->create( array( 'name' => 'Marge' ) );
     234        self::factory()->category->create(
    235235            array(
    236236                'name'   => 'Bart',
     
    238238            )
    239239        );
    240         $this->factory->category->create(
     240        self::factory()->category->create(
    241241            array(
    242242                'name'   => 'Lisa',
     
    262262
    263263    public function test_get_items_by_parent_non_found() {
    264         $parent1 = $this->factory->category->create( array( 'name' => 'Homer' ) );
     264        $parent1 = self::factory()->category->create( array( 'name' => 'Homer' ) );
    265265
    266266        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     
    285285
    286286    public function test_get_items_include_query() {
    287         $id1 = $this->factory->category->create();
    288         $id2 = $this->factory->category->create();
     287        $id1 = self::factory()->category->create();
     288        $id2 = self::factory()->category->create();
    289289
    290290        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     
    306306
    307307    public function test_get_items_exclude_query() {
    308         $id1 = $this->factory->category->create();
    309         $id2 = $this->factory->category->create();
     308        $id1 = self::factory()->category->create();
     309        $id2 = self::factory()->category->create();
    310310
    311311        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     
    326326
    327327    public function test_get_items_orderby_args() {
    328         $this->factory->category->create( array( 'name' => 'Apple' ) );
    329         $this->factory->category->create( array( 'name' => 'Banana' ) );
     328        self::factory()->category->create( array( 'name' => 'Apple' ) );
     329        self::factory()->category->create( array( 'name' => 'Banana' ) );
    330330
    331331        /*
     
    357357
    358358    public function test_get_items_orderby_id() {
    359         $this->factory->category->create( array( 'name' => 'Cantaloupe' ) );
    360         $this->factory->category->create( array( 'name' => 'Apple' ) );
    361         $this->factory->category->create( array( 'name' => 'Banana' ) );
     359        self::factory()->category->create( array( 'name' => 'Cantaloupe' ) );
     360        self::factory()->category->create( array( 'name' => 'Apple' ) );
     361        self::factory()->category->create( array( 'name' => 'Banana' ) );
    362362
    363363        // Defaults to 'orderby' => 'name', 'order' => 'asc'.
     
    393393
    394394    public function test_get_items_orderby_slugs() {
    395         $this->factory->category->create( array( 'name' => 'Burrito' ) );
    396         $this->factory->category->create( array( 'name' => 'Taco' ) );
    397         $this->factory->category->create( array( 'name' => 'Chalupa' ) );
     395        self::factory()->category->create( array( 'name' => 'Burrito' ) );
     396        self::factory()->category->create( array( 'name' => 'Taco' ) );
     397        self::factory()->category->create( array( 'name' => 'Chalupa' ) );
    398398
    399399        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     
    409409
    410410    protected function post_with_categories() {
    411         $post_id   = $this->factory->post->create();
    412         $category1 = $this->factory->category->create(
     411        $post_id   = self::factory()->post->create();
     412        $category1 = self::factory()->category->create(
    413413            array(
    414414                'name'        => 'DC',
     
    416416            )
    417417        );
    418         $category2 = $this->factory->category->create(
     418        $category2 = self::factory()->category->create(
    419419            array(
    420420                'name'        => 'Marvel',
     
    422422            )
    423423        );
    424         $category3 = $this->factory->category->create(
     424        $category3 = self::factory()->category->create(
    425425            array(
    426426                'name'        => 'Image',
     
    494494        $controller = new WP_REST_Terms_Controller( 'batman' );
    495495        $controller->register_routes();
    496         $term1 = $this->factory->term->create(
     496        $term1 = self::factory()->term->create(
    497497            array(
    498498                'name'     => 'Cape',
     
    500500            )
    501501        );
    502         $term2 = $this->factory->term->create(
     502        $term2 = self::factory()->term->create(
    503503            array(
    504504                'name'     => 'Mask',
     
    506506            )
    507507        );
    508         $this->factory->term->create(
     508        self::factory()->term->create(
    509509            array(
    510510                'name'     => 'Car',
     
    512512            )
    513513        );
    514         $post_id = $this->factory->post->create();
     514        $post_id = self::factory()->post->create();
    515515        wp_set_object_terms( $post_id, array( $term1, $term2 ), 'batman' );
    516516
     
    526526
    527527    public function test_get_items_search_args() {
    528         $this->factory->category->create( array( 'name' => 'Apple' ) );
    529         $this->factory->category->create( array( 'name' => 'Banana' ) );
     528        self::factory()->category->create( array( 'name' => 'Apple' ) );
     529        self::factory()->category->create( array( 'name' => 'Banana' ) );
    530530
    531531        /*
     
    550550
    551551    public function test_get_items_slug_arg() {
    552         $this->factory->category->create( array( 'name' => 'Apple' ) );
    553         $this->factory->category->create( array( 'name' => 'Banana' ) );
     552        self::factory()->category->create( array( 'name' => 'Apple' ) );
     553        self::factory()->category->create( array( 'name' => 'Banana' ) );
    554554
    555555        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     
    563563
    564564    public function test_get_terms_parent_arg() {
    565         $category1 = $this->factory->category->create( array( 'name' => 'Parent' ) );
    566         $this->factory->category->create(
     565        $category1 = self::factory()->category->create( array( 'name' => 'Parent' ) );
     566        self::factory()->category->create(
    567567            array(
    568568                'name'   => 'Child',
     
    588588    public function test_get_terms_private_taxonomy() {
    589589        register_taxonomy( 'robin', 'post', array( 'public' => false ) );
    590         $this->factory->term->create(
     590        self::factory()->term->create(
    591591            array(
    592592                'name'     => 'Cape',
     
    594594            )
    595595        );
    596         $this->factory->term->create(
     596        self::factory()->term->create(
    597597            array(
    598598                'name'     => 'Mask',
     
    633633
    634634        // 3rd page.
    635         $this->factory->category->create();
     635        self::factory()->category->create();
    636636        $total_categories++;
    637637        $total_pages++;
     
    776776    public function test_get_term_private_taxonomy() {
    777777        register_taxonomy( 'robin', 'post', array( 'public' => false ) );
    778         $term1 = $this->factory->term->create(
     778        $term1 = self::factory()->term->create(
    779779            array(
    780780                'name'     => 'Cape',
     
    790790    public function test_get_item_incorrect_taxonomy() {
    791791        register_taxonomy( 'robin', 'post' );
    792         $term1 = $this->factory->term->create(
     792        $term1 = self::factory()->term->create(
    793793            array(
    794794                'name'     => 'Cape',
     
    825825        wp_set_current_user( self::$administrator );
    826826
    827         $existing_id = $this->factory->category->create( array( 'name' => 'Existing' ) );
     827        $existing_id = self::factory()->category->create( array( 'name' => 'Existing' ) );
    828828
    829829        $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
     
    891891        wp_set_current_user( self::$administrator );
    892892
    893         $term = get_term_by( 'id', $this->factory->category->create(), 'category' );
     893        $term = get_term_by( 'id', self::factory()->category->create(), 'category' );
    894894
    895895        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
     
    923923        );
    924924
    925         $term = get_term_by( 'id', $this->factory->category->create( $orig_args ), 'category' );
     925        $term = get_term_by( 'id', self::factory()->category->create( $orig_args ), 'category' );
    926926
    927927        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
     
    969969        wp_set_current_user( self::$subscriber );
    970970
    971         $term = get_term_by( 'id', $this->factory->category->create(), 'category' );
     971        $term = get_term_by( 'id', self::factory()->category->create(), 'category' );
    972972
    973973        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
     
    980980        wp_set_current_user( self::$administrator );
    981981
    982         $parent = get_term_by( 'id', $this->factory->category->create(), 'category' );
    983         $term   = get_term_by( 'id', $this->factory->category->create(), 'category' );
     982        $parent = get_term_by( 'id', self::factory()->category->create(), 'category' );
     983        $term   = get_term_by( 'id', self::factory()->category->create(), 'category' );
    984984
    985985        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
     
    995995        wp_set_current_user( self::$administrator );
    996996
    997         $old_parent_term = get_term_by( 'id', $this->factory->category->create(), 'category' );
     997        $old_parent_term = get_term_by( 'id', self::factory()->category->create(), 'category' );
    998998        $new_parent_id   = 0;
    999999
    10001000        $term = get_term_by(
    10011001            'id',
    1002             $this->factory->category->create(
     1002            self::factory()->category->create(
    10031003                array(
    10041004                    'parent' => $old_parent_term->term_id,
     
    10221022        wp_set_current_user( self::$administrator );
    10231023
    1024         $term = get_term_by( 'id', $this->factory->category->create(), 'category' );
     1024        $term = get_term_by( 'id', self::factory()->category->create(), 'category' );
    10251025
    10261026        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
     
    10331033        wp_set_current_user( self::$administrator );
    10341034
    1035         $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
     1035        $term = get_term_by( 'id', self::factory()->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
    10361036
    10371037        $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
     
    10471047        wp_set_current_user( self::$administrator );
    10481048
    1049         $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
     1049        $term = get_term_by( 'id', self::factory()->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
    10501050
    10511051        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
     
    10771077        wp_set_current_user( self::$subscriber );
    10781078
    1079         $term     = get_term_by( 'id', $this->factory->category->create(), 'category' );
     1079        $term     = get_term_by( 'id', self::factory()->category->create(), 'category' );
    10801080        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    10811081        $response = rest_get_server()->dispatch( $request );
     
    11091109
    11101110    public function test_prepare_taxonomy_term_child() {
    1111         $child = $this->factory->category->create(
     1111        $child = self::factory()->category->create(
    11121112            array(
    11131113                'parent' => 1,
     
    11711171        $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
    11721172
    1173         $category_id = $this->factory->category->create();
     1173        $category_id = self::factory()->category->create();
    11741174        $request     = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id );
    11751175
Note: See TracChangeset for help on using the changeset viewer.