mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Build/Test Tools: Re-use a bunch of fixtures in test classes for user and XMLRPC tests.
Shaves a couple of seconds off of the tests. See #30017, #38716 git-svn-id: https://develop.svn.wordpress.org/trunk@39189 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -4,39 +4,37 @@
|
||||
* @group xmlrpc
|
||||
*/
|
||||
class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase {
|
||||
var $post_id;
|
||||
var $parent_comment_id;
|
||||
var $parent_comment_data;
|
||||
var $child_comment_id;
|
||||
var $child_comment_data;
|
||||
protected static $post_id;
|
||||
protected static $parent_comment_id;
|
||||
protected static $parent_comment_data;
|
||||
protected static $child_comment_id;
|
||||
protected static $child_comment_data;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
|
||||
self::$post_id = $factory->post->create();
|
||||
|
||||
$this->post_id = self::factory()->post->create();
|
||||
|
||||
$this->parent_comment_data = array(
|
||||
'comment_post_ID' => $this->post_id,
|
||||
self::$parent_comment_data = array(
|
||||
'comment_post_ID' => self::$post_id,
|
||||
'comment_author' => 'Test commenter',
|
||||
'comment_author_url' => 'http://example.com/',
|
||||
'comment_author_email' => 'example@example.com',
|
||||
'comment_content' => rand_str( 100 ),
|
||||
);
|
||||
$this->parent_comment_id = wp_insert_comment( $this->parent_comment_data );
|
||||
self::$parent_comment_id = wp_insert_comment( self::$parent_comment_data );
|
||||
|
||||
$this->child_comment_data = array(
|
||||
'comment_post_ID' => $this->post_id,
|
||||
self::$child_comment_data = array(
|
||||
'comment_post_ID' => self::$post_id,
|
||||
'comment_author' => 'Test commenter 2',
|
||||
'comment_author_url' => 'http://example.org/',
|
||||
'comment_author_email' => 'example@example.org',
|
||||
'comment_parent' => $this->parent_comment_id,
|
||||
'comment_parent' => self::$parent_comment_id,
|
||||
'comment_content' => rand_str( 100 )
|
||||
);
|
||||
$this->child_comment_id = wp_insert_comment( $this->child_comment_data );
|
||||
self::$child_comment_id = wp_insert_comment( self::$child_comment_data );
|
||||
}
|
||||
|
||||
function test_invalid_username_password() {
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'username', 'password', $this->parent_comment_id ) );
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'username', 'password', self::$parent_comment_id ) );
|
||||
$this->assertInstanceOf( 'IXR_Error', $result );
|
||||
$this->assertEquals( 403, $result->code );
|
||||
}
|
||||
@@ -44,7 +42,7 @@ class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase {
|
||||
function test_incapable_user() {
|
||||
$this->make_user_by_role( 'contributor' );
|
||||
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'contributor', 'contributor', $this->parent_comment_id ) );
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'contributor', 'contributor', self::$parent_comment_id ) );
|
||||
$this->assertInstanceOf( 'IXR_Error', $result );
|
||||
$this->assertEquals( 403, $result->code );
|
||||
}
|
||||
@@ -52,7 +50,7 @@ class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase {
|
||||
function test_valid_comment() {
|
||||
$this->make_user_by_role( 'editor' );
|
||||
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->parent_comment_id ) );
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$parent_comment_id ) );
|
||||
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
||||
|
||||
// Check data types
|
||||
@@ -76,23 +74,23 @@ class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase {
|
||||
$this->assertStringMatchesFormat( '%d', $result['comment_id'] );
|
||||
$this->assertStringMatchesFormat( '%d', $result['parent'] );
|
||||
$this->assertStringMatchesFormat( '%d', $result['post_id'] );
|
||||
$this->assertEquals( $this->parent_comment_id, $result['comment_id'] );
|
||||
$this->assertEquals( self::$parent_comment_id, $result['comment_id'] );
|
||||
$this->assertEquals( 0, $result['parent'] );
|
||||
$this->assertEquals( $this->parent_comment_data['comment_content'], $result['content'] );
|
||||
$this->assertEquals( $this->post_id, $result['post_id'] );
|
||||
$this->assertEquals( $this->parent_comment_data['comment_author'], $result['author'] );
|
||||
$this->assertEquals( $this->parent_comment_data['comment_author_url'], $result['author_url'] );
|
||||
$this->assertEquals( $this->parent_comment_data['comment_author_email'], $result['author_email'] );
|
||||
$this->assertEquals( self::$parent_comment_data['comment_content'], $result['content'] );
|
||||
$this->assertEquals( self::$post_id, $result['post_id'] );
|
||||
$this->assertEquals( self::$parent_comment_data['comment_author'], $result['author'] );
|
||||
$this->assertEquals( self::$parent_comment_data['comment_author_url'], $result['author_url'] );
|
||||
$this->assertEquals( self::$parent_comment_data['comment_author_email'], $result['author_email'] );
|
||||
}
|
||||
|
||||
function test_valid_child_comment() {
|
||||
$this->make_user_by_role( 'editor' );
|
||||
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->child_comment_id ) );
|
||||
$result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$child_comment_id ) );
|
||||
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
||||
|
||||
$this->assertEquals( $this->child_comment_id, $result['comment_id'] );
|
||||
$this->assertEquals( $this->parent_comment_id, $result['parent'] );
|
||||
$this->assertEquals( self::$child_comment_id, $result['comment_id'] );
|
||||
$this->assertEquals( self::$parent_comment_id, $result['parent'] );
|
||||
}
|
||||
|
||||
function test_invalid_id() {
|
||||
|
||||
Reference in New Issue
Block a user