diff --git a/tests/phpunit/tests/admin/pluginUpgraderSkin.php b/tests/phpunit/tests/admin/pluginUpgraderSkin.php new file mode 100644 index 0000000000000..3f4e96caf03b4 --- /dev/null +++ b/tests/phpunit/tests/admin/pluginUpgraderSkin.php @@ -0,0 +1,386 @@ +user->create( array( 'role' => 'administrator' ) ); + + if ( is_multisite() ) { + grant_super_admin( self::$admin_id ); + } + } + + /** + * Revokes the super admin fixture. + */ + public static function wpTearDownAfterClass() { + if ( is_multisite() ) { + revoke_super_admin( self::$admin_id ); + } + } + + /** + * Clears the plugins cache. + */ + public function tear_down() { + wp_cache_delete( 'plugins', 'plugins' ); + + parent::tear_down(); + } + + /** + * Tests the defaults of the skin. + * + * @ticket 66551 + * + * @covers Plugin_Upgrader_Skin::__construct + */ + public function test_constructor_should_use_defaults() { + $skin = new Plugin_Upgrader_Skin(); + + $this->assertSame( 'Update Plugin', $skin->options['title'], 'The title should be set.' ); + $this->assertSame( '', $skin->options['url'], 'The URL should be empty.' ); + $this->assertSame( '', $skin->options['nonce'], 'The nonce should be empty.' ); + $this->assertSame( '', $skin->plugin, 'The plugin should be empty.' ); + $this->assertFalse( $skin->plugin_active, 'The plugin should not be active.' ); + $this->assertFalse( $skin->plugin_network_active, 'The plugin should not be network active.' ); + } + + /** + * Tests that the arguments override the defaults. + * + * @ticket 66551 + * + * @covers Plugin_Upgrader_Skin::__construct + */ + public function test_constructor_should_use_arguments() { + $skin = new Plugin_Upgrader_Skin( + array( + 'url' => 'update.php?action=upgrade-plugin', + 'plugin' => self::PLUGIN, + 'nonce' => 'upgrade-plugin_' . self::PLUGIN, + 'title' => 'My title', + ) + ); + + $this->assertSame( 'update.php?action=upgrade-plugin', $skin->options['url'] ); + $this->assertSame( 'upgrade-plugin_' . self::PLUGIN, $skin->options['nonce'] ); + $this->assertSame( 'My title', $skin->options['title'] ); + $this->assertSame( self::PLUGIN, $skin->plugin ); + } + + /** + * Tests that the skin knows when the plugin is active. + * + * @ticket 66551 + * + * @covers Plugin_Upgrader_Skin::__construct + */ + public function test_constructor_should_detect_an_active_plugin() { + update_option( 'active_plugins', array( self::PLUGIN ) ); + + $skin = new Plugin_Upgrader_Skin( array( 'plugin' => self::PLUGIN ) ); + + $this->assertTrue( $skin->plugin_active, 'The plugin should be active.' ); + $this->assertFalse( $skin->plugin_network_active, 'The plugin should not be network active.' ); + } + + /** + * Tests that the skin knows when the plugin is active for the network. + * + * @ticket 66551 + * + * @group ms-required + * + * @covers Plugin_Upgrader_Skin::__construct + */ + public function test_constructor_should_detect_a_network_active_plugin() { + update_site_option( 'active_sitewide_plugins', array( self::PLUGIN => time() ) ); + + $skin = new Plugin_Upgrader_Skin( array( 'plugin' => self::PLUGIN ) ); + + $this->assertTrue( $skin->plugin_active, 'A network active plugin should be active.' ); + $this->assertTrue( $skin->plugin_network_active, 'The plugin should be network active.' ); + } + + /** + * Tests that an active plugin is activated again in a frame after it is updated. + * + * @ticket 66551 + * + * @covers Plugin_Upgrader_Skin::after + */ + public function test_after_should_reactivate_an_active_plugin_in_a_frame() { + wp_set_current_user( self::$admin_id ); + update_option( 'active_plugins', array( self::PLUGIN ) ); + + $output = $this->run_after( $this->get_skin( true ) ); + + $this->assertStringContainsString( '