Make WordPress Core

Ticket #30860: 30860.diff

File 30860.diff, 2.5 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..9ed1ee4 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                $files_to_move = array();
     443                $_get_dropins = _get_dropins();
     444                if ( $dropins = opendir( WP_CONTENT_DIR ) ) {
     445                        while ( false !== $dropin = readdir( $dropins ) ) {
     446                                if ( 0 !== strpos( $dropin, '.' ) && array_key_exists( $dropin, $_get_dropins ) ) {
     447                                        $files_to_move[] = $dropin;
     448                                }
     449                        }
     450                }
     451
     452                @closedir( $dropins );
     453
     454                foreach ( $files_to_move as $file_to_move ) {
     455                        $f = rename( WP_CONTENT_DIR . '/' . $file_to_move, $di_bu_dir . '/' . $file_to_move );
     456                }
     457        }
     458
     459        /**
     460         * Restore backed-up drop-ins.
     461         *
     462         * @since 4.2.0
     463         *
     464         * @access private
     465         */
     466        private function _restore_drop_ins() {
     467                $di_bu_dir = WP_CONTENT_DIR . '/drop-ins-backup';
     468
     469                $files_to_move = array();
     470                if ( is_dir( $di_bu_dir ) && $dropins = opendir( $di_bu_dir ) ) {
     471                        while ( false !== $dropin = readdir( $dropins ) ) {
     472                                if ( 0 !== strpos( $dropin, '.' ) ) {
     473                                        $files_to_move[] = $dropin;
     474                                }
     475                        }
     476                }
     477
     478                @closedir( $di_bu_dir );
     479
     480                foreach ( $files_to_move as $file_to_move ) {
     481                        rename( $di_bu_dir . '/' . $file_to_move, WP_CONTENT_DIR . '/' . $file_to_move );
     482                }
     483
     484                if ( is_dir( $di_bu_dir ) ) {
     485                        rmdir( $di_bu_dir );
     486                }
     487        }
    418488}