Docs: Improve documentation for Ajax comment tests per the documentation standards.

See #49572.

git-svn-id: https://develop.svn.wordpress.org/trunk@48220 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-06-30 00:41:30 +00:00
parent 6c81fa8a73
commit 6dca33c0b1
6 changed files with 131 additions and 173 deletions

View File

@ -39,7 +39,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
}
/**
* Set up the test fixture
* Sets up the test fixture.
*/
public function setUp() {
parent::setUp();
@ -48,9 +48,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
}
/**
* Test autosaving a post
*
* @return void
* Tests autosaving a post.
*/
public function test_autosave_post() {
// The original post_author.
@ -91,9 +89,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
}
/**
* Test autosaving a locked post
*
* @return void
* Tests autosaving a locked post.
*/
public function test_autosave_locked_post() {
// Lock the post to another user.
@ -144,9 +140,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
}
/**
* Test with an invalid nonce
*
* @return void
* Tests with an invalid nonce.
*/
public function test_with_invalid_nonce() {

View File

@ -16,7 +16,7 @@ require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
/**
* List of comments
* List of comments.
*
* @var array
*/
@ -37,7 +37,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Clear the POST actions in between requests
* Clears the POST actions in between requests.
*/
protected function _clear_post_action() {
unset( $_POST['trash'] );
@ -53,12 +53,12 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
*/
/**
* Test as a privilged user (administrator)
* Expects test to pass
* Tests as a privileged user (administrator).
*
* @param mixed $comment Comment object
* @param string action trash, untrash, etc.
* @return void
* Expects test to pass.
*
* @param WP_Comment $comment Comment object.
* @param string $action Action: 'trash', 'untrash', etc.
*/
public function _test_as_admin( $comment, $action ) {
@ -112,12 +112,12 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Test as a non-privileged user (subscriber)
* Expects test to fail
* Tests as a non-privileged user (subscriber).
*
* @param mixed $comment Comment object
* @param string action trash, untrash, etc.
* @return void
* Expects test to fail.
*
* @param WP_Comment $comment Comment object.
* @param string $action Action: 'trash', 'untrash', etc.
*/
public function _test_as_subscriber( $comment, $action ) {
@ -143,12 +143,12 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
/**
* Test with a bad nonce
* Expects test to fail
* Tests with a bad nonce.
*
* @param mixed $comment Comment object
* @param string action trash, untrash, etc.
* @return void
* Expects test to fail.
*
* @param WP_Comment $comment Comment object.
* @param string $action Action: 'trash', 'untrash', etc.
*/
public function _test_with_bad_nonce( $comment, $action ) {
@ -173,12 +173,12 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Test with a bad id
* Expects test to fail
* Tests with a bad ID.
*
* @param mixed $comment Comment object
* @param string action trash, untrash, etc.
* @return void
* Expects test to fail.
*
* @param WP_Comment $comment Comment object.
* @param string $action Action: 'trash', 'untrash', etc.
*/
public function _test_with_bad_id( $comment, $action ) {
@ -210,12 +210,12 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Test doubling the action (e.g. trash a trashed comment)
* Expects test to fail
* Tests doubling the action (e.g. trash a trashed comment).
*
* @param mixed $comment Comment object
* @param string action trash, untrash, etc.
* @return void
* Expects test to fail.
*
* @param WP_Comment $comment Comment object.
* @param string $action Action: 'trash', 'untrash', etc.
*/
public function _test_double_action( $comment, $action ) {
@ -260,9 +260,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Delete a comment as an administrator (expects success)
*
* @return void
* Deletes a comment as an administrator (expects success).
*/
public function test_ajax_comment_trash_actions_as_administrator() {
// Test trash/untrash.
@ -278,9 +276,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Delete a comment as a subscriber (expects permission denied)
*
* @return void
* Deletes a comment as a subscriber (expects permission denied).
*/
public function test_ajax_comment_trash_actions_as_subscriber() {
// Test trash/untrash.
@ -296,9 +292,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Delete a comment with no id
*
* @return void
* Deletes a comment with no ID.
*/
public function test_ajax_trash_comment_no_id() {
// Test trash/untrash.
@ -314,9 +308,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Delete a comment with a bad nonce
*
* @return void
* Deletes a comment with a bad nonce.
*/
public function test_ajax_trash_comment_bad_nonce() {
// Test trash/untrash.
@ -332,9 +324,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
}
/**
* Test trashing an already trashed comment, etc.
*
* @return void
* Tests trashing an already trashed comment, etc.
*/
public function test_ajax_trash_double_action() {
// Test trash/untrash.

View File

@ -16,14 +16,14 @@ require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
/**
* List of comments
* List of comments.
*
* @var array
*/
protected $_comments = array();
/**
* Set up the test fixture
* Sets up the test fixture.
*/
public function setUp() {
parent::setUp();
@ -33,7 +33,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Clear the POST actions in between requests
* Clears the POST actions in between requests.
*/
protected function _clear_post_action() {
unset( $_POST['id'] );
@ -46,11 +46,11 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
*/
/**
* Test as a privilged user (administrator)
* Expects test to pass
* Tests as a privileged user (administrator).
*
* @param mixed $comment Comment object
* @return void
* Expects test to pass.
*
* @param WP_Comment $comment Comment object.
*/
public function _test_as_admin( $comment ) {
@ -107,11 +107,11 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Test as a non-privileged user (subscriber)
* Expects test to fail
* Tests as a non-privileged user (subscriber).
*
* @param mixed $comment Comment object
* @return void
* Expects test to fail.
*
* @param WP_Comment $comment Comment object.
*/
public function _test_as_subscriber( $comment ) {
@ -135,11 +135,11 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Test with a bad nonce
* Expects test to fail
* Tests with a bad nonce.
*
* @param mixed $comment Comment object
* @return void
* Expects test to fail.
*
* @param WP_Comment $comment Comment object.
*/
public function _test_with_bad_nonce( $comment ) {
@ -163,10 +163,9 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Test with a bad id
* Expects test to fail
* Tests with a bad ID.
*
* @return void
* Expects test to fail.
*/
public function test_with_bad_id() {
@ -204,9 +203,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Dim a comment as an administrator (expects success)
*
* @return void
* Dims a comment as an administrator (expects success).
*/
public function test_ajax_comment_dim_actions_as_administrator() {
$comment = array_pop( $this->_comments );
@ -215,9 +212,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Dim a comment as a subscriber (expects permission denied)
*
* @return void
* Dims a comment as a subscriber (expects permission denied).
*/
public function test_ajax_comment_dim_actions_as_subscriber() {
$comment = array_pop( $this->_comments );
@ -225,9 +220,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Dim a comment with no id
*
* @return void
* Dims a comment with no ID.
*/
public function test_ajax_dim_comment_no_id() {
$comment = array_pop( $this->_comments );
@ -235,9 +228,7 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
}
/**
* Dim a comment with a bad nonce
*
* @return void
* Dims a comment with a bad nonce.
*/
public function test_ajax_dim_comment_bad_nonce() {
$comment = array_pop( $this->_comments );

View File

@ -16,14 +16,14 @@ require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
/**
* A post with at least one comment
* A post with at least one comment.
*
* @var mixed
*/
protected $_comment_post = null;
/**
* Set up the test fixture
* Sets up the test fixture.
*/
public function setUp() {
parent::setUp();
@ -38,10 +38,9 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
}
/**
* Get comments as a privilged user (administrator)
* Expects test to pass
* Gets comments as a privileged user (administrator).
*
* @return void
* Expects test to pass.
*/
public function test_as_admin() {
@ -132,45 +131,9 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
}
/**
* @ticket 39732
*/
public function test_wp_update_comment_data_is_wp_error() {
// Become an administrator
$this->_setRole( 'administrator' );
// Get a comment
$comments = get_comments(
array(
'post_id' => $this->_comment_post->ID,
)
);
$comment = array_pop( $comments );
// Set up a default request
$_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
$_POST['comment_ID'] = $comment->comment_ID;
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
// Simulate filter check error
add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 );
// Make the request
$this->setExpectedException( 'WPAjaxDieStopException', 'wp_update_comment_data filter fails for this comment.' );
$this->_handleAjax( 'edit-comment' );
}
/**
* Block comments from being updated by returning WP_Error
*/
public function _wp_update_comment_data_filter( $data, $comment, $commentarr ) {
return new WP_Error( 'comment_wrong', 'wp_update_comment_data filter fails for this comment.', 500 );
}
/**
* Get comments as a non-privileged user (subscriber)
* Expects test to fail
* Gets comments as a non-privileged user (subscriber).
*
* @return void
* Expects test to fail.
*/
public function test_as_subscriber() {
@ -196,10 +159,9 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
}
/**
* Get comments with a bad nonce
* Expects test to fail
* Gets comments with a bad nonce.
*
* @return void
* Expects test to fail.
*/
public function test_bad_nonce() {
@ -225,10 +187,9 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
}
/**
* Get comments for an invalid post
* This should return valid XML
* Gets comments for an invalid post.
*
* @return void
* This should return valid XML.
*/
public function test_invalid_comment() {
@ -244,4 +205,39 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
$this->_handleAjax( 'edit-comment' );
}
/**
* @ticket 39732
*/
public function test_wp_update_comment_data_is_wp_error() {
// Become an administrator.
$this->_setRole( 'administrator' );
// Get a comment.
$comments = get_comments(
array(
'post_id' => $this->_comment_post->ID,
)
);
$comment = array_pop( $comments );
// Set up a default request.
$_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
$_POST['comment_ID'] = $comment->comment_ID;
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
// Simulate filter check error.
add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 );
// Make the request.
$this->setExpectedException( 'WPAjaxDieStopException', 'wp_update_comment_data filter fails for this comment.' );
$this->_handleAjax( 'edit-comment' );
}
/**
* Blocks comments from being updated by returning WP_Error.
*/
public function _wp_update_comment_data_filter( $data, $comment, $commentarr ) {
return new WP_Error( 'comment_wrong', 'wp_update_comment_data filter fails for this comment.', 500 );
}
}

View File

@ -16,14 +16,14 @@ require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
/**
* A post with at least one comment
* A post with at least one comment.
*
* @var mixed
*/
protected static $comment_post = null;
/**
* A post with no comments
* A post with no comments.
*
* @var mixed
*/
@ -38,10 +38,9 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
}
/**
* Get comments as a privilged user (administrator)
* Expects test to pass
* Gets comments as a privileged user (administrator).
*
* @return void
* Expects test to pass.
*/
public function test_as_admin() {
@ -76,10 +75,9 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
}
/**
* Get comments as a non-privileged user (subscriber)
* Expects test to fail
* Gets comments as a non-privileged user (subscriber).
*
* @return void
* Expects test to fail.
*/
public function test_as_subscriber() {
@ -97,10 +95,9 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
}
/**
* Get comments with a bad nonce
* Expects test to fail
* Gets comments with a bad nonce.
*
* @return void
* Expects test to fail.
*/
public function test_bad_nonce() {
@ -118,10 +115,9 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
}
/**
* Get comments for an invalid post
* Bad post IDs are set to 0, this should return valid XML
* Gets comments for an invalid post.
*
* @return void
* Bad post IDs are set to 0, this should return valid XML.
*/
public function test_invalid_post() {
@ -139,10 +135,7 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
}
/**
* Get comments for an invalid post
* Bad post IDs are set to 0, this should return valid XML
*
* @return void
* Gets comments for a post with no comments.
*/
public function test_post_with_no_comments() {

View File

@ -16,14 +16,14 @@ require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
/**
* A post with at least one comment
* A post with at least one comment.
*
* @var mixed
*/
protected static $comment_post = null;
/**
* Draft post
* Draft post.
*
* @var mixed
*/
@ -43,10 +43,9 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Reply as a privilged user (administrator)
* Expects test to pass
* Tests reply as a privileged user (administrator).
*
* @return void
* Expects test to pass.
*/
public function test_as_admin() {
@ -90,10 +89,9 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Reply as a non-privileged user (subscriber)
* Expects test to fail
* Tests reply as a non-privileged user (subscriber).
*
* @return void
* Expects test to fail.
*/
public function test_as_subscriber() {
@ -120,10 +118,9 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Reply using a bad nonce
* Expects test to fail
* Tests reply using a bad nonce.
*
* @return void
* Expects test to fail.
*/
public function test_bad_nonce() {
@ -150,10 +147,9 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Reply to an invalid post
* Expects test to fail
* Tests reply to an invalid post.
*
* @return void
* Expects test to fail.
*/
public function test_invalid_post() {
@ -171,10 +167,9 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Reply to a draft post
* Expects test to fail
* Tests reply to a draft post.
*
* @return void
* Expects test to fail.
*/
public function test_with_draft_post() {
@ -192,11 +187,11 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Reply to a post with a simulated database failure
* Expects test to fail
* Tests reply to a post with a simulated database failure.
*
* Expects test to fail.
*
* @global $wpdb
* @return void
*/
public function test_blocked_comment() {
global $wpdb;
@ -225,7 +220,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Block comments from being saved
* Blocks comments from being saved.
*
* @param string $sql
* @return string
@ -239,10 +234,9 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Raises WP_Error after Posted a new pre comment
* Tests blocking a comment from being saved on 'pre_comment_approved'.
*
* @ticket 39730
* @return void
*/
public function test_pre_comments_approved() {
@ -263,7 +257,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
}
/**
* Block comments from being saved 'pre_comment_approved', by returning WP_Error
* Blocks comments from being saved on 'pre_comment_approved', by returning WP_Error.
*/
function _pre_comment_approved_filter( $approved, $commentdata ) {
return new WP_Error( 'comment_wrong', 'pre_comment_approved filter fails for new comment', 403 );