diff --git a/tests/phpunit/tests/admin/includes/wpGetPluginActionButton.php b/tests/phpunit/tests/admin/includes/wpGetPluginActionButton.php new file mode 100644 index 0000000000000..2082399ee42d3 --- /dev/null +++ b/tests/phpunit/tests/admin/includes/wpGetPluginActionButton.php @@ -0,0 +1,92 @@ +user->create( array( 'role' => 'administrator' ) ); + self::$test_plugin = (object) array( + 'name' => 'My Plugin', + 'slug' => 'my-plugin', + 'version' => '1.0.0', + ); + + mkdir( WP_PLUGIN_DIR . '/' . self::$test_plugin->slug ); + file_put_contents( + WP_PLUGIN_DIR . '/' . self::$test_plugin->slug . '/my_plugin.php', + "name . "\n* Version: " . self::$test_plugin->version . "\n*/" + ); + } + + /** + * Removes the test plugin and its directory after all tests run. + */ + public static function tear_down_after_class() { + parent::tear_down_after_class(); + + unlink( WP_PLUGIN_DIR . '/' . self::$test_plugin->slug . '/my_plugin.php' ); + rmdir( WP_PLUGIN_DIR . '/' . self::$test_plugin->slug ); + } + + /** + * Tests that an empty string is returned when the user does not have the + * correct capabilities. + * + * @ticket + */ + public function test_should_return_empty_string_without_proper_capabilities() { + $actual = wp_get_plugin_action_button( + self::$test_plugin->name, + self::$test_plugin, + true, + true + ); + $this->assertSame( '', $actual, 'No button markup should be returned.' ); + } + + /** + * Tests that an empty string is not returned when the user has the + * correct capabilities. + * + * @ticket + */ + public function test_should_not_return_empty_string_with_proper_capabilities() { + wp_set_current_user( self::$admin_user_id ); + + $actual = wp_get_plugin_action_button( + self::$test_plugin->name, + self::$test_plugin, + true, + true + ); + $this->assertNotSame( '', $actual, 'Button markup should be returned.' ); + } +}