diff --git a/tests/phpunit/tests/fonts/font-library/fontLibraryHooks.php b/tests/phpunit/tests/fonts/font-library/fontLibraryHooks.php index 3850c4fd1be05..5dcda986145a1 100644 --- a/tests/phpunit/tests/fonts/font-library/fontLibraryHooks.php +++ b/tests/phpunit/tests/fonts/font-library/fontLibraryHooks.php @@ -10,6 +10,15 @@ */ class Tests_Fonts_FontLibraryHooks extends WP_UnitTestCase { + /** + * Tear down the test fixture. + */ + public function tear_down() { + // Remove all fonts uploaded during the tests. + $this->remove_added_uploads(); + parent::tear_down(); + } + public function test_deleting_font_family_deletes_child_font_faces() { $font_family_id = self::factory()->post->create( array( diff --git a/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php b/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php index 8d66243668c46..79c1937f6cfa0 100644 --- a/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php +++ b/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php @@ -461,6 +461,9 @@ function ( $font_dir ) { // Delete the post. wp_delete_post( $data['id'], true ); $this->assertFileDoesNotExist( $expected_file_path, 'The font file should have been deleted when the post was deleted.' ); + + // Clean up: Delete the subdir test directory. + rmdir( WP_CONTENT_DIR . '/uploads/fonts/subdir' ); } /** diff --git a/tests/phpunit/tests/user/getActiveBlogForUser.php b/tests/phpunit/tests/user/getActiveBlogForUser.php index ef3e5e6eff6d0..87e80ae950772 100644 --- a/tests/phpunit/tests/user/getActiveBlogForUser.php +++ b/tests/phpunit/tests/user/getActiveBlogForUser.php @@ -69,7 +69,14 @@ public function test_get_active_blog_for_user_without_primary_site() { $result = get_active_blog_for_user( self::$user_id ); - wp_delete_site( $primary_site_id ); + /* + * Avoid using wp_delete_site() here because it will delete the uploads + * directory without checking if the site is the main one. Otherwise, + * when this test runs in a single site environment (e.g. when running + * grunt precommit), it will delete the entire contents of the uploads + * directory, which we want to avoid. + */ + wpmu_delete_blog( $primary_site_id, true ); $this->assertSame( $primary_site_id, $result->id ); }