Make WordPress Core

Ticket #30860: patch.diff

File patch.diff, 4.3 KB (added by sgrant, 10 years ago)

Unit tests and single change to return statement

  • src/wp-admin/includes/plugin.php

     
    884884        }
    885885
    886886        if ( empty( $plugins ) )
    887                 return;
     887                return array();
    888888
    889889        $invalid = array();
    890890
  • tests/phpunit/tests/admin/includesPlugin.php

     
    44 * @group admin
    55 */
    66class Tests_Admin_includesPlugin extends WP_UnitTestCase {
     7       
     8        private function _create_plugin( $data = "<?php\n/*\nPlugin Name: Test\n*/" ) {
     9                $name = rand_str() . '.php';
     10                $full_name = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . wp_unique_filename( WP_PLUGIN_DIR, $name );
     11
     12                $file = fopen( $full_name, 'w' );
     13                fwrite( $file, $data );
     14                fclose( $file );
     15
     16                return array( $name, $full_name );
     17        }
     18
    719        function test_get_plugin_data() {
    820                $data = get_plugin_data( DIR_TESTDATA . '/plugins/hello.php' );
    921
     
    6173                activate_plugin( 'hello.php' );
    6274                $test = is_plugin_active( 'hello.php' );
    6375                $this->assertTrue( $test );
     76
     77                deactivate_plugins( 'hello.php' );
    6478        }
    6579
    6680        function test_is_plugin_active_false() {
     
    7993                activate_plugin( 'hello.php' );
    8094                $test = is_plugin_inactive( 'hello.php' );
    8195                $this->assertFalse( $test );
     96
     97                deactivate_plugins( 'hello.php' );
    8298        }
     99
     100        /**
     101         * @covers ::get_plugin_files
     102         */
     103        function test_get_plugin_files_single() {
     104                $name = 'hello.php';
     105                $this->assertEquals( array( $name ), get_plugin_files( $name ) );
     106        }
     107
     108        /**
     109         * @covers ::get_mu_plugins
     110         */
     111        function test_get_mu_plugins_empty() {
     112                $this->assertEquals( array(), get_mu_plugins() );
     113        }
     114
     115        /**
     116         * @covers ::_sort_uname_callback
     117         */
     118        function test_sort_uname_callback() {
     119                $this->assertLessThan( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'b' ) ) );
     120                $this->assertGreaterThan( 0, _sort_uname_callback( array( 'Name' => 'c' ), array( 'Name' => 'b' ) ) );
     121                $this->assertEquals( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'a' ) ) );
     122        }
     123
     124        /**
     125         * @covers ::get_dropins
     126         */
     127        function test_get_dropins_empty() {
     128                $this->assertEquals( array(), get_dropins() );
     129        }
     130
     131        /**
     132         * @covers ::_get_dropins
     133         */
     134        function test_get_dropins_not_empty() {
     135                $this->assertGreaterThan( 0, get_dropins() );
     136        }
     137
     138        /**
     139         * @covers ::is_network_only_plugin
     140         */
     141        function test_is_network_only_plugin_hello() {
     142                $this->assertFalse( is_network_only_plugin( 'hello.php' ) );
     143        }
     144
     145        /**
     146         * @covers ::activate_plugins
     147         */
     148        function test_activate_plugins_single_no_array() {
     149            $name = 'hello.php';
     150                activate_plugins( $name );
     151                $this->assertTrue( is_plugin_active( $name ) );
     152                deactivate_plugins( $name );
     153        }
     154
     155        /**
     156         * @covers ::activate_plugins
     157         */
     158        function test_activate_plugins_single_array() {
     159            $name = 'hello.php';
     160                activate_plugins( array( $name ) );
     161                $this->assertTrue( is_plugin_active( $name ) );
     162                deactivate_plugins( $name );
     163        }
     164
     165        /**
     166         * @covers ::validate_active_plugins
     167         */
     168        function test_validate_active_plugins_empty() {
     169                $this->assertEquals( array(), validate_active_plugins() );
     170        }
     171
     172        /**
     173         * @covers ::validate_active_plugins
     174         */
     175        function test_validate_active_plugins_remove_invalid() {
     176                $plugin = $this->_create_plugin();
     177
     178                activate_plugin( $plugin[ 0 ] );
     179                unlink( $plugin[ 1 ] );
     180
     181                $result = validate_active_plugins();
     182                $this->assertTrue( isset( $result[ $plugin[ 0 ] ] ) );
     183        }
     184
     185        /**
     186         * @covers ::is_uninstallable_plugin
     187         */
     188        function test_is_uninstallable_plugin() {
     189                $this->assertFalse( is_uninstallable_plugin( 'hello' ) );
     190        }
     191
     192        /**
     193         * @covers ::is_uninstallable_plugin
     194         */
     195        function test_is_uninstallable_plugin_true() {
     196                $plugin = $this->_create_plugin();
     197
     198                $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
     199                $uninstallable_plugins[ $plugin[ 0 ] ] = TRUE;
     200                update_option( 'uninstall_plugins', $uninstallable_plugins );
     201
     202                $this->assertTrue( is_uninstallable_plugin( $plugin[ 0 ] ) );
     203
     204                unset( $uninstallable_plugins[ $plugin[ 0 ] ] );
     205                update_option( 'uninstall_plugins', $uninstallable_plugins );           
     206
     207                unlink( $plugin[ 1 ] );
     208        }
     209       
    83210}