Skip to content

Commit 5a96e2a

Browse files
Tests: Clean up the wp_delete_post() unit tests.
Four independent clean-ups in the test file: - **Remove the unused `$user_ids` fixture.** The property and its `wpSetUpBeforeClass()` method were copied over from the `wp_insert_post()` tests. Nothing in this class references `self::$user_ids`, so the only effect was creating three users for every test in the class. - **Rename `test_wp_delete_post_returns_false_for_invalid_post()`** to `test_wp_delete_post_returns_null_for_already_deleted_post()`. The test asserts `assertNull()`, and that is the correct expectation: for an ID with no matching row, `wp_delete_post()` returns the `null` coming out of `$wpdb->get_row()`, whereas `false` is only returned by the `$post_id <= 0` guard. The old name described the opposite of what the test covers. - **Reuse the `$actions` array** in the assertion loop of `test_wp_delete_post_actions()`. The same six action names were spelled out a second time inline, so the registration loop and the assertion loop could drift apart. - **Fix the `@ticket @63975` annotation.** The stray `@` made the tag invalid, so the test was not associated with the ticket. No assertion was added, removed or changed, and no test behavior changes. Developed in #13036. Follow-up to [60906]. Props Soean. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@63295 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3bbb42e commit 5a96e2a

1 file changed

Lines changed: 4 additions & 36 deletions

File tree

tests/phpunit/tests/post/wpDeletePost.php

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,6 @@
1616
*/
1717
class Tests_Post_WpDeletePost extends WP_UnitTestCase {
1818

19-
/**
20-
* User IDs for the test.
21-
*
22-
* @var array{administrator: int, editor: int, contributor: int}
23-
*/
24-
protected static $user_ids;
25-
26-
/**
27-
* Set up before class.
28-
*
29-
* @param WP_UnitTest_Factory $factory The Unit Test Factory.
30-
*/
31-
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
32-
self::$user_ids = array(
33-
'administrator' => $factory->user->create(
34-
array(
35-
'role' => 'administrator',
36-
)
37-
),
38-
'editor' => $factory->user->create(
39-
array(
40-
'role' => 'editor',
41-
)
42-
),
43-
'contributor' => $factory->user->create(
44-
array(
45-
'role' => 'contributor',
46-
)
47-
),
48-
);
49-
}
50-
5119
/**
5220
* Tests wp_delete_post reassign hierarchical post type.
5321
*/
@@ -120,9 +88,9 @@ public function test_wp_delete_post_short_circuit_on_post_id_zero() {
12088
}
12189

12290
/**
123-
* Tests wp_delete_post() when the post for the post_id has been already deleted.
91+
* Tests that wp_delete_post() returns null when the post has already been deleted.
12492
*/
125-
public function test_wp_delete_post_returns_false_for_invalid_post() {
93+
public function test_wp_delete_post_returns_null_for_already_deleted_post() {
12694
$post_id = self::factory()->post->create();
12795
$deleted_post = wp_delete_post( $post_id, true );
12896
$this->assertInstanceOf( WP_Post::class, $deleted_post );
@@ -163,7 +131,7 @@ static function () use ( $action, &$captured_action_args ) {
163131
$deleted_post = wp_delete_post( (string) $post_id, true );
164132
$this->assertInstanceOf( WP_Post::class, $deleted_post );
165133

166-
foreach ( array( 'before_delete_post', 'delete_post_post', 'delete_post', 'deleted_post_post', 'deleted_post', 'after_delete_post' ) as $action ) {
134+
foreach ( $actions as $action ) {
167135
$this->assertSame( $initial_action_counts[ $action ] + 1, did_action( $action ), "Expected $action action count to increment by 1." );
168136
$this->assertCount( 2, $captured_action_args[ $action ], "Expected count for $action action" );
169137
$this->assertSame( $post_id, $captured_action_args[ $action ][0], "Expected post ID for $action action" );
@@ -175,7 +143,7 @@ static function () use ( $action, &$captured_action_args ) {
175143
/**
176144
* Tests short-circuiting wp_delete_post() with pre_delete_post filter.
177145
*
178-
* @ticket @63975
146+
* @ticket 63975
179147
*/
180148
public function test_wp_delete_post_can_be_short_circuited() {
181149
$post_id = self::factory()->post->create();

0 commit comments

Comments
 (0)