Make WordPress Core

Ticket #30860: 30860.1.diff

File 30860.1.diff, 2.1 KB (added by valendesigns, 10 years ago)
  • tests/phpunit/tests/admin/includesPlugin.php

    diff --git tests/phpunit/tests/admin/includesPlugin.php tests/phpunit/tests/admin/includesPlugin.php
    index b6dd5c2..0bf6fef 100644
    class Tests_Admin_includesPlugin extends WP_UnitTestCase { 
    224224         * @covers ::get_dropins
    225225         */
    226226        public function test_get_dropins_empty() {
     227                $this->_back_up_drop_ins();
     228               
    227229                $this->assertEquals( array(), get_dropins() );
     230               
     231                // Clean up.
     232                $this->_restore_drop_ins();
    228233        }
    229234
    230235        /**
    231236         * @covers ::get_dropins
    232237         */
    233238        public function test_get_dropins_not_empty() {
     239                $this->_back_up_drop_ins();
     240               
    234241                $p1 = $this->_create_plugin( "<?php\n//Test", 'advanced-cache.php', WP_CONTENT_DIR );
    235242                $p2 = $this->_create_plugin( "<?php\n//Test", 'not-a-dropin.php', WP_CONTENT_DIR );
    236243
    class Tests_Admin_includesPlugin extends WP_UnitTestCase { 
    239246
    240247                unlink( $p1[1] );
    241248                unlink( $p2[1] );
     249
     250                // Clean up.
     251                $this->_restore_drop_ins();
    242252        }
    243253
    244254        /**
    class Tests_Admin_includesPlugin extends WP_UnitTestCase { 
    415425                        rmdir( $mu_bu_dir );
    416426                }
    417427        }
     428       
     429        /**
     430         * Move existing drop-ins to wp-content/drop-ins-backup.
     431         *
     432         * @since 4.2.0
     433         *
     434         * @access private
     435         */
     436        private function _back_up_drop_ins() {
     437                $di_bu_dir = WP_CONTENT_DIR . '/drop-ins-backup';
     438                if ( ! is_dir( $di_bu_dir ) ) {
     439                        mkdir( $di_bu_dir );
     440                }
     441
     442                foreach( _get_dropins() as $file_to_move => $v ) {
     443                        if ( file_exists( WP_CONTENT_DIR . '/' . $file_to_move ) ) {
     444                                rename( WP_CONTENT_DIR . '/' . $file_to_move, $di_bu_dir . '/' . $file_to_move );
     445                        }
     446                }
     447        }
     448
     449        /**
     450         * Restore backed-up drop-ins.
     451         *
     452         * @since 4.2.0
     453         *
     454         * @access private
     455         */
     456        private function _restore_drop_ins() {
     457                $di_bu_dir = WP_CONTENT_DIR . '/drop-ins-backup';
     458
     459                foreach( _get_dropins() as $file_to_move => $v ) {
     460                        if ( file_exists( $di_bu_dir . '/' . $file_to_move ) ) {
     461                                rename( $di_bu_dir . '/' . $file_to_move, WP_CONTENT_DIR . '/' . $file_to_move );
     462                        }
     463                }
     464
     465                if ( is_dir( $di_bu_dir ) ) {
     466                        rmdir( $di_bu_dir );
     467                }
     468        }
    418469}