Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#61851 closed enhancement (fixed)

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

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

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.


2 years ago
#1

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

#2 @flixos90
2 years ago

  • Resolution → fixed
  • Status assigned → 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.