如果你有phpUnitconfigured for testing a WP plugin, 您可以使用如下测试用例:
在您的plugin-directory/tests/Some_Test_Case.php
:
class Plugin_Test extends WP_UnitTestCase {
/**
* @dataProvider post_IDs_and_expected_results
*/
public function test_something( $post_id, $expected_result ) {
global $post;
$post = get_post( $post_id );
$plugin_content = call_plugin_function(); // Your function name here
$this->assertEquals( $expected_result, $plugin_content, "Content OK for post $post_id" );
}
public function post_IDs_and_expected_results() {
return array(
array( 1, \'expected result for post_id = 1\' ),
array( 2, \'expected result for post_id = 2\' )
);
}
}
插件目录中的命令行:phpunit ./tests/Some_Test_Case.php