Make WordPress Core

Opened 15 months ago

Closed 15 months ago

Last modified 15 months ago

#61851 closed enhancement (fixed)

Unit tests should typically not use `wp_delete_user()` to delete users for multisite compatibility

Reported by: flixos90's profile flixos90 Owned by: flixos90's profile flixos90
Milestone: 6.7 Priority: low
Severity: minor Version:
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: multisite Cc:

Description

Several PHPUnit tests rely on wp_delete_user() to delete temporarily created users. However, when using WordPress Multisite, wpmu_delete_user() needs to be used instead. For this purpose, the WordPress test base class provides a static method delete_user( $user_id ), which abstracts away this detail.

All PHPUnit tests should use this static method instead of wp_delete_user(), unless the test is explicitly excluding multisite or testing a behavior of wp_delete_user() with consideration of how it behaves differently with a multisite network.

Change History (3)

This ticket was mentioned in PR #7175 on WordPress/wordpress-develop by @flixos90.


15 months ago
#1

  • Keywords has-patch has-unit-tests added; needs-patch removed

#2 @flixos90
15 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58876:

Build/Test Tools: Avoid using wp_delete_user() in PHPUnit tests unless explicitly acknowledging or ignoring Multisite.

wp_delete_user() does not actually delete the entire user when using WordPress Multisite. Therefore tests should typically use the test helper method to fully delete the user, unless explicitly ignoring Multisite or testing the wp_delete_user() function while taking Multisite behavior into account.

Fixes #61851.

Note: See TracTickets for help on using tickets.