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/media/getPostGalleries.php

    r53852 r54090  
    2929     */
    3030    public function test_returns_empty_array_with_post_with_no_gallery() {
    31         $post_id = $this->factory->post->create(
     31        $post_id = self::factory()->post->create(
    3232            array(
    3333                'post_content' => '<p>A post with no gallery</p>',
     
    5050     */
    5151    public function test_returns_only_galleries( $content, $needle ) {
    52         $image_id = $this->factory->attachment->create_object(
     52        $image_id = self::factory()->attachment->create_object(
    5353            array(
    5454                'file'           => 'test.jpg',
     
    6767        );
    6868
    69         $post_id = $this->factory->post->create(
     69        $post_id = self::factory()->post->create(
    7070            array(
    7171                'post_content' => $content,
     
    125125    public function test_returns_no_srcs_with_shortcode_in_post_with_no_attached_images() {
    126126        // Set up an unattached image.
    127         $this->factory->attachment->create_object(
     127        self::factory()->attachment->create_object(
    128128            array(
    129129                'file'           => 'test.jpg',
     
    134134        );
    135135
    136         $post_id = $this->factory->post->create(
     136        $post_id = self::factory()->post->create(
    137137            array(
    138138                'post_content' => '[gallery]',
     
    174174    public function test_returns_no_srcs_with_block_in_post_with_no_attached_images() {
    175175        // Set up an unattached image.
    176         $this->factory->attachment->create_object(
     176        self::factory()->attachment->create_object(
    177177            array(
    178178                'file'           => 'test.jpg',
     
    183183        );
    184184
    185         $post_id = $this->factory->post->create(
     185        $post_id = self::factory()->post->create(
    186186            array(
    187187                'post_content' => '<!-- wp:gallery -->',
     
    232232    public function test_returns_no_srcs_with_block_v2_in_post_with_no_attached_images() {
    233233        // Set up an unattached image.
    234         $image_id = $this->factory->attachment->create_object(
     234        $image_id = self::factory()->attachment->create_object(
    235235            array(
    236236                'file'           => 'test.jpg',
     
    261261BLOB;
    262262
    263         $post_id = $this->factory->post->create(
     263        $post_id = self::factory()->post->create(
    264264            array(
    265265                'post_content' => $blob,
     
    310310     */
    311311    public function test_returns_html_with_shortcode_gallery() {
    312         $post_id = $this->factory->post->create(
     312        $post_id = self::factory()->post->create(
    313313            array(
    314314                'post_content' => 'I have no gallery',
     
    316316        );
    317317
    318         $post_id_two = $this->factory->post->create(
     318        $post_id_two = self::factory()->post->create(
    319319            array(
    320320                'post_content' => "[gallery id='$post_id']",
     
    322322        );
    323323
    324         $this->factory->attachment->create_object(
     324        self::factory()->attachment->create_object(
    325325            array(
    326326                'file'           => 'test.jpg',
     
    364364     */
    365365    public function test_returns_html_with_block_gallery() {
    366         $post_id = $this->factory->post->create(
     366        $post_id = self::factory()->post->create(
    367367            array(
    368368                'post_content' => 'I have no gallery.',
     
    371371
    372372        // Set up an unattached image.
    373         $image_id = $this->factory->attachment->create(
     373        $image_id = self::factory()->attachment->create(
    374374            array(
    375375                'file'           => 'test.jpg',
     
    388388BLOB;
    389389
    390         $post_id_two = $this->factory->post->create(
     390        $post_id_two = self::factory()->post->create(
    391391            array(
    392392                'post_content' => $blob,
     
    427427     */
    428428    public function test_returns_html_with_block_gallery_v2() {
    429         $image_id = $this->factory->attachment->create_object(
     429        $image_id = self::factory()->attachment->create_object(
    430430            array(
    431431                'file'           => 'test.jpg',
     
    456456BLOB;
    457457
    458         $post_id = $this->factory->post->create(
     458        $post_id = self::factory()->post->create(
    459459            array(
    460460                'post_content' => $blob,
     
    496496     */
    497497    public function test_respects_post_id_with_shortcode_gallery() {
    498         $global_post_id = $this->factory->post->create(
     498        $global_post_id = self::factory()->post->create(
    499499            array(
    500500                'post_content' => 'Global Post',
    501501            )
    502502        );
    503         $post_id        = $this->factory->post->create(
     503        $post_id        = self::factory()->post->create(
    504504            array(
    505505                'post_content' => '[gallery]',
    506506            )
    507507        );
    508         $this->factory->attachment->create_object(
     508        self::factory()->attachment->create_object(
    509509            array(
    510510                'file'           => 'test.jpg',
     
    578578        $ids_joined = join( ',', $ids );
    579579
    580         $global_post_id = $this->factory->post->create(
     580        $global_post_id = self::factory()->post->create(
    581581            array(
    582582                'post_content' => 'Global Post',
     
    589589BLOB;
    590590
    591         $post_id = $this->factory->post->create(
     591        $post_id = self::factory()->post->create(
    592592            array(
    593593                'post_content' => $blob,
    594594            )
    595595        );
    596         $this->factory->attachment->create_object(
     596        self::factory()->attachment->create_object(
    597597            array(
    598598                'file'           => 'test.jpg',
     
    658658        $metadata       = array_merge( array( 'file' => 'image1.jpg' ), self::IMG_META );
    659659        $url            = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . 'image1.jpg';
    660         $global_post_id = $this->factory->post->create(
     660        $global_post_id = self::factory()->post->create(
    661661            array(
    662662                'post_content' => 'Global Post',
     
    684684BLOB;
    685685
    686         $post_id = $this->factory->post->create(
     686        $post_id = self::factory()->post->create(
    687687            array(
    688688                'post_content' => $blob,
    689689            )
    690690        );
    691         $this->factory->attachment->create_object(
     691        self::factory()->attachment->create_object(
    692692            array(
    693693                'file'           => 'test.jpg',
     
    743743     */
    744744    public function test_respects_shortcode_id_attribute() {
    745         $post_id     = $this->factory->post->create(
     745        $post_id     = self::factory()->post->create(
    746746            array(
    747747                'post_content' => 'No gallery defined',
    748748            )
    749749        );
    750         $post_id_two = $this->factory->post->create(
     750        $post_id_two = self::factory()->post->create(
    751751            array(
    752752                'post_content' => "[gallery id='$post_id']",
    753753            )
    754754        );
    755         $this->factory->attachment->create_object(
     755        self::factory()->attachment->create_object(
    756756            array(
    757757                'file'           => 'test.jpg',
     
    951951    public function test_returns_srcs_from_html_with_block_with_no_json_blob() {
    952952        // Set up an unattached image.
    953         $image_id = $this->factory->attachment->create_object(
     953        $image_id = self::factory()->attachment->create_object(
    954954            array(
    955955                'file'           => 'test.jpg',
     
    973973BLOB;
    974974
    975         $post_id = $this->factory->post->create(
     975        $post_id = self::factory()->post->create(
    976976            array(
    977977                'post_content' => $blob,
     
    10231023     */
    10241024    public function test_returns_srcs_with_nested_block_gallery() {
    1025         $post_id  = $this->factory->post->create(
     1025        $post_id  = self::factory()->post->create(
    10261026            array(
    10271027                'post_content' => 'I have no gallery.',
    10281028            )
    10291029        );
    1030         $image_id = $this->factory->attachment->create_object(
     1030        $image_id = self::factory()->attachment->create_object(
    10311031            array(
    10321032                'file'           => 'test.jpg',
     
    10461046BLOB;
    10471047
    1048         $post_id_two = $this->factory->post->create( array( 'post_content' => $blob ) );
     1048        $post_id_two = self::factory()->post->create( array( 'post_content' => $blob ) );
    10491049
    10501050        $galleries = get_post_galleries( $post_id_two, false );
Note: See TracChangeset for help on using the changeset viewer.