AJAX UNIT TESTS: Have you ever wondered why these take 600 forevers to run? They all eventually call `do_action( 'admin_init' )`, which has `_maybe_update_core`, `_maybe_update_plugins`, and `_maybe_update_themes` hooked to it. REMOVE THEM, and AJAX unit tests run like the wind. `Tests_Ajax_Response` is still slow.

See #30017, #33968.


git-svn-id: https://develop.svn.wordpress.org/trunk@35311 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-10-21 03:17:36 +00:00
parent 5252cb7fe3
commit 14893eb628
6 changed files with 181 additions and 143 deletions

View File

@ -26,7 +26,10 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
* List of ajax actions called via POST
* @var type
*/
protected $_core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache' );
protected static $_core_actions_get = array(
'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
'autocomplete-user', 'dashboard-widgets', 'logged-in',
);
/**
* Saved error reporting level
@ -38,7 +41,7 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
* List of ajax actions called via GET
* @var type
*/
protected $_core_actions_post = array(
protected static $_core_actions_post = array(
'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
@ -47,9 +50,31 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat',
'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat', 'get-revision-diffs',
'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
'press-this-add-category', 'crop-image', 'generate-password',
);
public static function setUpBeforeClass() {
if ( ! defined( 'DOING_AJAX' ) ) {
define( 'DOING_AJAX', true );
}
remove_action( 'admin_init', '_maybe_update_core' );
remove_action( 'admin_init', '_maybe_update_plugins' );
remove_action( 'admin_init', '_maybe_update_themes' );
// Register the core actions
foreach ( array_merge( self::$_core_actions_get, self::$_core_actions_post ) as $action ) {
if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) ) {
add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 );
}
}
parent::setUpBeforeClass();
}
/**
* Set up the test fixture.
* Override wp_die(), pretend to be ajax, and suppres E_WARNINGs
@ -57,14 +82,8 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
// Register the core actions
foreach ( array_merge( $this->_core_actions_get, $this->_core_actions_post ) as $action )
if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) )
add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 );
add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
if ( !defined( 'DOING_AJAX' ) )
define( 'DOING_AJAX', true );
set_current_screen( 'ajax' );
// Clear logout cookies

View File

@ -21,11 +21,27 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
*/
protected $_post = null;
/**
* user_id
* @var int
*/
protected $user_id = 0;
protected static $admin_id = 0;
protected static $editor_id = 0;
protected static $post;
protected static $post_id;
protected static $user_ids = array();
public static function wpSetUpBeforeClass( $factory ) {
self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
self::$post_id = $factory->post->create( array( 'post_status' => 'draft' ) );
self::$post = get_post( self::$post_id );
}
public static function wpTearDownAfterClass() {
foreach ( self::$user_ids as $user_id ) {
self::delete_user( $user_id );
}
wp_delete_post( self::$post_id, true );
}
/**
* Set up the test fixture
@ -33,11 +49,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
public function setUp() {
parent::setUp();
// Set a user so the $post has 'post_author'
$this->user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $this->user_id );
$post_id = self::factory()->post->create( array( 'post_status' => 'draft' ) );
$this->_post = get_post( $post_id );
wp_set_current_user( self::$admin_id );
}
/**
@ -46,7 +58,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
*/
public function test_autosave_post() {
// The original post_author
wp_set_current_user( $this->user_id );
wp_set_current_user( self::$admin_id );
// Set up the $_POST request
$md5 = md5( uniqid() );
@ -55,9 +67,9 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
'_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
'data' => array(
'wp_autosave' => array(
'post_id' => $this->_post->ID,
'_wpnonce' => wp_create_nonce( 'update-post_' . $this->_post->ID ),
'post_content' => $this->_post->post_content . PHP_EOL . $md5,
'post_id' => self::$post_id,
'_wpnonce' => wp_create_nonce( 'update-post_' . self::$post->ID ),
'post_content' => self::$post->post_content . PHP_EOL . $md5,
'post_type' => 'post',
),
),
@ -78,8 +90,8 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
$this->assertTrue( $response['wp_autosave']['success'] );
// Check that the edit happened
$post = get_post( $this->_post->ID );
$this->assertGreaterThanOrEqual( 0, strpos( $post->post_content, $md5 ) );
$post = get_post( self::$post_id );
$this->assertGreaterThanOrEqual( 0, strpos( self::$post->post_content, $md5 ) );
}
/**
@ -88,14 +100,13 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
*/
public function test_autosave_locked_post() {
// Lock the post to another user
$another_user_id = self::factory()->user->create( array( 'role' => 'editor' ) );
wp_set_current_user( $another_user_id );
wp_set_post_lock( $this->_post->ID );
wp_set_current_user( self::$editor_id );
wp_set_post_lock( self::$post_id );
wp_set_current_user( $this->user_id );
wp_set_current_user( self::$admin_id );
// Ensure post is locked
$this->assertEquals( $another_user_id, wp_check_post_lock( $this->_post->ID ) );
$this->assertEquals( self::$editor_id, wp_check_post_lock( self::$post_id ) );
// Set up the $_POST request
$md5 = md5( uniqid() );
@ -104,9 +115,9 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
'_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
'data' => array(
'wp_autosave' => array(
'post_id' => $this->_post->ID,
'_wpnonce' => wp_create_nonce( 'update-post_' . $this->_post->ID ),
'post_content' => $this->_post->post_content . PHP_EOL . $md5,
'post_id' => self::$post_id,
'_wpnonce' => wp_create_nonce( 'update-post_' . self::$post_id ),
'post_content' => self::$post->post_content . PHP_EOL . $md5,
'post_type' => 'post',
),
),
@ -126,11 +137,11 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
$this->assertTrue( $response['wp_autosave']['success'] );
// Check that the original post was NOT edited
$post = get_post( $this->_post->ID );
$post = get_post( self::$post_id );
$this->assertFalse( strpos( $post->post_content, $md5 ) );
// Check if the autosave post was created
$autosave = wp_get_post_autosave( $this->_post->ID, get_current_user_id() );
$autosave = wp_get_post_autosave( self::$post_id, get_current_user_id() );
$this->assertNotEmpty( $autosave );
$this->assertGreaterThanOrEqual( 0, strpos( $autosave->post_content, $md5 ) );
}
@ -141,7 +152,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
*/
public function test_with_invalid_nonce( ) {
wp_set_current_user( $this->user_id );
wp_set_current_user( self::$admin_id );
// Set up the $_POST request
$_POST = array(
@ -149,7 +160,7 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
'_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
'data' => array(
'wp_autosave' => array(
'post_id' => $this->_post->ID,
'post_id' => self::$post_id,
'_wpnonce' => substr( md5( uniqid() ), 0, 10 ),
),
),

View File

@ -19,16 +19,35 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
* List of comments
* @var array
*/
protected $_comments = array();
protected static $comments = array();
/**
* Set up the test fixture
*/
public function setUp() {
parent::setUp();
$post_id = self::factory()->post->create();
$this->_comments = self::factory()->comment->create_post_comments( $post_id, 15 );
$this->_comments = array_map( 'get_comment', $this->_comments );
protected static $admin_id = 0;
protected static $editor_id = 0;
protected static $post;
protected static $post_id;
protected static $user_ids = array();
public static function wpSetUpBeforeClass( $factory ) {
self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
self::$post_id = $factory->post->create();
self::$post = get_post( self::$post_id );
$comment_ids = $factory->comment->create_post_comments( self::$post_id, 8 );
self::$comments = array_map( 'get_comment', $comment_ids );
}
public static function wpTearDownAfterClass() {
foreach ( self::$user_ids as $user_id ) {
self::delete_user( $user_id );
}
wp_delete_post( self::$post_id, true );
foreach ( self::$comments as $c ) {
wp_delete_comment( $c->ID, true );
}
}
/**
@ -66,7 +85,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$_POST['id'] = $comment->comment_ID;
$_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
$_POST[$action] = 1;
$_POST['_total'] = count( $this->_comments );
$_POST['_total'] = count( self::$comments );
$_POST['_per_page'] = 100;
$_POST['_page'] = 1;
$_POST['_url'] = admin_url( 'edit-comments.php' );
@ -124,7 +143,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$_POST['id'] = $comment->comment_ID;
$_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
$_POST[$action] = 1;
$_POST['_total'] = count( $this->_comments );
$_POST['_total'] = count( self::$comments );
$_POST['_per_page'] = 100;
$_POST['_page'] = 1;
$_POST['_url'] = admin_url( 'edit-comments.php' );
@ -154,7 +173,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$_POST['id'] = $comment->comment_ID;
$_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
$_POST[$action] = 1;
$_POST['_total'] = count( $this->_comments );
$_POST['_total'] = count( self::$comments );
$_POST['_per_page'] = 100;
$_POST['_page'] = 1;
$_POST['_url'] = admin_url( 'edit-comments.php' );
@ -183,7 +202,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$_POST['id'] = 12346789;
$_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' );
$_POST[$action] = 1;
$_POST['_total'] = count( $this->_comments );
$_POST['_total'] = count( self::$comments );
$_POST['_per_page'] = 100;
$_POST['_page'] = 1;
$_POST['_url'] = admin_url( 'edit-comments.php' );
@ -219,7 +238,7 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
$_POST['id'] = $comment->comment_ID;
$_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
$_POST[$action] = 1;
$_POST['_total'] = count( $this->_comments );
$_POST['_total'] = count( self::$comments );
$_POST['_per_page'] = 100;
$_POST['_page'] = 1;
$_POST['_url'] = admin_url( 'edit-comments.php' );
@ -254,20 +273,16 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
* @return void
*/
public function test_ajax_comment_trash_actions_as_administrator() {
// Test trash/untrash
$comment = array_pop( $this->_comments );
$this->_test_as_admin( $comment, 'trash' );
$this->_test_as_admin( $comment, 'untrash' );
$this->_test_as_admin( self::$comments[0], 'trash' );
$this->_test_as_admin( self::$comments[0], 'untrash' );
// Test spam/unspam
$comment = array_pop( $this->_comments );
$this->_test_as_admin( $comment, 'spam' );
$this->_test_as_admin( $comment, 'unspam' );
$this->_test_as_admin( self::$comments[1], 'spam' );
$this->_test_as_admin( self::$comments[1], 'unspam' );
// Test delete
$comment = array_pop( $this->_comments );
$this->_test_as_admin( $comment, 'delete' );
$this->_test_as_admin( self::$comments[2], 'delete' );
}
/**
@ -275,20 +290,16 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
* @return void
*/
public function test_ajax_comment_trash_actions_as_subscriber() {
// Test trash/untrash
$comment = array_pop( $this->_comments );
$this->_test_as_subscriber( $comment, 'trash' );
$this->_test_as_subscriber( $comment, 'untrash' );
$this->_test_as_subscriber( self::$comments[0], 'trash' );
$this->_test_as_subscriber( self::$comments[0], 'untrash' );
// Test spam/unspam
$comment = array_pop( $this->_comments );
$this->_test_as_subscriber( $comment, 'spam' );
$this->_test_as_subscriber( $comment, 'unspam' );
$this->_test_as_subscriber( self::$comments[1], 'spam' );
$this->_test_as_subscriber( self::$comments[1], 'unspam' );
// Test delete
$comment = array_pop( $this->_comments );
$this->_test_as_subscriber( $comment, 'delete' );
$this->_test_as_subscriber( self::$comments[2], 'delete' );
}
/**
@ -296,20 +307,16 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
* @return void
*/
public function test_ajax_trash_comment_no_id() {
// Test trash/untrash
$comment = array_pop( $this->_comments );
$this->_test_as_admin( $comment, 'trash' );
$this->_test_as_admin( $comment, 'untrash' );
$this->_test_as_admin( self::$comments[0], 'trash' );
$this->_test_as_admin( self::$comments[0], 'untrash' );
// Test spam/unspam
$comment = array_pop( $this->_comments );
$this->_test_as_admin( $comment, 'spam' );
$this->_test_as_admin( $comment, 'unspam' );
$this->_test_as_admin( self::$comments[1], 'spam' );
$this->_test_as_admin( self::$comments[1], 'unspam' );
// Test delete
$comment = array_pop( $this->_comments );
$this->_test_as_admin( $comment, 'delete' );
$this->_test_as_admin( self::$comments[2], 'delete' );
}
/**
@ -317,20 +324,16 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
* @return void
*/
public function test_ajax_trash_comment_bad_nonce() {
// Test trash/untrash
$comment = array_pop( $this->_comments );
$this->_test_with_bad_nonce( $comment, 'trash' );
$this->_test_with_bad_nonce( $comment, 'untrash' );
$this->_test_with_bad_nonce( self::$comments[0], 'trash' );
$this->_test_with_bad_nonce( self::$comments[0], 'untrash' );
// Test spam/unspam
$comment = array_pop( $this->_comments );
$this->_test_with_bad_nonce( $comment, 'spam' );
$this->_test_with_bad_nonce( $comment, 'unspam' );
$this->_test_with_bad_nonce( self::$comments[1], 'spam' );
$this->_test_with_bad_nonce( self::$comments[1], 'unspam' );
// Test delete
$comment = array_pop( $this->_comments );
$this->_test_with_bad_nonce( $comment, 'delete' );
$this->_test_with_bad_nonce( self::$comments[2], 'delete' );
}
/**
@ -338,19 +341,15 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
* @return void
*/
public function test_ajax_trash_double_action() {
// Test trash/untrash
$comment = array_pop( $this->_comments );
$this->_test_double_action( $comment, 'trash' );
$this->_test_double_action( $comment, 'untrash' );
$this->_test_double_action( self::$comments[0], 'trash' );
$this->_test_double_action( self::$comments[0], 'untrash' );
// Test spam/unspam
$comment = array_pop( $this->_comments );
$this->_test_double_action( $comment, 'spam' );
$this->_test_double_action( $comment, 'unspam' );
$this->_test_double_action( self::$comments[1], 'spam' );
$this->_test_double_action( self::$comments[1], 'unspam' );
// Test delete
$comment = array_pop( $this->_comments );
$this->_test_double_action( $comment, 'delete' );
$this->_test_double_action( self::$comments[2], 'delete' );
}
}

View File

@ -19,27 +19,29 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
* A post with at least one comment
* @var mixed
*/
protected $_comment_post = null;
protected static $comment_post = null;
/**
* A post with no comments
* @var mixed
*/
protected $_no_comment_post = null;
protected static $no_comment_post = null;
/**
* Set up the test fixture
*/
public function setUp() {
parent::setUp();
$post_id = self::factory()->post->create();
self::factory()->comment->create_post_comments( $post_id, 5 );
$this->_comment_post = get_post( $post_id );
protected static $comment_ids = array();
$post_id = self::factory()->post->create();
$this->_no_comment_post = get_post( $post_id );
public static function wpSetUpBeforeClass( $factory ) {
self::$comment_post = $factory->post->create_and_get();
self::$comment_ids = $factory->comment->create_post_comments( self::$comment_post->ID, 5 );
self::$no_comment_post = $factory->post->create_and_get();
}
unset( $GLOBALS['post_id'] );
public static function wpTearDownAfterClass() {
foreach ( self::$comment_ids as $comment_id ) {
wp_delete_comment( $comment_id, true );
}
wp_delete_post( self::$comment_post->ID, true );
wp_delete_post( self::$no_comment_post->ID, true );
}
/**
@ -55,7 +57,7 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
// Set up a default request
$_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' );
$_POST['action'] = 'get-comments';
$_POST['p'] = $this->_comment_post->ID;
$_POST['p'] = self::$comment_post->ID;
// Make the request
try {
@ -92,7 +94,7 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
// Set up a default request
$_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' );
$_POST['action'] = 'get-comments';
$_POST['p'] = $this->_comment_post->ID;
$_POST['p'] = self::$comment_post->ID;
// Make the request
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
@ -112,7 +114,7 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
// Set up a default request
$_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
$_POST['action'] = 'get-comments';
$_POST['p'] = $this->_comment_post->ID;
$_POST['p'] = self::$comment_post->ID;
// Make the request
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
@ -152,7 +154,7 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
// Set up a default request
$_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' );
$_POST['action'] = 'get-comments';
$_POST['p'] = $this->_no_comment_post->ID;
$_POST['p'] = self::$no_comment_post->ID;
// Make the request
$this->setExpectedException( 'WPAjaxDieStopException', '1' );

View File

@ -19,25 +19,29 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
* A post with at least one comment
* @var mixed
*/
protected $_comment_post = null;
protected static $comment_post = null;
/**
* Draft post
* @var mixed
*/
protected $_draft_post = null;
protected static $draft_post = null;
/**
* Set up the test fixture
*/
public function setUp() {
parent::setUp();
$post_id = self::factory()->post->create();
self::factory()->comment->create_post_comments( $post_id, 5 );
$this->_comment_post = get_post( $post_id );
protected static $comment_ids = array();
$post_id = self::factory()->post->create( array( 'post_status' => 'draft' ) );
$this->_draft_post = get_post( $post_id );
public static function wpSetUpBeforeClass( $factory ) {
self::$comment_post = $factory->post->create_and_get();
self::$comment_ids = $factory->comment->create_post_comments( self::$comment_post->ID, 5 );
self::$draft_post = $factory->post->create_and_get( array( 'post_status' => 'draft' ) );
}
public static function wpTearDownAfterClass() {
foreach ( self::$comment_ids as $comment_id ) {
wp_delete_comment( $comment_id, true );
}
wp_delete_post( self::$comment_post->ID, true );
wp_delete_post( self::$draft_post->ID, true );
}
public function tearDown() {
@ -57,7 +61,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
// Get a comment
$comments = get_comments( array(
'post_id' => $this->_comment_post->ID
'post_id' => self::$comment_post->ID
) );
$comment = array_pop( $comments );
@ -65,7 +69,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
$_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.';
$_POST['comment_post_ID'] = $this->_comment_post->ID;
$_POST['comment_post_ID'] = self::$comment_post->ID;
// Make the request
try {
@ -101,7 +105,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
// Get a comment
$comments = get_comments( array(
'post_id' => $this->_comment_post->ID
'post_id' => self::$comment_post->ID
) );
$comment = array_pop( $comments );
@ -109,7 +113,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
$_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.';
$_POST['comment_post_ID'] = $this->_comment_post->ID;
$_POST['comment_post_ID'] = self::$comment_post->ID;
// Make the request
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
@ -128,7 +132,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
// Get a comment
$comments = get_comments( array(
'post_id' => $this->_comment_post->ID
'post_id' => self::$comment_post->ID
) );
$comment = array_pop( $comments );
@ -136,7 +140,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
$_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() );
$_POST['comment_ID'] = $comment->comment_ID;
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
$_POST['comment_post_ID'] = $this->_comment_post->ID;
$_POST['comment_post_ID'] = self::$comment_post->ID;
// Make the request
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
@ -176,7 +180,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
// Set up a default request
$_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
$_POST['comment_post_ID'] = $this->_draft_post->ID;
$_POST['comment_post_ID'] = self::$draft_post->ID;
// Make the request
$this->setExpectedException( 'WPAjaxDieStopException', 'ERROR: you are replying to a comment on a draft post.' );
@ -198,7 +202,7 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
// Set up a default request
$_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
$_POST['comment_post_ID'] = $this->_comment_post->ID;
$_POST['comment_post_ID'] = self::$comment_post->ID;
// Block comments from being saved, simulate a DB error
add_filter( 'query', array( $this, '_block_comments' ) );

View File

@ -19,19 +19,22 @@ class Tests_Ajax_TagSearch extends WP_Ajax_UnitTestCase {
* List of terms to insert on setup
* @var array
*/
private $_terms = array(
private static $terms = array(
'chattels', 'depo', 'energumen', 'figuriste', 'habergeon', 'impropriation'
);
/**
* Setup
* @todo use a term factory
*/
public function setUp() {
parent::setUp();
private static $term_ids = array();
foreach ( $this->_terms as $term )
wp_insert_term( $term, 'post_tag' );
public static function wpSetUpBeforeClass() {
foreach ( self::$terms as $t ) {
self::$term_ids[] = wp_insert_term( $t, 'post_tag' );
}
}
public static function wpTearDownAfterClass() {
foreach ( self::$term_ids as $t ) {
wp_delete_term( $t, 'post_tag' );
}
}
/**