Make WordPress Core

Changeset 31009


Ignore:
Timestamp:
12/31/2014 03:00:32 PM (10 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesPlugin.php

    r31003 r31009  
    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
     
    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 );
     
    240247        unlink( $p1[1] );
    241248        unlink( $p2[1] );
     249
     250        // Clean up.
     251        $this->_restore_drop_ins();
    242252    }
    243253
     
    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}
Note: See TracChangeset for help on using the changeset viewer.