From be2ea9b9f9b06bb69667145759b2f3afd9167f02 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 31 Dec 2014 15:00:32 +0000 Subject: [PATCH] Back up and restore dropins during `get_dropins()` tests. This change ensures that the `get_dropins()` tests don't detect any actual dropins that you might be running on your develop.wordpress installation. Props valendesigns. Fixes #30860. git-svn-id: https://develop.svn.wordpress.org/trunk@31009 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/admin/includesPlugin.php | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/phpunit/tests/admin/includesPlugin.php b/tests/phpunit/tests/admin/includesPlugin.php index b6dd5c2614..15afaef1b6 100644 --- a/tests/phpunit/tests/admin/includesPlugin.php +++ b/tests/phpunit/tests/admin/includesPlugin.php @@ -224,13 +224,20 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase { * @covers ::get_dropins */ public function test_get_dropins_empty() { + $this->_back_up_drop_ins(); + $this->assertEquals( array(), get_dropins() ); + + // Clean up. + $this->_restore_drop_ins(); } /** * @covers ::get_dropins */ public function test_get_dropins_not_empty() { + $this->_back_up_drop_ins(); + $p1 = $this->_create_plugin( "_create_plugin( "_restore_drop_ins(); } /** @@ -415,4 +425,45 @@ class Tests_Admin_includesPlugin extends WP_UnitTestCase { rmdir( $mu_bu_dir ); } } + + /** + * Move existing drop-ins to wp-content/drop-ins-backup. + * + * @since 4.2.0 + * + * @access private + */ + private function _back_up_drop_ins() { + $di_bu_dir = WP_CONTENT_DIR . '/drop-ins-backup'; + if ( ! is_dir( $di_bu_dir ) ) { + mkdir( $di_bu_dir ); + } + + foreach( _get_dropins() as $file_to_move => $v ) { + if ( file_exists( WP_CONTENT_DIR . '/' . $file_to_move ) ) { + rename( WP_CONTENT_DIR . '/' . $file_to_move, $di_bu_dir . '/' . $file_to_move ); + } + } + } + + /** + * Restore backed-up drop-ins. + * + * @since 4.2.0 + * + * @access private + */ + private function _restore_drop_ins() { + $di_bu_dir = WP_CONTENT_DIR . '/drop-ins-backup'; + + foreach( _get_dropins() as $file_to_move => $v ) { + if ( file_exists( $di_bu_dir . '/' . $file_to_move ) ) { + rename( $di_bu_dir . '/' . $file_to_move, WP_CONTENT_DIR . '/' . $file_to_move ); + } + } + + if ( is_dir( $di_bu_dir ) ) { + rmdir( $di_bu_dir ); + } + } }