Make WordPress Core


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

    r54086 r54090  
    186186        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    187187        // Single.
    188         $attachment_id = $this->factory->attachment->create_object(
     188        $attachment_id = self::factory()->attachment->create_object(
    189189            $this->test_file,
    190190            0,
     
    247247
    248248    public function test_registered_get_item_params() {
    249         $id1      = $this->factory->attachment->create_object(
     249        $id1      = self::factory()->attachment->create_object(
    250250            $this->test_file,
    251251            0,
     
    267267     */
    268268    public function test_allow_header_sent_on_options_request() {
    269         $id1      = $this->factory->attachment->create_object(
     269        $id1      = self::factory()->attachment->create_object(
    270270            $this->test_file,
    271271            0,
     
    295295    public function test_get_items() {
    296296        wp_set_current_user( 0 );
    297         $id1            = $this->factory->attachment->create_object(
    298             $this->test_file,
    299             0,
    300             array(
    301                 'post_mime_type' => 'image/jpeg',
    302                 'post_excerpt'   => 'A sample caption',
    303             )
    304         );
    305         $draft_post     = $this->factory->post->create( array( 'post_status' => 'draft' ) );
    306         $id2            = $this->factory->attachment->create_object(
     297        $id1            = self::factory()->attachment->create_object(
     298            $this->test_file,
     299            0,
     300            array(
     301                'post_mime_type' => 'image/jpeg',
     302                'post_excerpt'   => 'A sample caption',
     303            )
     304        );
     305        $draft_post     = self::factory()->post->create( array( 'post_status' => 'draft' ) );
     306        $id2            = self::factory()->attachment->create_object(
    307307            $this->test_file,
    308308            $draft_post,
     
    312312            )
    313313        );
    314         $published_post = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    315         $id3            = $this->factory->attachment->create_object(
     314        $published_post = self::factory()->post->create( array( 'post_status' => 'publish' ) );
     315        $id3            = self::factory()->attachment->create_object(
    316316            $this->test_file,
    317317            $published_post,
     
    335335    public function test_get_items_logged_in_editor() {
    336336        wp_set_current_user( self::$editor_id );
    337         $id1            = $this->factory->attachment->create_object(
    338             $this->test_file,
    339             0,
    340             array(
    341                 'post_mime_type' => 'image/jpeg',
    342                 'post_excerpt'   => 'A sample caption',
    343             )
    344         );
    345         $draft_post     = $this->factory->post->create( array( 'post_status' => 'draft' ) );
    346         $id2            = $this->factory->attachment->create_object(
     337        $id1            = self::factory()->attachment->create_object(
     338            $this->test_file,
     339            0,
     340            array(
     341                'post_mime_type' => 'image/jpeg',
     342                'post_excerpt'   => 'A sample caption',
     343            )
     344        );
     345        $draft_post     = self::factory()->post->create( array( 'post_status' => 'draft' ) );
     346        $id2            = self::factory()->attachment->create_object(
    347347            $this->test_file,
    348348            $draft_post,
     
    352352            )
    353353        );
    354         $published_post = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    355         $id3            = $this->factory->attachment->create_object(
     354        $published_post = self::factory()->post->create( array( 'post_status' => 'publish' ) );
     355        $id3            = self::factory()->attachment->create_object(
    356356            $this->test_file,
    357357            $published_post,
     
    373373
    374374    public function test_get_items_media_type() {
    375         $id1      = $this->factory->attachment->create_object(
     375        $id1      = self::factory()->attachment->create_object(
    376376            $this->test_file,
    377377            0,
     
    396396
    397397    public function test_get_items_mime_type() {
    398         $id1      = $this->factory->attachment->create_object(
     398        $id1      = self::factory()->attachment->create_object(
    399399            $this->test_file,
    400400            0,
     
    419419
    420420    public function test_get_items_parent() {
    421         $post_id        = $this->factory->post->create( array( 'post_title' => 'Test Post' ) );
    422         $attachment_id  = $this->factory->attachment->create_object(
     421        $post_id        = self::factory()->post->create( array( 'post_title' => 'Test Post' ) );
     422        $attachment_id  = self::factory()->attachment->create_object(
    423423            $this->test_file,
    424424            $post_id,
     
    428428            )
    429429        );
    430         $attachment_id2 = $this->factory->attachment->create_object(
     430        $attachment_id2 = self::factory()->attachment->create_object(
    431431            $this->test_file,
    432432            0,
     
    464464    public function test_get_items_invalid_status_param_is_error_response() {
    465465        wp_set_current_user( self::$editor_id );
    466         $this->factory->attachment->create_object(
     466        self::factory()->attachment->create_object(
    467467            $this->test_file,
    468468            0,
     
    482482        // Logged out users can't make the request.
    483483        wp_set_current_user( 0 );
    484         $attachment_id1 = $this->factory->attachment->create_object(
     484        $attachment_id1 = self::factory()->attachment->create_object(
    485485            $this->test_file,
    486486            0,
     
    506506        // Logged out users can't make the request.
    507507        wp_set_current_user( 0 );
    508         $attachment_id1 = $this->factory->attachment->create_object(
     508        $attachment_id1 = self::factory()->attachment->create_object(
    509509            $this->test_file,
    510510            0,
     
    515515            )
    516516        );
    517         $attachment_id2 = $this->factory->attachment->create_object(
     517        $attachment_id2 = self::factory()->attachment->create_object(
    518518            $this->test_file,
    519519            0,
     
    551551
    552552    public function test_get_items_valid_date() {
    553         $id1     = $this->factory->attachment->create_object(
     553        $id1     = self::factory()->attachment->create_object(
    554554            $this->test_file,
    555555            0,
     
    560560            )
    561561        );
    562         $id2     = $this->factory->attachment->create_object(
     562        $id2     = self::factory()->attachment->create_object(
    563563            $this->test_file,
    564564            0,
     
    569569            )
    570570        );
    571         $id3     = $this->factory->attachment->create_object(
     571        $id3     = self::factory()->attachment->create_object(
    572572            $this->test_file,
    573573            0,
     
    602602     */
    603603    public function test_get_items_valid_modified_date() {
    604         $id1 = $this->factory->attachment->create_object(
     604        $id1 = self::factory()->attachment->create_object(
    605605            $this->test_file,
    606606            0,
     
    611611            )
    612612        );
    613         $id2 = $this->factory->attachment->create_object(
     613        $id2 = self::factory()->attachment->create_object(
    614614            $this->test_file,
    615615            0,
     
    620620            )
    621621        );
    622         $id3 = $this->factory->attachment->create_object(
     622        $id3 = self::factory()->attachment->create_object(
    623623            $this->test_file,
    624624            0,
     
    662662     */
    663663    public function test_get_items_with_empty_page_runs_count_query_after() {
    664         $this->factory->attachment->create_object(
     664        self::factory()->attachment->create_object(
    665665            $this->test_file,
    666666            0,
     
    684684
    685685    public function test_get_item() {
    686         $attachment_id = $this->factory->attachment->create_object(
     686        $attachment_id = self::factory()->attachment->create_object(
    687687            $this->test_file,
    688688            0,
     
    704704     */
    705705    public function test_get_item_sizes() {
    706         $attachment_id = $this->factory->attachment->create_object(
     706        $attachment_id = self::factory()->attachment->create_object(
    707707            $this->test_file,
    708708            0,
     
    735735     */
    736736    public function test_get_item_sizes_with_no_url() {
    737         $attachment_id = $this->factory->attachment->create_object(
     737        $attachment_id = self::factory()->attachment->create_object(
    738738            $this->test_file,
    739739            0,
     
    762762    public function test_get_item_private_post_not_authenticated() {
    763763        wp_set_current_user( 0 );
    764         $draft_post = $this->factory->post->create( array( 'post_status' => 'draft' ) );
    765         $id1        = $this->factory->attachment->create_object(
     764        $draft_post = self::factory()->post->create( array( 'post_status' => 'draft' ) );
     765        $id1        = self::factory()->attachment->create_object(
    766766            $this->test_file,
    767767            $draft_post,
     
    777777
    778778    public function test_get_item_inherit_status_with_invalid_parent() {
    779         $attachment_id = $this->factory->attachment->create_object(
     779        $attachment_id = self::factory()->attachment->create_object(
    780780            $this->test_file,
    781781            REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
     
    794794
    795795    public function test_get_item_auto_status_with_invalid_parent_not_authenticated_returns_error() {
    796         $attachment_id = $this->factory->attachment->create_object(
     796        $attachment_id = self::factory()->attachment->create_object(
    797797            $this->test_file,
    798798            REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
     
    964964
    965965    public function test_create_item_invalid_edit_permissions() {
    966         $post_id = $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
     966        $post_id = self::factory()->post->create( array( 'post_author' => self::$editor_id ) );
    967967        wp_set_current_user( self::$author_id );
    968968        $request = new WP_REST_Request( 'POST', '/wp/v2/media' );
     
    973973
    974974    public function test_create_item_invalid_upload_permissions() {
    975         $post_id = $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
     975        $post_id = self::factory()->post->create( array( 'post_author' => self::$editor_id ) );
    976976        wp_set_current_user( self::$uploader_id );
    977977        $request = new WP_REST_Request( 'POST', '/wp/v2/media' );
     
    982982
    983983    public function test_create_item_invalid_post_type() {
    984         $attachment_id = $this->factory->post->create(
     984        $attachment_id = self::factory()->post->create(
    985985            array(
    986986                'post_type'   => 'attachment',
     
    10471047    public function test_update_item() {
    10481048        wp_set_current_user( self::$editor_id );
    1049         $attachment_id = $this->factory->attachment->create_object(
     1049        $attachment_id = self::factory()->attachment->create_object(
    10501050            $this->test_file,
    10511051            0,
     
    10761076    public function test_update_item_parent() {
    10771077        wp_set_current_user( self::$editor_id );
    1078         $original_parent = $this->factory->post->create( array() );
    1079         $attachment_id   = $this->factory->attachment->create_object(
     1078        $original_parent = self::factory()->post->create( array() );
     1079        $attachment_id   = self::factory()->attachment->create_object(
    10801080            $this->test_file,
    10811081            $original_parent,
     
    10901090        $this->assertSame( $original_parent, $attachment->post_parent );
    10911091
    1092         $new_parent = $this->factory->post->create( array() );
     1092        $new_parent = self::factory()->post->create( array() );
    10931093        $request    = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id );
    10941094        $request->set_param( 'post', $new_parent );
     
    11011101    public function test_update_item_invalid_permissions() {
    11021102        wp_set_current_user( self::$author_id );
    1103         $attachment_id = $this->factory->attachment->create_object(
     1103        $attachment_id = self::factory()->attachment->create_object(
    11041104            $this->test_file,
    11051105            0,
     
    11171117
    11181118    public function test_update_item_invalid_post_type() {
    1119         $attachment_id = $this->factory->post->create(
     1119        $attachment_id = self::factory()->post->create(
    11201120            array(
    11211121                'post_type'   => 'attachment',
     
    11251125        );
    11261126        wp_set_current_user( self::$editor_id );
    1127         $attachment_id = $this->factory->attachment->create_object(
     1127        $attachment_id = self::factory()->attachment->create_object(
    11281128            $this->test_file,
    11291129            0,
     
    14491449    public function test_delete_item() {
    14501450        wp_set_current_user( self::$editor_id );
    1451         $attachment_id    = $this->factory->attachment->create_object(
     1451        $attachment_id    = self::factory()->attachment->create_object(
    14521452            $this->test_file,
    14531453            0,
     
    14651465    public function test_delete_item_no_trash() {
    14661466        wp_set_current_user( self::$editor_id );
    1467         $attachment_id = $this->factory->attachment->create_object(
     1467        $attachment_id = self::factory()->attachment->create_object(
    14681468            $this->test_file,
    14691469            0,
     
    14901490    public function test_delete_item_invalid_delete_permissions() {
    14911491        wp_set_current_user( self::$author_id );
    1492         $attachment_id = $this->factory->attachment->create_object(
     1492        $attachment_id = self::factory()->attachment->create_object(
    14931493            $this->test_file,
    14941494            0,
     
    15051505
    15061506    public function test_prepare_item() {
    1507         $attachment_id = $this->factory->attachment->create_object(
     1507        $attachment_id = self::factory()->attachment->create_object(
    15081508            $this->test_file,
    15091509            0,
     
    15241524
    15251525    public function test_prepare_item_limit_fields() {
    1526         $attachment_id = $this->factory->attachment->create_object(
     1526        $attachment_id = self::factory()->attachment->create_object(
    15271527            $this->test_file,
    15281528            0,
     
    16151615        $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
    16161616
    1617         $attachment_id = $this->factory->attachment->create_object(
     1617        $attachment_id = self::factory()->attachment->create_object(
    16181618            $this->test_file,
    16191619            0,
     
    16521652
    16531653        wp_set_current_user( self::$editor_id );
    1654         $attachment_id = $this->factory->attachment->create_object(
     1654        $attachment_id = self::factory()->attachment->create_object(
    16551655            $this->test_file,
    16561656            0,
     
    16781678
    16791679    public function test_search_item_by_filename() {
    1680         $id1 = $this->factory->attachment->create_object(
    1681             $this->test_file,
    1682             0,
    1683             array(
    1684                 'post_mime_type' => 'image/jpeg',
    1685             )
    1686         );
    1687         $id2 = $this->factory->attachment->create_object(
     1680        $id1 = self::factory()->attachment->create_object(
     1681            $this->test_file,
     1682            0,
     1683            array(
     1684                'post_mime_type' => 'image/jpeg',
     1685            )
     1686        );
     1687        $id2 = self::factory()->attachment->create_object(
    16881688            $this->test_file2,
    16891689            0,
     
    19361936
    19371937        wp_set_current_user( self::$editor_id );
    1938         $attachment_id = $this->factory->attachment->create_object(
     1938        $attachment_id = self::factory()->attachment->create_object(
    19391939            $this->test_file,
    19401940            0,
Note: See TracChangeset for help on using the changeset viewer.