From e9bcac0b250c1477f9eac97eda239d1eb0717fd7 Mon Sep 17 00:00:00 2001 From: roshniahuja Date: Thu, 16 Jul 2026 23:00:18 +0530 Subject: [PATCH] Privacy: Add unit tests for wp_schedule_delete_old_privacy_export_files(). Add test coverage for the three branches of the function: scheduling the `wp_privacy_delete_old_export_files` event when it is not yet scheduled, skipping scheduling while WordPress is installing, and not creating a duplicate event when one is already scheduled. See #59707. --- .../wpScheduleDeleteOldPrivacyExportFiles.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpScheduleDeleteOldPrivacyExportFiles.php diff --git a/tests/phpunit/tests/functions/wpScheduleDeleteOldPrivacyExportFiles.php b/tests/phpunit/tests/functions/wpScheduleDeleteOldPrivacyExportFiles.php new file mode 100644 index 0000000000000..17c06473b692c --- /dev/null +++ b/tests/phpunit/tests/functions/wpScheduleDeleteOldPrivacyExportFiles.php @@ -0,0 +1,74 @@ +assertFalse( wp_next_scheduled( 'wp_privacy_delete_old_export_files' ), 'The event should not be scheduled before the function runs.' ); + + wp_schedule_delete_old_privacy_export_files(); + + $this->assertIsInt( wp_next_scheduled( 'wp_privacy_delete_old_export_files' ), 'The event should be scheduled after the function runs.' ); + } + + /** + * Tests that no event is scheduled while WordPress is installing. + * + * @ticket 59707 + */ + public function test_wp_schedule_delete_old_privacy_export_files_is_installing() { + wp_installing( true ); + + $this->assertFalse( wp_next_scheduled( 'wp_privacy_delete_old_export_files' ), 'The event should not be scheduled before the function runs.' ); + + wp_schedule_delete_old_privacy_export_files(); + + $this->assertFalse( wp_next_scheduled( 'wp_privacy_delete_old_export_files' ), 'The event should not be scheduled while WordPress is installing.' ); + } + + /** + * Tests that calling the function again does not create a duplicate event. + * + * @ticket 59707 + */ + public function test_wp_schedule_delete_old_privacy_export_files_already_scheduled() { + wp_schedule_delete_old_privacy_export_files(); + $first = wp_next_scheduled( 'wp_privacy_delete_old_export_files' ); + + wp_schedule_delete_old_privacy_export_files(); + + $this->assertSame( $first, wp_next_scheduled( 'wp_privacy_delete_old_export_files' ), 'Calling the function again should not reschedule the event.' ); + } +}