Make WordPress Core

Changeset 57237


Ignore:
Timestamp:
01/02/2024 03:57:20 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use more specific assertions in wp_scheduled_delete() tests.

Includes clarifying test method names and descriptions.

Follow-up to [57224].

See #59938.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/wpScheduledDelete.php

    r57224 r57237  
    22
    33/**
    4  * Tests for the wp_scheduled_delete function.
     4 * Tests for the wp_scheduled_delete() function.
    55 *
    6  * @group Functions.php
     6 * @group functions
    77 *
    88 * @covers ::wp_scheduled_delete
    … …  
    1818                        wp_delete_comment( self::$comment_id );
    1919                }
     20
    2021                // Remove page.
    2122                if ( self::$page_id ) {
    2223                        wp_delete_post( self::$page_id );
    2324                }
     25
    2426                parent::tear_down();
    2527        }
    2628
    2729        /**
    28          * Delete old trashed post/pages.
     30         * Tests that old trashed posts/pages are deleted.
    2931         *
    3032         * @ticket 59938
    31          *
    3233         */
    3334        public function test_wp_scheduled_delete() {
    … …  
    4142                add_post_meta( self::$page_id, '_wp_trash_meta_status', 'published' );
    4243
    43                 $this->assertNotEmpty( get_post( self::$page_id ) );
     44                $this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );
    4445
    4546                wp_scheduled_delete();
    4647
    47                 $this->assertEmpty( get_post( self::$page_id ) );
     48                $this->assertNull( get_post( self::$page_id ) );
    4849        }
    4950
    5051        /**
    51          * Don't delete old trashed post/pages if status not trash.
    52          * Remove the trash meta status.
     52         * Tests that old trashed posts/pages are not deleted if status is not 'trash'.
     53         *
     54         * Ensures that the trash meta status is removed.
    5355         *
    5456         * @ticket 59938
    55          *
    5657         */
    57         public function test_wp_scheduled_delete_not_trash() {
     58        public function test_wp_scheduled_delete_status_not_trash() {
    5859                self::$page_id = self::factory()->post->create(
    5960                        array(
    … …  
    6566                add_post_meta( self::$page_id, '_wp_trash_meta_status', 'published' );
    6667
    67                 $this->assertNotEmpty( get_post( self::$page_id ) );
     68                $this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );
    6869
    6970                wp_scheduled_delete();
    7071
    71                 $this->assertNotEmpty( get_post( self::$page_id ) );
    72                 $this->assertEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
    73                 $this->assertEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
     72                $this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );
     73                $this->assertSame( '', get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
     74                $this->assertSame( '', get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
    7475        }
    7576
    7677
    7778        /**
    78          * Don't delete old trashed post/pages if old enough.
     79         * Tests that old trashed posts/pages are not deleted if not old enough.
    7980         *
    8081         * @ticket 59938
    81          *
    8282         */
    83         public function test_wp_scheduled_delete_not_old() {
     83        public function test_wp_scheduled_delete_page_not_old_enough() {
    8484                self::$page_id = self::factory()->post->create(
    8585                        array(
    … …  
    9191                add_post_meta( self::$page_id, '_wp_trash_meta_status', 'published' );
    9292
    93                 $this->assertNotEmpty( get_post( self::$page_id ) );
     93                $this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );
    9494
    9595                wp_scheduled_delete();
    9696
    97                 $this->assertNotEmpty( get_post( self::$page_id ) );
    98                 $this->assertNotEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
    99                 $this->assertNotEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
     97                $this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );
     98                $this->assertIsNumeric( get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
     99                $this->assertSame( 'published', get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
    100100        }
    101101
    102102        /**
    103          * Delete old trashed comments.
     103         * Tests that old trashed comments are deleted.
    104104         *
    105105         * @ticket 59938
    106          *
    107106         */
    108107        public function test_wp_scheduled_delete_comment() {
    … …  
    115114                add_post_meta( self::$comment_id, '_wp_trash_meta_status', 'published' );
    116115
    117                 $this->assertNotEmpty( get_comment( self::$comment_id ) );
     116                $this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );
    118117
    119118                wp_scheduled_delete();
    120119
    121                 $this->assertEmpty( get_comment( self::$comment_id ) );
     120                $this->assertNull( get_comment( self::$comment_id ) );
    122121        }
    123122
    124123        /**
    125          * Don't delete old trashed comments if status not trash.
    126          * Remove the trash meta status.
     124         * Tests that old trashed comments are not deleted if status is not 'trash'.
     125         *
     126         * Ensures that the trash meta status is removed.
    127127         *
    128128         * @ticket 59938
    129          *
    130129         */
    131         public function test_wp_scheduled_delete_not_trash_comment() {
     130        public function test_wp_scheduled_delete_comment_status_not_trash() {
    132131                self::$comment_id = self::factory()->comment->create(
    133132                        array(
    … …  
    138137                add_comment_meta( self::$comment_id, '_wp_trash_meta_status', 'published' );
    139138
    140                 $this->assertNotEmpty( get_comment( self::$comment_id ) );
     139                $this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );
    141140
    142141                wp_scheduled_delete();
    143142
    144                 $this->assertNotEmpty( get_comment( self::$comment_id ) );
    145                 $this->assertEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
    146                 $this->assertEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
     143                $this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );
     144                $this->assertSame( '', get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
     145                $this->assertSame( '', get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
    147146        }
    148147
    149148
    150149        /**
    151          * Don't delete old trashed comments if old enough.
     150         * Tests that old trashed comments are not deleted if not old enough.
    152151         *
    153152         * @ticket 59938
    154          *
    155153         */
    156         public function test_wp_scheduled_delete_not_old_comment() {
     154        public function test_wp_scheduled_delete_comment_not_old_enough() {
    157155                self::$comment_id = self::factory()->comment->create(
    158156                        array(
    … …  
    163161                add_comment_meta( self::$comment_id, '_wp_trash_meta_status', 'published' );
    164162
    165                 $this->assertNotEmpty( get_comment( self::$comment_id ) );
     163                $this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );
    166164
    167165                wp_scheduled_delete();
    168166
    169                 $this->assertNotEmpty( get_comment( self::$comment_id ) );
    170                 $this->assertNotEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
    171                 $this->assertNotEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
     167                $this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );
     168                $this->assertIsNumeric( get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
     169                $this->assertSame( 'published', get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
    172170        }
    173171}
Note: See TracChangeset for help on using the changeset viewer.