mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
tests/phpunit/tests/admin/includes/wpGetPluginActionButton.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/** | ||
* Tests for wp_get_plugin_action_button(). | ||
* | ||
* @group plugins | ||
* @group admin | ||
* | ||
* @covers ::wp_get_plugin_action_button | ||
*/ | ||
class Tests_Admin_Includes_WpGetPluginActionButton extends WP_UnitTestCase { | ||
|
||
/** | ||
* Administrator user ID. | ||
* | ||
* @var int | ||
*/ | ||
private static $admin_user_id; | ||
|
||
/** | ||
* Test plugin data. | ||
* | ||
* @var stdClass | ||
*/ | ||
private static $test_plugin; | ||
|
||
/** | ||
* Sets up properties and adds a test plugin before any tests run. | ||
*/ | ||
public static function set_up_before_class() { | ||
parent::set_up_before_class(); | ||
|
||
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | ||
|
||
self::$admin_user_id = self::factory()->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', | ||
"<?php\n/**\n* Plugin Name: " . self::$test_plugin->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.' ); | ||
} | ||
} |