实际上,您不能使用WP_UnitTestCase
, 因为在bootstrap.php
您已经将插件加载为mu-plugin
.
我建议您测试插件激活:调用do_action(\'activate_\' . FULL_ABSPATH_TO_YOUR_PLUGIN_PHP)
, 哪里FULL_ABSPATH_TO_YOUR_PLUGIN_PHP
将类似于:var/www/html/wordpress/wp-content/plugins/hello-world/hello-world.php
在本例中hello-world
插件吊销指定用户激活时的功能:
class ActivationEventTest extends WP_UnitTestCase {
const PLUGIN_BASENAME = \'var/www/html/wordpress/wp-content/plugins/hello-world/hello-world.php\';
public function testActivateWithSupport() {
$this->factory()->user->create( [
\'user_email\' => \'[email protected]\',
\'user_pass\' => \'reallyheavypasword\',
\'user_login\' => \'hello\',
\'user_role\' => 4,
\'role\' => 4
] );
do_action( \'activate_\' . static::PLUGIN_BASENAME );
$user = get_user_by( \'login\', \'hello\' );
$this->assertEmpty( $user->caps );
$this->assertEmpty( $user->roles );
}
}