wordpress-develop/tests/phpunit/tests/xmlrpc/wp/newComment.php
Gary Pendergast 8f95800d52 Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
2017-11-30 23:09:33 +00:00

99 lines
2.0 KiB
PHP

<?php
/**
* @group xmlrpc
*/
class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase {
function test_valid_comment() {
$this->make_user_by_role( 'administrator' );
$post = self::factory()->post->create_and_get();
$result = $this->myxmlrpcserver->wp_newComment(
array(
1,
'administrator',
'administrator',
$post->ID,
array(
'content' => rand_str( 100 ),
),
)
);
$this->assertNotIXRError( $result );
}
function test_empty_comment() {
$this->make_user_by_role( 'administrator' );
$post = self::factory()->post->create_and_get();
$result = $this->myxmlrpcserver->wp_newComment(
array(
1,
'administrator',
'administrator',
$post->ID,
array(
'content' => '',
),
)
);
$this->assertIXRError( $result );
$this->assertEquals( 403, $result->code );
}
function test_new_comment_post_closed() {
$this->make_user_by_role( 'administrator' );
$post = self::factory()->post->create_and_get(
array(
'comment_status' => 'closed',
)
);
$this->assertEquals( 'closed', $post->comment_status );
$result = $this->myxmlrpcserver->wp_newComment(
array(
1,
'administrator',
'administrator',
$post->ID,
array(
'content' => rand_str( 100 ),
),
)
);
$this->assertIXRError( $result );
$this->assertEquals( 403, $result->code );
}
function test_new_comment_duplicated() {
$this->make_user_by_role( 'administrator' );
$post = self::factory()->post->create_and_get();
$comment_args = array(
1,
'administrator',
'administrator',
$post->ID,
array(
'content' => rand_str( 100 ),
),
);
// First time it's a valid comment
$result = $this->myxmlrpcserver->wp_newComment( $comment_args );
$this->assertNotIXRError( $result );
// Run second time for duplication error
$result = $this->myxmlrpcserver->wp_newComment( $comment_args );
$this->assertIXRError( $result );
$this->assertEquals( 403, $result->code );
}
}