<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[35311] trunk/tests/phpunit: 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.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/35311">35311</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/35311","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>wonderboymusic</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-10-21 03:17:36 +0000 (Wed, 21 Oct 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/30017">#30017</a>, <a href="https://core.trac.wordpress.org/ticket/33968">#33968</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunitincludestestcaseajaxphp">trunk/tests/phpunit/includes/testcase-ajax.php</a></li>
<li><a href="#trunktestsphpunittestsajaxAutosavephp">trunk/tests/phpunit/tests/ajax/Autosave.php</a></li>
<li><a href="#trunktestsphpunittestsajaxDeleteCommentphp">trunk/tests/phpunit/tests/ajax/DeleteComment.php</a></li>
<li><a href="#trunktestsphpunittestsajaxGetCommentsphp">trunk/tests/phpunit/tests/ajax/GetComments.php</a></li>
<li><a href="#trunktestsphpunittestsajaxReplytoCommentphp">trunk/tests/phpunit/tests/ajax/ReplytoComment.php</a></li>
<li><a href="#trunktestsphpunittestsajaxTagSearchphp">trunk/tests/phpunit/tests/ajax/TagSearch.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunitincludestestcaseajaxphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/testcase-ajax.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/testcase-ajax.php 2015-10-21 03:01:13 UTC (rev 35310)
+++ trunk/tests/phpunit/includes/testcase-ajax.php 2015-10-21 03:17:36 UTC (rev 35311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,7 +26,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * List of ajax actions called via POST
</span><span class="cx" style="display: block; padding: 0 10px"> * @var type
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $_core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $_core_actions_get = array(
+ 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
+ 'autocomplete-user', 'dashboard-widgets', 'logged-in',
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Saved error reporting level
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,7 +41,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * List of ajax actions called via GET
</span><span class="cx" style="display: block; padding: 0 10px"> * @var type
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $_core_actions_post = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $_core_actions_post = array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
</span><span class="cx" style="display: block; padding: 0 10px"> 'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
</span><span class="cx" style="display: block; padding: 0 10px"> 'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -47,9 +50,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
</span><span class="cx" style="display: block; padding: 0 10px"> 'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
</span><span class="cx" style="display: block; padding: 0 10px"> 'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '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',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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();
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Set up the test fixture.
</span><span class="cx" style="display: block; padding: 0 10px"> * Override wp_die(), pretend to be ajax, and suppres E_WARNINGs
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -57,14 +82,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function setUp() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::setUp();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
- if ( !defined( 'DOING_AJAX' ) )
- define( 'DOING_AJAX', true );
</del><span class="cx" style="display: block; padding: 0 10px"> set_current_screen( 'ajax' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Clear logout cookies
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxAutosavephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/ajax/Autosave.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/Autosave.php 2015-10-21 03:01:13 UTC (rev 35310)
+++ trunk/tests/phpunit/tests/ajax/Autosave.php 2015-10-21 03:17:36 UTC (rev 35311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,23 +21,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected $_post = null;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * user_id
- * @var int
- */
- protected $user_id = 0;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $admin_id = 0;
+ protected static $editor_id = 0;
+ protected static $post;
+ protected static $post_id;
+ protected static $user_ids = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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 );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Set up the test fixture
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function setUp() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::setUp();
</span><span class="cx" style="display: block; padding: 0 10px"> // Set a user so the $post has 'post_author'
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_current_user( self::$admin_id );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,7 +58,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_autosave_post() {
</span><span class="cx" style="display: block; padding: 0 10px"> // The original post_author
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_set_current_user( $this->user_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_current_user( self::$admin_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up the $_POST request
</span><span class="cx" style="display: block; padding: 0 10px"> $md5 = md5( uniqid() );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,9 +67,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'data' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp_autosave' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post_id' => $this->_post->ID,
- '_wpnonce' => wp_create_nonce( 'update-post_' . $this->_post->ID ),
- 'post_content' => $this->_post->post_content . PHP_EOL . $md5,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'post_id' => self::$post_id,
+ '_wpnonce' => wp_create_nonce( 'update-post_' . self::$post->ID ),
+ 'post_content' => self::$post->post_content . PHP_EOL . $md5,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'post',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,8 +90,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( $response['wp_autosave']['success'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Check that the edit happened
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post = get_post( $this->_post->ID );
- $this->assertGreaterThanOrEqual( 0, strpos( $post->post_content, $md5 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post = get_post( self::$post_id );
+ $this->assertGreaterThanOrEqual( 0, strpos( self::$post->post_content, $md5 ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,14 +100,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_autosave_locked_post() {
</span><span class="cx" style="display: block; padding: 0 10px"> // Lock the post to another user
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $another_user_id = self::factory()->user->create( array( 'role' => 'editor' ) );
- wp_set_current_user( $another_user_id );
- wp_set_post_lock( $this->_post->ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_current_user( self::$editor_id );
+ wp_set_post_lock( self::$post_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_set_current_user( $this->user_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_current_user( self::$admin_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Ensure post is locked
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( $another_user_id, wp_check_post_lock( $this->_post->ID ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( self::$editor_id, wp_check_post_lock( self::$post_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up the $_POST request
</span><span class="cx" style="display: block; padding: 0 10px"> $md5 = md5( uniqid() );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -104,9 +115,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'data' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp_autosave' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post_id' => $this->_post->ID,
- '_wpnonce' => wp_create_nonce( 'update-post_' . $this->_post->ID ),
- 'post_content' => $this->_post->post_content . PHP_EOL . $md5,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'post_id' => self::$post_id,
+ '_wpnonce' => wp_create_nonce( 'update-post_' . self::$post_id ),
+ 'post_content' => self::$post->post_content . PHP_EOL . $md5,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'post',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,11 +137,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( $response['wp_autosave']['success'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Check that the original post was NOT edited
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post = get_post( $this->_post->ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post = get_post( self::$post_id );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( strpos( $post->post_content, $md5 ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Check if the autosave post was created
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $autosave = wp_get_post_autosave( $this->_post->ID, get_current_user_id() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $autosave = wp_get_post_autosave( self::$post_id, get_current_user_id() );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertNotEmpty( $autosave );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertGreaterThanOrEqual( 0, strpos( $autosave->post_content, $md5 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -141,7 +152,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_with_invalid_nonce( ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_set_current_user( $this->user_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_current_user( self::$admin_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up the $_POST request
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -149,7 +160,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '_nonce' => wp_create_nonce( 'heartbeat-nonce' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'data' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp_autosave' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post_id' => $this->_post->ID,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'post_id' => self::$post_id,
</ins><span class="cx" style="display: block; padding: 0 10px"> '_wpnonce' => substr( md5( uniqid() ), 0, 10 ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxDeleteCommentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/ajax/DeleteComment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/DeleteComment.php 2015-10-21 03:01:13 UTC (rev 35310)
+++ trunk/tests/phpunit/tests/ajax/DeleteComment.php 2015-10-21 03:17:36 UTC (rev 35311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,18 +19,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * List of comments
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $_comments = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $comments = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * 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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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 );
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Clear the POST actions in between requests
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,7 +85,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['id'] = $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST[$action] = 1;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['_total'] = count( $this->_comments );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['_total'] = count( self::$comments );
</ins><span class="cx" style="display: block; padding: 0 10px"> $_POST['_per_page'] = 100;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_page'] = 1;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_url'] = admin_url( 'edit-comments.php' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -124,7 +143,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['id'] = $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST[$action] = 1;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['_total'] = count( $this->_comments );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['_total'] = count( self::$comments );
</ins><span class="cx" style="display: block; padding: 0 10px"> $_POST['_per_page'] = 100;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_page'] = 1;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_url'] = admin_url( 'edit-comments.php' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -154,7 +173,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['id'] = $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST[$action] = 1;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['_total'] = count( $this->_comments );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['_total'] = count( self::$comments );
</ins><span class="cx" style="display: block; padding: 0 10px"> $_POST['_per_page'] = 100;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_page'] = 1;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_url'] = admin_url( 'edit-comments.php' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -183,7 +202,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['id'] = 12346789;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST[$action] = 1;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['_total'] = count( $this->_comments );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['_total'] = count( self::$comments );
</ins><span class="cx" style="display: block; padding: 0 10px"> $_POST['_per_page'] = 100;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_page'] = 1;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_url'] = admin_url( 'edit-comments.php' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -219,7 +238,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['id'] = $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST[$action] = 1;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['_total'] = count( $this->_comments );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['_total'] = count( self::$comments );
</ins><span class="cx" style="display: block; padding: 0 10px"> $_POST['_per_page'] = 100;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_page'] = 1;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_url'] = admin_url( 'edit-comments.php' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -254,20 +273,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_ajax_comment_trash_actions_as_administrator() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Test trash/untrash
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_admin( $comment, 'trash' );
- $this->_test_as_admin( $comment, 'untrash' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_admin( self::$comments[0], 'trash' );
+ $this->_test_as_admin( self::$comments[0], 'untrash' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test spam/unspam
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_admin( $comment, 'spam' );
- $this->_test_as_admin( $comment, 'unspam' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_admin( self::$comments[1], 'spam' );
+ $this->_test_as_admin( self::$comments[1], 'unspam' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test delete
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_admin( $comment, 'delete' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_admin( self::$comments[2], 'delete' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -275,20 +290,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_ajax_comment_trash_actions_as_subscriber() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Test trash/untrash
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_subscriber( $comment, 'trash' );
- $this->_test_as_subscriber( $comment, 'untrash' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_subscriber( self::$comments[0], 'trash' );
+ $this->_test_as_subscriber( self::$comments[0], 'untrash' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test spam/unspam
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_subscriber( $comment, 'spam' );
- $this->_test_as_subscriber( $comment, 'unspam' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_subscriber( self::$comments[1], 'spam' );
+ $this->_test_as_subscriber( self::$comments[1], 'unspam' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test delete
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_subscriber( $comment, 'delete' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_subscriber( self::$comments[2], 'delete' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -296,20 +307,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_ajax_trash_comment_no_id() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Test trash/untrash
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_admin( $comment, 'trash' );
- $this->_test_as_admin( $comment, 'untrash' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_admin( self::$comments[0], 'trash' );
+ $this->_test_as_admin( self::$comments[0], 'untrash' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test spam/unspam
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_admin( $comment, 'spam' );
- $this->_test_as_admin( $comment, 'unspam' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_admin( self::$comments[1], 'spam' );
+ $this->_test_as_admin( self::$comments[1], 'unspam' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test delete
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_as_admin( $comment, 'delete' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_as_admin( self::$comments[2], 'delete' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -317,20 +324,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_ajax_trash_comment_bad_nonce() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Test trash/untrash
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_with_bad_nonce( $comment, 'trash' );
- $this->_test_with_bad_nonce( $comment, 'untrash' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_with_bad_nonce( self::$comments[0], 'trash' );
+ $this->_test_with_bad_nonce( self::$comments[0], 'untrash' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test spam/unspam
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_with_bad_nonce( $comment, 'spam' );
- $this->_test_with_bad_nonce( $comment, 'unspam' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_with_bad_nonce( self::$comments[1], 'spam' );
+ $this->_test_with_bad_nonce( self::$comments[1], 'unspam' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test delete
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_with_bad_nonce( $comment, 'delete' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_with_bad_nonce( self::$comments[2], 'delete' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -338,19 +341,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_ajax_trash_double_action() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Test trash/untrash
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_double_action( $comment, 'trash' );
- $this->_test_double_action( $comment, 'untrash' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_double_action( self::$comments[0], 'trash' );
+ $this->_test_double_action( self::$comments[0], 'untrash' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test spam/unspam
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_double_action( $comment, 'spam' );
- $this->_test_double_action( $comment, 'unspam' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_double_action( self::$comments[1], 'spam' );
+ $this->_test_double_action( self::$comments[1], 'unspam' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Test delete
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $comment = array_pop( $this->_comments );
- $this->_test_double_action( $comment, 'delete' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->_test_double_action( self::$comments[2], 'delete' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxGetCommentsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/ajax/GetComments.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/GetComments.php 2015-10-21 03:01:13 UTC (rev 35310)
+++ trunk/tests/phpunit/tests/ajax/GetComments.php 2015-10-21 03:17:36 UTC (rev 35311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,27 +19,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * A post with at least one comment
</span><span class="cx" style="display: block; padding: 0 10px"> * @var mixed
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $_comment_post = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $comment_post = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * A post with no comments
</span><span class="cx" style="display: block; padding: 0 10px"> * @var mixed
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $_no_comment_post = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $no_comment_post = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * 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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $comment_ids = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post_id = self::factory()->post->create();
- $this->_no_comment_post = get_post( $post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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();
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unset( $GLOBALS['post_id'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,7 +57,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up a default request
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['action'] = 'get-comments';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['p'] = $this->_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['p'] = self::$comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -92,7 +94,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up a default request
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['action'] = 'get-comments';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['p'] = $this->_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['p'] = self::$comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,7 +114,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up a default request
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['action'] = 'get-comments';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['p'] = $this->_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['p'] = self::$comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -152,7 +154,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up a default request
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce'] = wp_create_nonce( 'get-comments' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['action'] = 'get-comments';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['p'] = $this->_no_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['p'] = self::$no_comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedException( 'WPAjaxDieStopException', '1' );
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxReplytoCommentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/ajax/ReplytoComment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/ReplytoComment.php 2015-10-21 03:01:13 UTC (rev 35310)
+++ trunk/tests/phpunit/tests/ajax/ReplytoComment.php 2015-10-21 03:17:36 UTC (rev 35311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,27 +19,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * A post with at least one comment
</span><span class="cx" style="display: block; padding: 0 10px"> * @var mixed
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $_comment_post = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $comment_post = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Draft post
</span><span class="cx" style="display: block; padding: 0 10px"> * @var mixed
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $_draft_post = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $draft_post = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * 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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected static $comment_ids = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post_id = self::factory()->post->create( array( 'post_status' => 'draft' ) );
- $this->_draft_post = get_post( $post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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 );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function tearDown() {
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'query', array( $this, '_block_comments' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> parent::tearDown();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -57,7 +61,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get a comment
</span><span class="cx" style="display: block; padding: 0 10px"> $comments = get_comments( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post_id' => $this->_comment_post->ID
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'post_id' => self::$comment_post->ID
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $comment = array_pop( $comments );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -65,7 +69,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['comment_ID'] = $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['comment_post_ID'] = $this->_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['comment_post_ID'] = self::$comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -101,7 +105,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get a comment
</span><span class="cx" style="display: block; padding: 0 10px"> $comments = get_comments( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post_id' => $this->_comment_post->ID
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'post_id' => self::$comment_post->ID
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $comment = array_pop( $comments );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -109,7 +113,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['comment_ID'] = $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['comment_post_ID'] = $this->_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['comment_post_ID'] = self::$comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -128,7 +132,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get a comment
</span><span class="cx" style="display: block; padding: 0 10px"> $comments = get_comments( array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post_id' => $this->_comment_post->ID
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'post_id' => self::$comment_post->ID
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $comment = array_pop( $comments );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -136,7 +140,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['comment_ID'] = $comment->comment_ID;
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['comment_post_ID'] = $this->_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['comment_post_ID'] = self::$comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -176,7 +180,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up a default request
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['comment_post_ID'] = $this->_draft_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['comment_post_ID'] = self::$draft_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Make the request
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedException( 'WPAjaxDieStopException', 'ERROR: you are replying to a comment on a draft post.' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -198,7 +202,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Set up a default request
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $_POST['comment_post_ID'] = $this->_comment_post->ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $_POST['comment_post_ID'] = self::$comment_post->ID;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Block comments from being saved, simulate a DB error
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'query', array( $this, '_block_comments' ) );
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxTagSearchphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/ajax/TagSearch.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/TagSearch.php 2015-10-21 03:01:13 UTC (rev 35310)
+++ trunk/tests/phpunit/tests/ajax/TagSearch.php 2015-10-21 03:17:36 UTC (rev 35311)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,21 +19,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * List of terms to insert on setup
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private $_terms = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private static $terms = array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'chattels', 'depo', 'energumen', 'figuriste', 'habergeon', 'impropriation'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Setup
- * @todo use a term factory
- */
- public function setUp() {
- parent::setUp();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private static $term_ids = array();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $this->_terms as $term )
- wp_insert_term( $term, 'post_tag' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function wpSetUpBeforeClass() {
+ foreach ( self::$terms as $t ) {
+ self::$term_ids[] = wp_insert_term( $t, 'post_tag' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public static function wpTearDownAfterClass() {
+ foreach ( self::$term_ids as $t ) {
+ wp_delete_term( $t, 'post_tag' );
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Test as an admin
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre>
</div>
</div>
</body>
</html>