Make WordPress Core


Ignore:
Timestamp:
09/06/2022 10:09:49 PM (18 months 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-comments-controller.php

    r53909 r54090  
    238238        );
    239239
    240         $password_comment = $this->factory->comment->create( $args );
     240        $password_comment = self::factory()->comment->create( $args );
    241241
    242242        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    262262        );
    263263
    264         $password_comment = $this->factory->comment->create( $args );
     264        $password_comment = self::factory()->comment->create( $args );
    265265
    266266        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    285285        );
    286286
    287         $password_comment = $this->factory->comment->create( $args );
     287        $password_comment = self::factory()->comment->create( $args );
    288288
    289289        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    303303        );
    304304
    305         $password_comment = $this->factory->comment->create( $args );
     305        $password_comment = self::factory()->comment->create( $args );
    306306
    307307        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    322322        );
    323323
    324         $password_comment = $this->factory->comment->create( $args );
     324        $password_comment = self::factory()->comment->create( $args );
    325325
    326326        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    341341        );
    342342
    343         $private_comment = $this->factory->comment->create( $args );
     343        $private_comment = self::factory()->comment->create( $args );
    344344
    345345        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    360360        );
    361361
    362         $private_comment = $this->factory->comment->create( $args );
     362        $private_comment = self::factory()->comment->create( $args );
    363363
    364364        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    374374        wp_set_current_user( 0 );
    375375
    376         $comment_id = $this->factory->comment->create(
     376        $comment_id = self::factory()->comment->create(
    377377            array(
    378378                'comment_approved' => 1,
     
    395395        wp_set_current_user( self::$admin_id );
    396396
    397         $comment_id = $this->factory->comment->create(
     397        $comment_id = self::factory()->comment->create(
    398398            array(
    399399                'comment_approved' => 1,
     
    425425        wp_set_current_user( self::$admin_id );
    426426
    427         $this->factory->comment->create_post_comments( 0, 2 );
     427        self::factory()->comment->create_post_comments( 0, 2 );
    428428
    429429        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    454454
    455455    public function test_get_items_for_post() {
    456         $second_post_id = $this->factory->post->create();
    457         $this->factory->comment->create_post_comments( $second_post_id, 2 );
     456        $second_post_id = self::factory()->post->create();
     457        self::factory()->comment->create_post_comments( $second_post_id, 2 );
    458458
    459459        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    479479        );
    480480
    481         $id1 = $this->factory->comment->create( $args );
    482         $id2 = $this->factory->comment->create( $args );
     481        $id1 = self::factory()->comment->create( $args );
     482        $id2 = self::factory()->comment->create( $args );
    483483
    484484        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    519519        );
    520520
    521         $id1 = $this->factory->comment->create( $args );
    522         $id2 = $this->factory->comment->create( $args );
     521        $id1 = self::factory()->comment->create( $args );
     522        $id2 = self::factory()->comment->create( $args );
    523523
    524524        $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    575575        );
    576576
    577         $id = $this->factory->comment->create( $args );
     577        $id = self::factory()->comment->create( $args );
    578578
    579579        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    599599        wp_set_current_user( 0 );
    600600
    601         $post_id = $this->factory->post->create( array( 'post_status' => 'private' ) );
     601        $post_id = self::factory()->post->create( array( 'post_status' => 'private' ) );
    602602
    603603        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    617617        );
    618618
    619         $this->factory->comment->create( $args );
     619        self::factory()->comment->create( $args );
    620620        $args['user_id'] = self::$subscriber_id;
    621         $this->factory->comment->create( $args );
     621        self::factory()->comment->create( $args );
    622622        unset( $args['user_id'] );
    623         $this->factory->comment->create( $args );
     623        self::factory()->comment->create( $args );
    624624
    625625        // Limit to comment author.
     
    660660        );
    661661
    662         $this->factory->comment->create( $args );
     662        self::factory()->comment->create( $args );
    663663        $args['user_id'] = self::$subscriber_id;
    664         $this->factory->comment->create( $args );
     664        self::factory()->comment->create( $args );
    665665        unset( $args['user_id'] );
    666         $this->factory->comment->create( $args );
     666        self::factory()->comment->create( $args );
    667667
    668668        $total_comments = self::$total_comments + 3;
     
    710710            'comment_post_ID'  => self::$post_id,
    711711        );
    712         $parent_id              = $this->factory->comment->create( $args );
    713         $parent_id2             = $this->factory->comment->create( $args );
     712        $parent_id              = self::factory()->comment->create( $args );
     713        $parent_id2             = self::factory()->comment->create( $args );
    714714        $args['comment_parent'] = $parent_id;
    715         $this->factory->comment->create( $args );
     715        self::factory()->comment->create( $args );
    716716        $args['comment_parent'] = $parent_id2;
    717         $this->factory->comment->create( $args );
     717        self::factory()->comment->create( $args );
    718718
    719719        $total_comments = self::$total_comments + 4;
     
    746746            'comment_post_ID'  => self::$post_id,
    747747        );
    748         $parent_id              = $this->factory->comment->create( $args );
    749         $parent_id2             = $this->factory->comment->create( $args );
     748        $parent_id              = self::factory()->comment->create( $args );
     749        $parent_id2             = self::factory()->comment->create( $args );
    750750        $args['comment_parent'] = $parent_id;
    751         $this->factory->comment->create( $args );
     751        self::factory()->comment->create( $args );
    752752        $args['comment_parent'] = $parent_id2;
    753         $this->factory->comment->create( $args );
     753        self::factory()->comment->create( $args );
    754754
    755755        $total_comments = self::$total_comments + 4;
     
    787787        );
    788788
    789         $id = $this->factory->comment->create( $args );
     789        $id = self::factory()->comment->create( $args );
    790790
    791791        $total_comments = self::$total_comments + 1;
     
    826826
    827827        // 3rd page.
    828         $this->factory->comment->create(
     828        self::factory()->comment->create(
    829829            array(
    830830                'comment_post_ID' => self::$post_id,
     
    896896
    897897    public function test_get_comments_valid_date() {
    898         $comment1 = $this->factory->comment->create(
     898        $comment1 = self::factory()->comment->create(
    899899            array(
    900900                'comment_date'    => '2016-01-15T00:00:00Z',
     
    902902            )
    903903        );
    904         $comment2 = $this->factory->comment->create(
     904        $comment2 = self::factory()->comment->create(
    905905            array(
    906906                'comment_date'    => '2016-01-16T00:00:00Z',
     
    908908            )
    909909        );
    910         $comment3 = $this->factory->comment->create(
     910        $comment3 = self::factory()->comment->create(
    911911            array(
    912912                'comment_date'    => '2016-01-17T00:00:00Z',
     
    10041004        wp_set_current_user( 0 );
    10051005
    1006         $comment_id = $this->factory->comment->create(
     1006        $comment_id = self::factory()->comment->create(
    10071007            array(
    10081008                'comment_approved' => 1,
     
    10191019        wp_set_current_user( self::$admin_id );
    10201020
    1021         $comment_id = $this->factory->comment->create(
     1021        $comment_id = self::factory()->comment->create(
    10221022            array(
    10231023                'comment_approved' => 1,
     
    10481048
    10491049    public function test_get_comment_with_children_link() {
    1050         $comment_id_1 = $this->factory->comment->create(
     1050        $comment_id_1 = self::factory()->comment->create(
    10511051            array(
    10521052                'comment_approved' => 1,
     
    10561056        );
    10571057
    1058         $child_comment = $this->factory->comment->create(
     1058        $child_comment = self::factory()->comment->create(
    10591059            array(
    10601060                'comment_approved' => 1,
     
    10721072
    10731073    public function test_get_comment_without_children_link() {
    1074         $comment_id_1 = $this->factory->comment->create(
     1074        $comment_id_1 = self::factory()->comment->create(
    10751075            array(
    10761076                'comment_approved' => 1,
     
    10941094        );
    10951095
    1096         $password_comment = $this->factory->comment->create( $args );
     1096        $password_comment = self::factory()->comment->create( $args );
    10971097
    10981098        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) );
     
    11121112        );
    11131113
    1114         $password_comment = $this->factory->comment->create( $args );
     1114        $password_comment = self::factory()->comment->create( $args );
    11151115
    11161116        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) );
     
    14911491
    14921492    public function test_create_item_assign_different_user() {
    1493         $subscriber_id = $this->factory->user->create(
     1493        $subscriber_id = self::factory()->user->create(
    14941494            array(
    14951495                'role'       => 'subscriber',
     
    15221522
    15231523    public function test_create_comment_without_type() {
    1524         $post_id = $this->factory->post->create();
     1524        $post_id = self::factory()->post->create();
    15251525
    15261526        wp_set_current_user( self::$admin_id );
     
    15601560     */
    15611561    public function test_create_comment_with_invalid_type() {
    1562         $post_id = $this->factory->post->create();
     1562        $post_id = self::factory()->post->create();
    15631563
    15641564        wp_set_current_user( self::$admin_id );
     
    15841584
    15851585    public function test_create_comment_invalid_email() {
    1586         $post_id = $this->factory->post->create();
     1586        $post_id = self::factory()->post->create();
    15871587
    15881588        wp_set_current_user( self::$admin_id );
     
    16071607
    16081608    public function test_create_item_current_user() {
    1609         $user_id = $this->factory->user->create(
     1609        $user_id = self::factory()->user->create(
    16101610            array(
    16111611                'role'         => 'subscriber',
     
    17291729
    17301730    public function test_create_comment_with_status_IP_and_user_agent() {
    1731         $post_id = $this->factory->post->create();
     1731        $post_id = self::factory()->post->create();
    17321732
    17331733        wp_set_current_user( self::$admin_id );
     
    20072007        wp_set_current_user( self::$subscriber_id );
    20082008
    2009         $this->factory->comment->create(
     2009        self::factory()->comment->create(
    20102010            array(
    20112011                'comment_post_ID'      => self::$post_id,
     
    20322032
    20332033    public function test_create_comment_closed() {
    2034         $post_id = $this->factory->post->create(
     2034        $post_id = self::factory()->post->create(
    20352035            array(
    20362036                'comment_status' => 'closed',
     
    23042304
    23052305    public function test_update_item() {
    2306         $post_id = $this->factory->post->create();
     2306        $post_id = self::factory()->post->create();
    23072307
    23082308        wp_set_current_user( self::$admin_id );
     
    23482348        update_option( 'timezone_string', $params['timezone_string'] );
    23492349
    2350         $comment_id = $this->factory->comment->create();
     2350        $comment_id = self::factory()->comment->create();
    23512351
    23522352        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $comment_id ) );
     
    23752375
    23762376    public function test_update_item_no_content() {
    2377         $post_id = $this->factory->post->create();
     2377        $post_id = self::factory()->post->create();
    23782378
    23792379        wp_set_current_user( self::$admin_id );
     
    24132413        wp_set_current_user( self::$admin_id );
    24142414
    2415         $comment_id = $this->factory->comment->create(
     2415        $comment_id = self::factory()->comment->create(
    24162416            array(
    24172417                'comment_approved' => 0,
     
    24402440        wp_set_current_user( self::$admin_id );
    24412441
    2442         $comment_id = $this->factory->comment->create(
     2442        $comment_id = self::factory()->comment->create(
    24432443            array(
    24442444                'comment_approved' => 0,
     
    27212721
    27222722    public function test_update_comment_private_post_invalid_permission() {
    2723         $private_comment_id = $this->factory->comment->create(
     2723        $private_comment_id = self::factory()->comment->create(
    27242724            array(
    27252725                'comment_approved' => 1,
     
    27462746        wp_set_current_user( self::$admin_id );
    27472747
    2748         $comment_id_1 = $this->factory->comment->create(
     2748        $comment_id_1 = self::factory()->comment->create(
    27492749            array(
    27502750                'comment_approved' => 1,
     
    27542754        );
    27552755
    2756         $child_comment = $this->factory->comment->create(
     2756        $child_comment = self::factory()->comment->create(
    27572757            array(
    27582758                'comment_approved' => 1,
     
    30483048        wp_set_current_user( self::$admin_id );
    30493049
    3050         $comment_id = $this->factory->comment->create(
     3050        $comment_id = self::factory()->comment->create(
    30513051            array(
    30523052                'comment_approved' => 1,
     
    30683068        wp_set_current_user( self::$admin_id );
    30693069
    3070         $comment_id = $this->factory->comment->create(
     3070        $comment_id = self::factory()->comment->create(
    30713071            array(
    30723072                'comment_approved' => 1,
     
    30893089        wp_set_current_user( self::$admin_id );
    30903090
    3091         $comment_id = $this->factory->comment->create(
     3091        $comment_id = self::factory()->comment->create(
    30923092            array(
    30933093                'comment_approved' => 1,
     
    31243124        wp_set_current_user( self::$admin_id );
    31253125
    3126         $comment_id_1 = $this->factory->comment->create(
     3126        $comment_id_1 = self::factory()->comment->create(
    31273127            array(
    31283128                'comment_approved' => 1,
     
    31323132        );
    31333133
    3134         $child_comment = $this->factory->comment->create(
     3134        $child_comment = self::factory()->comment->create(
    31353135            array(
    31363136                'comment_approved' => 1,
Note: See TracChangeset for help on using the changeset viewer.