<!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>[53785] trunk/tests/phpunit/tests: Tests: Move `wp_insert_post()` tests to their own file.</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 { white-space: pre-line; 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/53785">53785</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/53785","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-07-27 14:59:12 +0000 (Wed, 27 Jul 2022)</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'>Tests: Move `wp_insert_post()` tests to their own file.
Now that there is a separate test class for `wp_insert_post()` tests, some of the pre-existing tests from the general `Tests_Post` class can be moved there.
Includes:
* Removal of unnecessarily setting the current user to Editor for all tests.
* Removal of unnecessarily setting the cron option to an empty array for all tests.
Follow-up to [496/tests], <a href="https://core.trac.wordpress.org/changeset/36607">[36607]</a>, <a href="https://core.trac.wordpress.org/changeset/53782">[53782]</a>, <a href="https://core.trac.wordpress.org/changeset/53783">[53783]</a>.
See <a href="https://core.trac.wordpress.org/ticket/55652">#55652</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestspostwpInsertPostphp">trunk/tests/phpunit/tests/post/wpInsertPost.php</a></li>
<li><a href="#trunktestsphpunittestspostphp">trunk/tests/phpunit/tests/post.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunittestspostwpInsertPostphp"></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/post/wpInsertPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/wpInsertPost.php 2022-07-27 12:25:06 UTC (rev 53784)
+++ trunk/tests/phpunit/tests/post/wpInsertPost.php 2022-07-27 14:59:12 UTC (rev 53785)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2,11 +2,13 @@
</span><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"> * @group post
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @covers ::wp_insert_post
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_Post_wpInsertPost extends WP_UnitTestCase {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> protected static $user_ids = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'administrator' => null,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'editor' => null,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'contributor' => null,
</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">@@ -17,6 +19,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'role' => 'administrator',
</span><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">+ 'editor' => $factory->user->create(
+ array(
+ 'role' => 'editor',
+ )
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'contributor' => $factory->user->create(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'role' => 'contributor',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,6 +73,1154 @@
</span><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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Helper function: return the timestamp(s) of cron jobs for the specified hook and post.
+ */
+ private function next_schedule_for_post( $hook, $post_id ) {
+ return wp_next_scheduled( 'publish_future_post', array( 0 => (int) $post_id ) );
+ }
+
+ /**
+ * Helper function, unsets current user globally.
+ */
+ private function unset_current_user() {
+ global $current_user, $user_ID;
+
+ $current_user = null;
+ $user_ID = null;
+ }
+
+ /**
+ * Test simple valid behavior: insert and get a post.
+ *
+ * @dataProvider data_vb_insert_get_delete
+ */
+ public function test_vb_insert_get_delete( $post_type ) {
+ register_post_type(
+ 'cpt',
+ array(
+ 'taxonomies' => array( 'post_tag', 'ctax' ),
+ )
+ );
+ register_taxonomy( 'ctax', 'cpt' );
+
+ wp_set_current_user( self::$user_ids['editor'] );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => "{$post_type}_content",
+ 'post_title' => "{$post_type}_title",
+ 'tax_input' => array(
+ 'post_tag' => 'tag1,tag2',
+ 'ctax' => 'cterm1,cterm2',
+ ),
+ 'post_type' => $post_type,
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+ $this->assertIsInt( $post_id );
+ $this->assertGreaterThan( 0, $post_id );
+
+ // Fetch the post and make sure it matches.
+ $post = get_post( $post_id );
+
+ $this->assertSame( $data['post_content'], $post->post_content );
+ $this->assertSame( $data['post_title'], $post->post_title );
+ $this->assertSame( $data['post_status'], $post->post_status );
+ $this->assertEquals( $data['post_author'], $post->post_author );
+
+ // Test cache state.
+ $post_cache = wp_cache_get( $post_id, 'posts' );
+ $this->assertInstanceOf( 'stdClass', $post_cache );
+ $this->assertSame( $post_id, $post_cache->ID );
+
+ update_object_term_cache( $post_id, $post_type );
+ $term_cache = wp_cache_get( $post_id, 'post_tag_relationships' );
+ $this->assertIsArray( $term_cache );
+ $this->assertCount( 2, $term_cache );
+
+ $term_cache = wp_cache_get( $post_id, 'ctax_relationships' );
+ if ( 'cpt' === $post_type ) {
+ $this->assertIsArray( $term_cache );
+ $this->assertCount( 2, $term_cache );
+ } else {
+ $this->assertFalse( $term_cache );
+ }
+
+ wp_delete_post( $post_id, true );
+
+ $this->assertFalse( wp_cache_get( $post_id, 'posts' ) );
+ $this->assertFalse( wp_cache_get( $post_id, 'post_tag_relationships' ) );
+ $this->assertFalse( wp_cache_get( $post_id, 'ctax_relationships' ) );
+
+ $GLOBALS['wp_taxonomies']['post_tag']->object_type = array( 'post' );
+ }
+
+ public function data_vb_insert_get_delete() {
+ $post_types = array( 'post', 'cpt' );
+
+ return $this->text_array_to_dataprovider( $post_types );
+ }
+
+ /**
+ * Insert a post with a future date, and make sure the status and cron schedule are correct.
+ */
+ public function test_vb_insert_future() {
+ $future_date = strtotime( '+1 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+ $this->assertIsInt( $post_id );
+ $this->assertGreaterThan( 0, $post_id );
+
+ // Fetch the post and make sure it matches.
+ $post = get_post( $post_id );
+
+ $this->assertSame( $data['post_content'], $post->post_content );
+ $this->assertSame( $data['post_title'], $post->post_title );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertEquals( $data['post_author'], $post->post_author );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // There should be a publish_future_post hook scheduled on the future date.
+ $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ /**
+ * Insert a post with a future date, and make sure the status and cron schedule are correct.
+ */
+ public function test_vb_insert_future_over_dst() {
+ // Some magic days - one DST one not.
+ $future_date_1 = strtotime( 'June 21st +1 year' );
+ $future_date_2 = strtotime( 'Jan 11th +1 year' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ // Fetch the post and make sure has the correct date and status.
+ $post = get_post( $post_id );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // Check that there's a publish_future_post job scheduled at the right time.
+ $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+
+ // Now save it again with a date further in the future.
+ $data['ID'] = $post_id;
+ $data['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' );
+ $data['post_date_gmt'] = null;
+ wp_update_post( $data );
+
+ // Fetch the post again and make sure it has the new post_date.
+ $post = get_post( $post_id );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // And the correct date on the cron job.
+ $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ /**
+ * Future post bug: posts get published at the wrong time if you edit the timestamp.
+ *
+ * @ticket 4710
+ */
+ public function test_vb_insert_future_edit_bug() {
+ $future_date_1 = strtotime( '+1 day' );
+ $future_date_2 = strtotime( '+2 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ // Fetch the post and make sure has the correct date and status.
+ $post = get_post( $post_id );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // Check that there's a publish_future_post job scheduled at the right time.
+ $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+
+ // Now save it again with a date further in the future.
+ $data['ID'] = $post_id;
+ $data['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' );
+ $data['post_date_gmt'] = null;
+ wp_update_post( $data );
+
+ // Fetch the post again and make sure it has the new post_date.
+ $post = get_post( $post_id );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // And the correct date on the cron job.
+ $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ /**
+ * Insert a draft post with a future date, and make sure no cron schedule is set.
+ */
+ public function test_vb_insert_future_draft() {
+ $future_date = strtotime( '+1 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'draft',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+ $this->assertIsInt( $post_id );
+ $this->assertGreaterThan( 0, $post_id );
+
+ // Fetch the post and make sure it matches.
+ $post = get_post( $post_id );
+
+ $this->assertSame( $data['post_content'], $post->post_content );
+ $this->assertSame( $data['post_title'], $post->post_title );
+ $this->assertSame( 'draft', $post->post_status );
+ $this->assertEquals( $data['post_author'], $post->post_author );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // There should be a publish_future_post hook scheduled on the future date.
+ $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+
+ }
+
+ /**
+ * Insert a future post, then edit and change it to draft, and make sure cron gets it right.
+ */
+ public function test_vb_insert_future_change_to_draft() {
+ $future_date_1 = strtotime( '+1 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ // Fetch the post and make sure has the correct date and status.
+ $post = get_post( $post_id );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // Check that there's a publish_future_post job scheduled at the right time.
+ $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+
+ // Now save it again with status set to draft.
+ $data['ID'] = $post_id;
+ $data['post_status'] = 'draft';
+ wp_update_post( $data );
+
+ // Fetch the post again and make sure it has the new post_date.
+ $post = get_post( $post_id );
+ $this->assertSame( 'draft', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // And the correct date on the cron job.
+ $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ /**
+ * Insert a future post, then edit and change the status, and make sure cron gets it right.
+ *
+ * @dataProvider data_vb_insert_future_change_status
+ */
+ public function test_vb_insert_future_change_status( $status ) {
+ $future_date_1 = strtotime( '+1 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => "{$status}_content",
+ 'post_title' => "{$status}_title",
+ 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ // Fetch the post and make sure has the correct date and status.
+ $post = get_post( $post_id );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // Check that there's a publish_future_post job scheduled at the right time.
+ $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+
+ // Now save it again with status changed.
+ $data['ID'] = $post_id;
+ $data['post_status'] = $status;
+ wp_update_post( $data );
+
+ // Fetch the post again and make sure it has the new post_date.
+ $post = get_post( $post_id );
+ $this->assertSame( $status, $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // And the correct date on the cron job.
+ $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ public function data_vb_insert_future_change_status() {
+ $statuses = array(
+ 'draft',
+ 'static',
+ 'object',
+ 'attachment',
+ 'inherit',
+ 'pending',
+ );
+
+ return $this->text_array_to_dataprovider( $statuses );
+ }
+
+ /**
+ * Insert a draft post with a future date, and make sure no cron schedule is set.
+ */
+ public function test_vb_insert_future_private() {
+ $future_date = strtotime( '+1 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'private',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+ $this->assertIsInt( $post_id );
+ $this->assertGreaterThan( 0, $post_id );
+
+ // Fetch the post and make sure it matches.
+ $post = get_post( $post_id );
+
+ $this->assertSame( $data['post_content'], $post->post_content );
+ $this->assertSame( $data['post_title'], $post->post_title );
+ $this->assertSame( 'private', $post->post_status );
+ $this->assertEquals( $data['post_author'], $post->post_author );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // There should be a publish_future_post hook scheduled on the future date.
+ $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ /**
+ * Insert a post with an invalid date, make sure it fails.
+ *
+ * @ticket 17180
+ */
+ public function test_vb_insert_invalid_date() {
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => '2012-02-30 00:00:00',
+ );
+
+ // Test both return paths with or without WP_Error.
+ $post_id = wp_insert_post( $data, true );
+ $this->assertWPError( $post_id );
+ $this->assertSame( 'invalid_date', $post_id->get_error_code() );
+
+ $post_id = wp_insert_post( $data );
+ $this->assertSame( 0, $post_id );
+ }
+
+ /**
+ * Insert a future post, then edit and change it to private, and make sure cron gets it right.
+ */
+ public function test_vb_insert_future_change_to_private() {
+ $future_date_1 = strtotime( '+1 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ // Fetch the post and make sure has the correct date and status.
+ $post = get_post( $post_id );
+ $this->assertSame( 'future', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // Check that there's a publish_future_post job scheduled at the right time.
+ $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+
+ // Now save it again with status set to draft.
+ $data['ID'] = $post_id;
+ $data['post_status'] = 'private';
+ wp_update_post( $data );
+
+ // Fetch the post again and make sure it has the new post_date.
+ $post = get_post( $post_id );
+ $this->assertSame( 'private', $post->post_status );
+ $this->assertSame( $data['post_date'], $post->post_date );
+
+ // And the correct date on the cron job.
+ $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ /**
+ * @ticket 5305
+ */
+ public function test_wp_insert_post_should_not_allow_a_bare_numeric_slug_that_might_conflict_with_a_date_archive_when_generating_from_an_empty_post_title() {
+ $this->set_permalink_structure( '/%postname%/' );
+
+ $post_id = wp_insert_post(
+ array(
+ 'post_title' => '',
+ 'post_content' => 'test',
+ 'post_status' => 'publish',
+ 'post_type' => 'post',
+ )
+ );
+
+ $post = get_post( $post_id );
+
+ $this->assertSame( "$post_id-2", $post->post_name );
+ }
+
+ /**
+ * @ticket 5305
+ * @ticket 33392
+ */
+ public function test_wp_insert_post_should_invalidate_post_cache_before_generating_guid_when_post_name_is_empty_and_is_generated_from_the_post_ID() {
+ register_post_type( 'wptests_pt' );
+
+ $post_id = wp_insert_post(
+ array(
+ 'post_title' => '',
+ 'post_type' => 'wptests_pt',
+ 'post_status' => 'publish',
+ )
+ );
+
+ $post = get_post( $post_id );
+
+ $this->assertStringContainsString( 'wptests_pt=' . $post_id, $post->guid );
+ }
+
+ /**
+ * @ticket 55877
+ * @covers ::wp_insert_post
+ */
+ public function test_wp_insert_post_should_not_trigger_warning_for_pending_posts_with_unknown_cpt() {
+ $post_id = wp_insert_post(
+ array(
+ 'post_title' => 'title',
+ 'post_type' => 'unknown',
+ 'post_status' => 'pending',
+ )
+ );
+
+ $this->assertIsInt( $post_id );
+ $this->assertGreaterThan( 0, $post_id );
+ }
+
+ /**
+ * @ticket 20451
+ */
+ public function test_wp_insert_post_with_meta_input() {
+ $post_id = wp_insert_post(
+ array(
+ 'post_title' => '',
+ 'post_content' => 'test',
+ 'post_status' => 'publish',
+ 'post_type' => 'post',
+ 'meta_input' => array(
+ 'hello' => 'world',
+ 'foo' => 'bar',
+ ),
+ )
+ );
+
+ $this->assertSame( 'world', get_post_meta( $post_id, 'hello', true ) );
+ $this->assertSame( 'bar', get_post_meta( $post_id, 'foo', true ) );
+ }
+
+ /**
+ * "When I delete a future post using wp_delete_post( $post->ID ) it does not update the cron correctly."
+ *
+ * @ticket 5364
+ * @covers ::wp_delete_post
+ */
+ public function test_delete_future_post_cron() {
+ $future_date = strtotime( '+1 day' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ // Check that there's a publish_future_post job scheduled at the right time.
+ $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+
+ // Now delete the post and make sure the cron entry is removed.
+ wp_delete_post( $post_id );
+
+ $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
+ }
+
+ /**
+ * Bug: permalink doesn't work if post title is empty.
+ *
+ * Might only fail if the post ID is greater than four characters.
+ *
+ * @ticket 5305
+ */
+ public function test_permalink_without_title() {
+ $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
+
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => '',
+ 'post_date' => '2007-10-31 06:15:00',
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ // Permalink should include the post ID at the end.
+ $expected = get_option( 'siteurl' ) . '/2007/10/31/' . $post_id . '/';
+ $this->assertSame( $expected, get_permalink( $post_id ) );
+ }
+
+ /**
+ * @ticket 23708
+ */
+ public function test_get_post_ancestors_within_loop() {
+ global $post;
+
+ $parent_id = self::factory()->post->create();
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_parent' => $parent_id,
+ )
+ );
+
+ $this->assertSame( array( $parent_id ), get_post_ancestors( 0 ) );
+ }
+
+ /**
+ * @ticket 23474
+ * @covers ::wp_update_post
+ */
+ public function test_update_invalid_post_id() {
+ $post_id = self::factory()->post->create();
+ $post = get_post( $post_id, ARRAY_A );
+
+ $post['ID'] = 123456789;
+
+ $this->assertSame( 0, wp_insert_post( $post ) );
+ $this->assertSame( 0, wp_update_post( $post ) );
+
+ $this->assertInstanceOf( 'WP_Error', wp_insert_post( $post, true ) );
+ $this->assertInstanceOf( 'WP_Error', wp_update_post( $post, true ) );
+
+ }
+
+ /**
+ * @ticket 19373
+ */
+ public function test_insert_programmatic_sanitized() {
+ $this->unset_current_user();
+
+ register_taxonomy( 'test_tax', 'post' );
+
+ $title = 'title';
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => $title,
+ 'tax_input' => array(
+ 'test_tax' => array( 'term', 'term2', 'term3' ),
+ ),
+ );
+
+ $post_id = wp_insert_post( $data, true, true );
+ $this->assertIsInt( $post_id );
+ $this->assertGreaterThan( 0, $post_id );
+
+ $post = get_post( $post_id );
+ $this->assertEquals( self::$user_ids['editor'], $post->post_author );
+ $this->assertSame( $title, $post->post_title );
+ }
+
+ /**
+ * @ticket 31168
+ */
+ public function test_wp_insert_post_default_comment_ping_status_open() {
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ )
+ );
+ $post = get_post( $post_id );
+
+ $this->assertSame( 'open', $post->comment_status );
+ $this->assertSame( 'open', $post->ping_status );
+ }
+
+ /**
+ * @ticket 31168
+ */
+ public function test_wp_insert_post_page_default_comment_ping_status_closed() {
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_type' => 'page',
+ )
+ );
+ $post = get_post( $post_id );
+
+ $this->assertSame( 'closed', $post->comment_status );
+ $this->assertSame( 'closed', $post->ping_status );
+ }
+
+ /**
+ * @ticket 31168
+ */
+ public function test_wp_insert_post_cpt_default_comment_ping_status_open() {
+ $post_type = rand_str( 20 );
+ register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => rand_str(),
+ 'post_title' => rand_str(),
+ 'post_type' => $post_type,
+ )
+ );
+ $post = get_post( $post_id );
+
+ _unregister_post_type( $post_type );
+
+ $this->assertSame( 'open', $post->comment_status );
+ $this->assertSame( 'open', $post->ping_status );
+ }
+
+ /**
+ * @ticket 31168
+ */
+ public function test_wp_insert_post_cpt_default_comment_ping_status_closed() {
+ $post_type = rand_str( 20 );
+ register_post_type( $post_type );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => rand_str(),
+ 'post_title' => rand_str(),
+ 'post_type' => $post_type,
+ )
+ );
+ $post = get_post( $post_id );
+
+ _unregister_post_type( $post_type );
+
+ $this->assertSame( 'closed', $post->comment_status );
+ $this->assertSame( 'closed', $post->ping_status );
+ }
+
+ /**
+ * If a post is updated without providing a post_name param,
+ * a new slug should not be generated.
+ *
+ * @ticket 34865
+ */
+ public function test_post_updates_without_slug_provided() {
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_title' => 'Stuff',
+ 'post_status' => 'publish',
+ )
+ );
+
+ $data = array(
+ 'ID' => $post_id,
+ 'post_title' => 'Stuff and Things',
+ );
+
+ wp_insert_post( $data );
+
+ $updated_post = get_post( $post_id );
+ // Ensure changing the post_title didn't modify the post_name.
+ $this->assertSame( 'stuff', $updated_post->post_name );
+ }
+
+ /**
+ * @ticket 32585
+ */
+ public function test_wp_insert_post_author_zero() {
+ $post_id = self::factory()->post->create( array( 'post_author' => 0 ) );
+
+ $this->assertEquals( 0, get_post( $post_id )->post_author );
+ }
+
+ /**
+ * @ticket 32585
+ */
+ public function test_wp_insert_post_author_null() {
+ wp_set_current_user( self::$user_ids['editor'] );
+
+ $post_id = self::factory()->post->create( array( 'post_author' => null ) );
+
+ $this->assertEquals( self::$user_ids['editor'], get_post( $post_id )->post_author );
+ }
+
+ /**
+ * @ticket 15946
+ */
+ public function test_wp_insert_post_should_respect_post_date_gmt() {
+ $data = array(
+ 'post_author' => self::$user_ids['editor'],
+ 'post_status' => 'publish',
+ 'post_content' => 'content',
+ 'post_title' => 'title',
+ 'post_date_gmt' => '2014-01-01 12:00:00',
+ );
+
+ // Insert a post and make sure the ID is OK.
+ $post_id = wp_insert_post( $data );
+
+ $post = get_post( $post_id );
+
+ $this->assertSame( $data['post_content'], $post->post_content );
+ $this->assertSame( $data['post_title'], $post->post_title );
+ $this->assertEquals( $data['post_author'], $post->post_author );
+ $this->assertSame( get_date_from_gmt( $data['post_date_gmt'] ), $post->post_date );
+ $this->assertSame( $data['post_date_gmt'], $post->post_date_gmt );
+ }
+
+ /**
+ * Test ensuring that the post_name (UUID) is preserved when wp_insert_post()/wp_update_post() is called.
+ *
+ * @see _wp_customize_changeset_filter_insert_post_data()
+ * @ticket 30937
+ */
+ public function test_wp_insert_post_for_customize_changeset_should_not_drop_post_name() {
+ $this->assertSame( 10, has_filter( 'wp_insert_post_data', '_wp_customize_changeset_filter_insert_post_data' ) );
+
+ $changeset_data = array(
+ 'blogname' => array(
+ 'value' => 'Hello World',
+ ),
+ );
+
+ wp_set_current_user( self::$user_ids['contributor'] );
+
+ $uuid = wp_generate_uuid4();
+ $post_id = wp_insert_post(
+ array(
+ 'post_type' => 'customize_changeset',
+ 'post_name' => strtoupper( $uuid ),
+ 'post_content' => wp_json_encode( $changeset_data ),
+ )
+ );
+ $this->assertSame( $uuid, get_post( $post_id )->post_name, 'Expected lower-case UUID4 to be inserted.' );
+ $this->assertSame( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
+
+ $changeset_data['blogname']['value'] = 'Hola Mundo';
+ wp_update_post(
+ array(
+ 'ID' => $post_id,
+ 'post_status' => 'draft',
+ 'post_content' => wp_json_encode( $changeset_data ),
+ )
+ );
+ $this->assertSame( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for drafts.' );
+ $this->assertSame( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
+
+ $changeset_data['blogname']['value'] = 'Hallo Welt';
+ wp_update_post(
+ array(
+ 'ID' => $post_id,
+ 'post_status' => 'pending',
+ 'post_content' => wp_json_encode( $changeset_data ),
+ )
+ );
+ $this->assertSame( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for pending.' );
+ $this->assertSame( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
+ }
+
+ /**
+ * @ticket 48113
+ */
+ public function test_insert_post_should_respect_date_floating_post_status_arg() {
+ register_post_status( 'floating', array( 'date_floating' => true ) );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_status' => 'floating',
+ 'post_date' => null,
+ 'post_date_gmt' => null,
+ )
+ );
+
+ $post = get_post( $post_id );
+ self::assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
+ }
+
+ /**
+ * @ticket 48113
+ */
+ public function test_insert_post_should_respect_date_floating_post_status_arg_not_set() {
+ register_post_status( 'not-floating', array( 'date_floating' => false ) );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_status' => 'floating',
+ 'post_date' => null,
+ 'post_date_gmt' => null,
+ )
+ );
+
+ $post = get_post( $post_id );
+ self::assertEqualsWithDelta(
+ strtotime( gmdate( 'Y-m-d H:i:s' ) ),
+ strtotime( $post->post_date_gmt ),
+ 2,
+ 'The dates should be equal'
+ );
+ }
+
+ /**
+ * Test ensuring that wp_update_post() does not unintentionally modify post tags
+ * if the post has several tags with the same name but different slugs.
+ *
+ * Tags should only be modified if 'tags_input' parameter was explicitly provided,
+ * and is different from the existing tags.
+ *
+ * @ticket 45121
+ * @covers ::wp_update_post
+ */
+ public function test_update_post_should_only_modify_post_tags_if_different_tags_input_was_provided() {
+ $tag_1 = wp_insert_term( 'wp_update_post_tag', 'post_tag', array( 'slug' => 'wp_update_post_tag_1' ) );
+ $tag_2 = wp_insert_term( 'wp_update_post_tag', 'post_tag', array( 'slug' => 'wp_update_post_tag_2' ) );
+ $tag_3 = wp_insert_term( 'wp_update_post_tag', 'post_tag', array( 'slug' => 'wp_update_post_tag_3' ) );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'tags_input' => array( $tag_1['term_id'], $tag_2['term_id'] ),
+ )
+ );
+
+ $post = get_post( $post_id );
+
+ $tags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
+ $this->assertSameSets( array( $tag_1['term_id'], $tag_2['term_id'] ), $tags );
+
+ wp_update_post( $post );
+
+ $tags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
+ $this->assertSameSets( array( $tag_1['term_id'], $tag_2['term_id'] ), $tags );
+
+ wp_update_post(
+ array(
+ 'ID' => $post->ID,
+ 'tags_input' => array( $tag_2['term_id'], $tag_3['term_id'] ),
+ )
+ );
+
+ $tags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
+ $this->assertSameSets( array( $tag_2['term_id'], $tag_3['term_id'] ), $tags );
+ }
+
+ /**
+ * @ticket 52187
+ */
+ public function test_insert_empty_post_date() {
+ $post_date_gmt = '2020-12-29 10:11:45';
+ $invalid_date = '2020-12-41 14:15:27';
+
+ // Empty post_date_gmt with floating status
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_status' => 'draft',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertEqualsWithDelta(
+ strtotime( gmdate( 'Y-m-d H:i:s' ) ),
+ strtotime( $post->post_date ),
+ 2,
+ 'The dates should be equal'
+ );
+ $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date_gmt' => '0000-00-00 00:00:00',
+ 'post_status' => 'draft',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertEqualsWithDelta(
+ strtotime( gmdate( 'Y-m-d H:i:s' ) ),
+ strtotime( $post->post_date ),
+ 2,
+ 'The dates should be equal'
+ );
+ $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+ // Empty post_date_gmt without floating status
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_status' => 'publish',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertEqualsWithDelta(
+ strtotime( gmdate( 'Y-m-d H:i:s' ) ),
+ strtotime( $post->post_date ),
+ 2,
+ 'The dates should be equal'
+ );
+ $this->assertEqualsWithDelta(
+ strtotime( gmdate( 'Y-m-d H:i:s' ) ),
+ strtotime( get_gmt_from_date( $post->post_date ) ),
+ 2,
+ 'The dates should be equal'
+ );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date_gmt' => '0000-00-00 00:00:00',
+ 'post_status' => 'publish',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertEqualsWithDelta(
+ strtotime( gmdate( 'Y-m-d H:i:s' ) ),
+ strtotime( $post->post_date ),
+ 2,
+ 'The dates should be equal'
+ );
+ $this->assertEqualsWithDelta(
+ strtotime( gmdate( 'Y-m-d H:i:s' ) ),
+ strtotime( get_gmt_from_date( $post->post_date ) ),
+ 2,
+ 'The dates should be equal'
+ );
+
+ // Valid post_date_gmt
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date_gmt' => $post_date_gmt,
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( get_date_from_gmt( $post_date_gmt ), $post->post_date );
+ $this->assertSame( $post_date_gmt, $post->post_date_gmt );
+
+ // Invalid post_date_gmt
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date_gmt' => $invalid_date,
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( '1970-01-01 00:00:00', $post->post_date );
+ $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
+ }
+
+ /**
+ * @ticket 52187
+ */
+ public function test_insert_valid_post_date() {
+ $post_date = '2020-12-28 11:26:35';
+ $post_date_gmt = '2020-12-29 10:11:45';
+ $invalid_date = '2020-12-41 14:15:27';
+
+ // Empty post_date_gmt with floating status
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $post_date,
+ 'post_status' => 'draft',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( $post_date, $post->post_date );
+ $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $post_date,
+ 'post_date_gmt' => '0000-00-00 00:00:00',
+ 'post_status' => 'draft',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( $post_date, $post->post_date );
+ $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+ // Empty post_date_gmt without floating status
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $post_date,
+ 'post_status' => 'publish',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( $post_date, $post->post_date );
+ $this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $post_date,
+ 'post_date_gmt' => '0000-00-00 00:00:00',
+ 'post_status' => 'publish',
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( $post_date, $post->post_date );
+ $this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
+
+ // Valid post_date_gmt
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $post_date,
+ 'post_date_gmt' => $post_date_gmt,
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( $post_date, $post->post_date );
+ $this->assertSame( $post_date_gmt, $post->post_date_gmt );
+
+ // Invalid post_date_gmt
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $post_date,
+ 'post_date_gmt' => $invalid_date,
+ )
+ );
+ $post = get_post( $post_id );
+ $this->assertSame( $post_date, $post->post_date );
+ $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
+ }
+
+ /**
+ * @ticket 52187
+ */
+ public function test_insert_invalid_post_date() {
+ $post_date = '2020-12-28 11:26:35';
+ $post_date_gmt = '2020-12-29 10:11:45';
+ $invalid_date = '2020-12-41 14:15:27';
+
+ // Empty post_date_gmt with floating status
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $invalid_date,
+ 'post_status' => 'draft',
+ )
+ );
+ $this->assertSame( 0, $post_id );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $invalid_date,
+ 'post_date_gmt' => '0000-00-00 00:00:00',
+ 'post_status' => 'draft',
+ )
+ );
+ $this->assertSame( 0, $post_id );
+
+ // Empty post_date_gmt without floating status
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $invalid_date,
+ 'post_status' => 'publish',
+ )
+ );
+ $this->assertSame( 0, $post_id );
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $invalid_date,
+ 'post_date_gmt' => '0000-00-00 00:00:00',
+ 'post_status' => 'publish',
+ )
+ );
+ $this->assertSame( 0, $post_id );
+
+ // Valid post_date_gmt
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $invalid_date,
+ 'post_date_gmt' => $post_date_gmt,
+ )
+ );
+ $this->assertSame( 0, $post_id );
+
+ // Invalid post_date_gmt
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_date' => $invalid_date,
+ 'post_date_gmt' => $invalid_date,
+ )
+ );
+ $this->assertSame( 0, $post_id );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 11863
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_trashing_a_post_should_add_trashed_suffix_to_post_name() {
</span></span></pre></div>
<a id="trunktestsphpunittestspostphp"></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/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post.php 2022-07-27 12:25:06 UTC (rev 53784)
+++ trunk/tests/phpunit/tests/post.php 2022-07-27 14:59:12 UTC (rev 53785)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -30,604 +30,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> remove_role( 'grammarian' );
</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">- public function set_up() {
- parent::set_up();
-
- wp_set_current_user( self::$editor_id );
- _set_cron_array( array() );
- }
-
- /**
- * Helper function: return the timestamp(s) of cron jobs for the specified hook and post.
- */
- private function next_schedule_for_post( $hook, $post_id ) {
- return wp_next_scheduled( 'publish_future_post', array( 0 => (int) $post_id ) );
- }
-
- /**
- * Helper function, unsets current user globally.
- */
- private function unset_current_user() {
- global $current_user, $user_ID;
-
- $current_user = null;
- $user_ID = null;
- }
-
- /**
- * Test simple valid behavior: insert and get a post.
- *
- * @dataProvider data_vb_insert_get_delete
- */
- public function test_vb_insert_get_delete( $post_type ) {
- register_post_type(
- 'cpt',
- array(
- 'taxonomies' => array( 'post_tag', 'ctax' ),
- )
- );
- register_taxonomy( 'ctax', 'cpt' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => "{$post_type}_content",
- 'post_title' => "{$post_type}_title",
- 'tax_input' => array(
- 'post_tag' => 'tag1,tag2',
- 'ctax' => 'cterm1,cterm2',
- ),
- 'post_type' => $post_type,
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
- $this->assertIsInt( $post_id );
- $this->assertGreaterThan( 0, $post_id );
-
- // Fetch the post and make sure it matches.
- $post = get_post( $post_id );
-
- $this->assertSame( $data['post_content'], $post->post_content );
- $this->assertSame( $data['post_title'], $post->post_title );
- $this->assertSame( $data['post_status'], $post->post_status );
- $this->assertEquals( $data['post_author'], $post->post_author );
-
- // Test cache state.
- $post_cache = wp_cache_get( $post_id, 'posts' );
- $this->assertInstanceOf( 'stdClass', $post_cache );
- $this->assertSame( $post_id, $post_cache->ID );
-
- update_object_term_cache( $post_id, $post_type );
- $term_cache = wp_cache_get( $post_id, 'post_tag_relationships' );
- $this->assertIsArray( $term_cache );
- $this->assertCount( 2, $term_cache );
-
- $term_cache = wp_cache_get( $post_id, 'ctax_relationships' );
- if ( 'cpt' === $post_type ) {
- $this->assertIsArray( $term_cache );
- $this->assertCount( 2, $term_cache );
- } else {
- $this->assertFalse( $term_cache );
- }
-
- wp_delete_post( $post_id, true );
-
- $this->assertFalse( wp_cache_get( $post_id, 'posts' ) );
- $this->assertFalse( wp_cache_get( $post_id, 'post_tag_relationships' ) );
- $this->assertFalse( wp_cache_get( $post_id, 'ctax_relationships' ) );
-
- $GLOBALS['wp_taxonomies']['post_tag']->object_type = array( 'post' );
- }
-
- public function data_vb_insert_get_delete() {
- $post_types = array( 'post', 'cpt' );
-
- return $this->text_array_to_dataprovider( $post_types );
- }
-
- /**
- * Insert a post with a future date, and make sure the status and cron schedule are correct.
- */
- public function test_vb_insert_future() {
- $future_date = strtotime( '+1 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
- $this->assertIsInt( $post_id );
- $this->assertGreaterThan( 0, $post_id );
-
- // Fetch the post and make sure it matches.
- $post = get_post( $post_id );
-
- $this->assertSame( $data['post_content'], $post->post_content );
- $this->assertSame( $data['post_title'], $post->post_title );
- $this->assertSame( 'future', $post->post_status );
- $this->assertEquals( $data['post_author'], $post->post_author );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // There should be a publish_future_post hook scheduled on the future date.
- $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- /**
- * Insert a post with a future date, and make sure the status and cron schedule are correct.
- */
- public function test_vb_insert_future_over_dst() {
- // Some magic days - one DST one not.
- $future_date_1 = strtotime( 'June 21st +1 year' );
- $future_date_2 = strtotime( 'Jan 11th +1 year' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- // Fetch the post and make sure has the correct date and status.
- $post = get_post( $post_id );
- $this->assertSame( 'future', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // Check that there's a publish_future_post job scheduled at the right time.
- $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
-
- // Now save it again with a date further in the future.
- $data['ID'] = $post_id;
- $data['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' );
- $data['post_date_gmt'] = null;
- wp_update_post( $data );
-
- // Fetch the post again and make sure it has the new post_date.
- $post = get_post( $post_id );
- $this->assertSame( 'future', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // And the correct date on the cron job.
- $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- /**
- * Future post bug: posts get published at the wrong time if you edit the timestamp.
- *
- * @ticket 4710
- */
- public function test_vb_insert_future_edit_bug() {
- $future_date_1 = strtotime( '+1 day' );
- $future_date_2 = strtotime( '+2 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- // Fetch the post and make sure has the correct date and status.
- $post = get_post( $post_id );
- $this->assertSame( 'future', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // Check that there's a publish_future_post job scheduled at the right time.
- $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
-
- // Now save it again with a date further in the future.
- $data['ID'] = $post_id;
- $data['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' );
- $data['post_date_gmt'] = null;
- wp_update_post( $data );
-
- // Fetch the post again and make sure it has the new post_date.
- $post = get_post( $post_id );
- $this->assertSame( 'future', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // And the correct date on the cron job.
- $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- /**
- * Insert a draft post with a future date, and make sure no cron schedule is set.
- */
- public function test_vb_insert_future_draft() {
- $future_date = strtotime( '+1 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'draft',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
- $this->assertIsInt( $post_id );
- $this->assertGreaterThan( 0, $post_id );
-
- // Fetch the post and make sure it matches.
- $post = get_post( $post_id );
-
- $this->assertSame( $data['post_content'], $post->post_content );
- $this->assertSame( $data['post_title'], $post->post_title );
- $this->assertSame( 'draft', $post->post_status );
- $this->assertEquals( $data['post_author'], $post->post_author );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // There should be a publish_future_post hook scheduled on the future date.
- $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
-
- }
-
- /**
- * Insert a future post, then edit and change it to draft, and make sure cron gets it right.
- */
- public function test_vb_insert_future_change_to_draft() {
- $future_date_1 = strtotime( '+1 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- // Fetch the post and make sure has the correct date and status.
- $post = get_post( $post_id );
- $this->assertSame( 'future', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // Check that there's a publish_future_post job scheduled at the right time.
- $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
-
- // Now save it again with status set to draft.
- $data['ID'] = $post_id;
- $data['post_status'] = 'draft';
- wp_update_post( $data );
-
- // Fetch the post again and make sure it has the new post_date.
- $post = get_post( $post_id );
- $this->assertSame( 'draft', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // And the correct date on the cron job.
- $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- /**
- * Insert a future post, then edit and change the status, and make sure cron gets it right.
- *
- * @dataProvider data_vb_insert_future_change_status
- */
- public function test_vb_insert_future_change_status( $status ) {
- $future_date_1 = strtotime( '+1 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => "{$status}_content",
- 'post_title' => "{$status}_title",
- 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- // Fetch the post and make sure has the correct date and status.
- $post = get_post( $post_id );
- $this->assertSame( 'future', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // Check that there's a publish_future_post job scheduled at the right time.
- $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
-
- // Now save it again with status changed.
- $data['ID'] = $post_id;
- $data['post_status'] = $status;
- wp_update_post( $data );
-
- // Fetch the post again and make sure it has the new post_date.
- $post = get_post( $post_id );
- $this->assertSame( $status, $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // And the correct date on the cron job.
- $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- public function data_vb_insert_future_change_status() {
- $statuses = array(
- 'draft',
- 'static',
- 'object',
- 'attachment',
- 'inherit',
- 'pending',
- );
-
- return $this->text_array_to_dataprovider( $statuses );
- }
-
- /**
- * Insert a draft post with a future date, and make sure no cron schedule is set.
- */
- public function test_vb_insert_future_private() {
- $future_date = strtotime( '+1 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'private',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
- $this->assertIsInt( $post_id );
- $this->assertGreaterThan( 0, $post_id );
-
- // Fetch the post and make sure it matches.
- $post = get_post( $post_id );
-
- $this->assertSame( $data['post_content'], $post->post_content );
- $this->assertSame( $data['post_title'], $post->post_title );
- $this->assertSame( 'private', $post->post_status );
- $this->assertEquals( $data['post_author'], $post->post_author );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // There should be a publish_future_post hook scheduled on the future date.
- $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- /**
- * Insert a post with an invalid date, make sure it fails.
- *
- * @ticket 17180
- */
- public function test_vb_insert_invalid_date() {
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => '2012-02-30 00:00:00',
- );
-
- // Test both return paths with or without WP_Error.
- $post_id = wp_insert_post( $data, true );
- $this->assertWPError( $post_id );
- $this->assertSame( 'invalid_date', $post_id->get_error_code() );
-
- $post_id = wp_insert_post( $data );
- $this->assertSame( 0, $post_id );
- }
-
- /**
- * Insert a future post, then edit and change it to private, and make sure cron gets it right.
- */
- public function test_vb_insert_future_change_to_private() {
- $future_date_1 = strtotime( '+1 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- // Fetch the post and make sure has the correct date and status.
- $post = get_post( $post_id );
- $this->assertSame( 'future', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // Check that there's a publish_future_post job scheduled at the right time.
- $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
-
- // Now save it again with status set to draft.
- $data['ID'] = $post_id;
- $data['post_status'] = 'private';
- wp_update_post( $data );
-
- // Fetch the post again and make sure it has the new post_date.
- $post = get_post( $post_id );
- $this->assertSame( 'private', $post->post_status );
- $this->assertSame( $data['post_date'], $post->post_date );
-
- // And the correct date on the cron job.
- $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- /**
- * @ticket 5305
- */
- public function test_wp_insert_post_should_not_allow_a_bare_numeric_slug_that_might_conflict_with_a_date_archive_when_generating_from_an_empty_post_title() {
- $this->set_permalink_structure( '/%postname%/' );
-
- $post_id = wp_insert_post(
- array(
- 'post_title' => '',
- 'post_content' => 'test',
- 'post_status' => 'publish',
- 'post_type' => 'post',
- )
- );
-
- $post = get_post( $post_id );
-
- $this->assertSame( "$post_id-2", $post->post_name );
- }
-
- /**
- * @ticket 5305
- * @ticket 33392
- */
- public function test_wp_insert_post_should_invalidate_post_cache_before_generating_guid_when_post_name_is_empty_and_is_generated_from_the_post_ID() {
- register_post_type( 'wptests_pt' );
-
- $post_id = wp_insert_post(
- array(
- 'post_title' => '',
- 'post_type' => 'wptests_pt',
- 'post_status' => 'publish',
- )
- );
-
- $post = get_post( $post_id );
-
- $this->assertStringContainsString( 'wptests_pt=' . $post_id, $post->guid );
- }
-
- /**
- * @ticket 55877
- * @covers ::wp_insert_post
- */
- public function test_wp_insert_post_should_not_trigger_warning_for_pending_posts_with_unknown_cpt() {
- $post_id = wp_insert_post(
- array(
- 'post_title' => 'title',
- 'post_type' => 'unknown',
- 'post_status' => 'pending',
- )
- );
-
- $this->assertIsInt( $post_id );
- $this->assertGreaterThan( 0, $post_id );
- }
-
- /**
- * @ticket 20451
- */
- public function test_wp_insert_post_with_meta_input() {
- $post_id = wp_insert_post(
- array(
- 'post_title' => '',
- 'post_content' => 'test',
- 'post_status' => 'publish',
- 'post_type' => 'post',
- 'meta_input' => array(
- 'hello' => 'world',
- 'foo' => 'bar',
- ),
- )
- );
-
- $this->assertSame( 'world', get_post_meta( $post_id, 'hello', true ) );
- $this->assertSame( 'bar', get_post_meta( $post_id, 'foo', true ) );
- }
-
- /**
- * "When I delete a future post using wp_delete_post( $post->ID ) it does not update the cron correctly."
- *
- * @ticket 5364
- */
- public function test_delete_future_post_cron() {
- $future_date = strtotime( '+1 day' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date' => date_format( date_create( "@{$future_date}" ), 'Y-m-d H:i:s' ),
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- // Check that there's a publish_future_post job scheduled at the right time.
- $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
-
- // Now delete the post and make sure the cron entry is removed.
- wp_delete_post( $post_id );
-
- $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) );
- }
-
- /**
- * Bug: permalink doesn't work if post title is empty.
- *
- * Might only fail if the post ID is greater than four characters.
- *
- * @ticket 5305
- */
- public function test_permalink_without_title() {
- $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
-
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => '',
- 'post_date' => '2007-10-31 06:15:00',
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- // Permalink should include the post ID at the end.
- $expected = get_option( 'siteurl' ) . '/2007/10/31/' . $post_id . '/';
- $this->assertSame( $expected, get_permalink( $post_id ) );
- }
-
- /**
- * @ticket 23708
- */
- public function test_get_post_ancestors_within_loop() {
- global $post;
-
- $parent_id = self::factory()->post->create();
- $post = self::factory()->post->create_and_get(
- array(
- 'post_parent' => $parent_id,
- )
- );
-
- $this->assertSame( array( $parent_id ), get_post_ancestors( 0 ) );
- }
-
- /**
- * @ticket 23474
- */
- public function test_update_invalid_post_id() {
- $post_id = self::factory()->post->create();
- $post = get_post( $post_id, ARRAY_A );
-
- $post['ID'] = 123456789;
-
- $this->assertSame( 0, wp_insert_post( $post ) );
- $this->assertSame( 0, wp_update_post( $post ) );
-
- $this->assertInstanceOf( 'WP_Error', wp_insert_post( $post, true ) );
- $this->assertInstanceOf( 'WP_Error', wp_update_post( $post, true ) );
-
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_parse_post_content_single_page() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $multipage, $pages, $numpages;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -737,34 +139,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @ticket 19373
- */
- public function test_insert_programmatic_sanitized() {
- $this->unset_current_user();
-
- register_taxonomy( 'test_tax', 'post' );
-
- $title = 'title';
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => $title,
- 'tax_input' => array(
- 'test_tax' => array( 'term', 'term2', 'term3' ),
- ),
- );
-
- $post_id = wp_insert_post( $data, true, true );
- $this->assertIsInt( $post_id );
- $this->assertGreaterThan( 0, $post_id );
-
- $post = get_post( $post_id );
- $this->assertEquals( self::$editor_id, $post->post_author );
- $this->assertSame( $title, $post->post_title );
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * @ticket 24803
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_count_posts() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -878,6 +252,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $post = self::factory()->post->create( array( 'post_type' => $post_type ) );
</span><span class="cx" style="display: block; padding: 0 10px"> wp_set_object_terms( $post, 'foo', $tax );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_current_user( self::$editor_id );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $wp_tag_cloud = wp_tag_cloud(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => $post_type,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -936,91 +312,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @ticket 31168
- */
- public function test_wp_insert_post_default_comment_ping_status_open() {
- $post_id = self::factory()->post->create(
- array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- )
- );
- $post = get_post( $post_id );
-
- $this->assertSame( 'open', $post->comment_status );
- $this->assertSame( 'open', $post->ping_status );
- }
-
- /**
- * @ticket 31168
- */
- public function test_wp_insert_post_page_default_comment_ping_status_closed() {
- $post_id = self::factory()->post->create(
- array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_type' => 'page',
- )
- );
- $post = get_post( $post_id );
-
- $this->assertSame( 'closed', $post->comment_status );
- $this->assertSame( 'closed', $post->ping_status );
- }
-
- /**
- * @ticket 31168
- */
- public function test_wp_insert_post_cpt_default_comment_ping_status_open() {
- $post_type = rand_str( 20 );
- register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => rand_str(),
- 'post_title' => rand_str(),
- 'post_type' => $post_type,
- )
- );
- $post = get_post( $post_id );
-
- _unregister_post_type( $post_type );
-
- $this->assertSame( 'open', $post->comment_status );
- $this->assertSame( 'open', $post->ping_status );
- }
-
- /**
- * @ticket 31168
- */
- public function test_wp_insert_post_cpt_default_comment_ping_status_closed() {
- $post_type = rand_str( 20 );
- register_post_type( $post_type );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => rand_str(),
- 'post_title' => rand_str(),
- 'post_type' => $post_type,
- )
- );
- $post = get_post( $post_id );
-
- _unregister_post_type( $post_type );
-
- $this->assertSame( 'closed', $post->comment_status );
- $this->assertSame( 'closed', $post->ping_status );
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * If a post is sticky and is updated by a user that does not have the publish_post capability,
</span><span class="cx" style="display: block; padding: 0 10px"> * it should _stay_ sticky.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1127,74 +418,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( 1, $a2->get_call_count() );
</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">- /**
- * If a post is updated without providing a post_name param,
- * a new slug should not be generated.
- *
- * @ticket 34865
- */
- public function test_post_updates_without_slug_provided() {
- $post_id = self::factory()->post->create(
- array(
- 'post_title' => 'Stuff',
- 'post_status' => 'publish',
- )
- );
-
- $data = array(
- 'ID' => $post_id,
- 'post_title' => 'Stuff and Things',
- );
-
- wp_insert_post( $data );
-
- $updated_post = get_post( $post_id );
- // Ensure changing the post_title didn't modify the post_name.
- $this->assertSame( 'stuff', $updated_post->post_name );
- }
-
- /**
- * @ticket 32585
- */
- public function test_wp_insert_post_author_zero() {
- $post_id = self::factory()->post->create( array( 'post_author' => 0 ) );
-
- $this->assertEquals( 0, get_post( $post_id )->post_author );
- }
-
- /**
- * @ticket 32585
- */
- public function test_wp_insert_post_author_null() {
- $post_id = self::factory()->post->create( array( 'post_author' => null ) );
-
- $this->assertEquals( self::$editor_id, get_post( $post_id )->post_author );
- }
-
- /**
- * @ticket 15946
- */
- public function test_wp_insert_post_should_respect_post_date_gmt() {
- $data = array(
- 'post_author' => self::$editor_id,
- 'post_status' => 'publish',
- 'post_content' => 'content',
- 'post_title' => 'title',
- 'post_date_gmt' => '2014-01-01 12:00:00',
- );
-
- // Insert a post and make sure the ID is OK.
- $post_id = wp_insert_post( $data );
-
- $post = get_post( $post_id );
-
- $this->assertSame( $data['post_content'], $post->post_content );
- $this->assertSame( $data['post_title'], $post->post_title );
- $this->assertEquals( $data['post_author'], $post->post_author );
- $this->assertSame( get_date_from_gmt( $data['post_date_gmt'] ), $post->post_date );
- $this->assertSame( $data['post_date_gmt'], $post->post_date_gmt );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_delete_post_reassign_hierarchical_post_type() {
</span><span class="cx" style="display: block; padding: 0 10px"> $grandparent_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $parent_page_id = self::factory()->post->create(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1220,57 +443,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Test ensuring that the post_name (UUID) is preserved when wp_insert_post()/wp_update_post() is called.
- *
- * @see _wp_customize_changeset_filter_insert_post_data()
- * @ticket 30937
- */
- public function test_wp_insert_post_for_customize_changeset_should_not_drop_post_name() {
- $this->assertSame( 10, has_filter( 'wp_insert_post_data', '_wp_customize_changeset_filter_insert_post_data' ) );
-
- $changeset_data = array(
- 'blogname' => array(
- 'value' => 'Hello World',
- ),
- );
-
- wp_set_current_user( $this->factory()->user->create( array( 'role' => 'contributor' ) ) );
-
- $uuid = wp_generate_uuid4();
- $post_id = wp_insert_post(
- array(
- 'post_type' => 'customize_changeset',
- 'post_name' => strtoupper( $uuid ),
- 'post_content' => wp_json_encode( $changeset_data ),
- )
- );
- $this->assertSame( $uuid, get_post( $post_id )->post_name, 'Expected lower-case UUID4 to be inserted.' );
- $this->assertSame( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
-
- $changeset_data['blogname']['value'] = 'Hola Mundo';
- wp_update_post(
- array(
- 'ID' => $post_id,
- 'post_status' => 'draft',
- 'post_content' => wp_json_encode( $changeset_data ),
- )
- );
- $this->assertSame( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for drafts.' );
- $this->assertSame( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
-
- $changeset_data['blogname']['value'] = 'Hallo Welt';
- wp_update_post(
- array(
- 'ID' => $post_id,
- 'post_status' => 'pending',
- 'post_content' => wp_json_encode( $changeset_data ),
- )
- );
- $this->assertSame( $uuid, get_post( $post_id )->post_name, 'Expected post_name to not have been dropped for pending.' );
- $this->assertSame( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) );
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * Test ensuring that the post_slug can be filtered with a custom value short circuiting the built in
</span><span class="cx" style="display: block; padding: 0 10px"> * function that tries to create a unique name based on the post name.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1298,326 +470,8 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @ticket 48113
- */
- public function test_insert_post_should_respect_date_floating_post_status_arg() {
- register_post_status( 'floating', array( 'date_floating' => true ) );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_status' => 'floating',
- 'post_date' => null,
- 'post_date_gmt' => null,
- )
- );
-
- $post = get_post( $post_id );
- self::assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
- }
-
- /**
- * @ticket 48113
- */
- public function test_insert_post_should_respect_date_floating_post_status_arg_not_set() {
- register_post_status( 'not-floating', array( 'date_floating' => false ) );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_status' => 'floating',
- 'post_date' => null,
- 'post_date_gmt' => null,
- )
- );
-
- $post = get_post( $post_id );
- self::assertEqualsWithDelta(
- strtotime( gmdate( 'Y-m-d H:i:s' ) ),
- strtotime( $post->post_date_gmt ),
- 2,
- 'The dates should be equal'
- );
- }
-
- /**
- * Test ensuring that wp_update_post() does not unintentionally modify post tags
- * if the post has several tags with the same name but different slugs.
- *
- * Tags should only be modified if 'tags_input' parameter was explicitly provided,
- * and is different from the existing tags.
- *
- * @ticket 45121
- */
- public function test_update_post_should_only_modify_post_tags_if_different_tags_input_was_provided() {
- $tag_1 = wp_insert_term( 'wp_update_post_tag', 'post_tag', array( 'slug' => 'wp_update_post_tag_1' ) );
- $tag_2 = wp_insert_term( 'wp_update_post_tag', 'post_tag', array( 'slug' => 'wp_update_post_tag_2' ) );
- $tag_3 = wp_insert_term( 'wp_update_post_tag', 'post_tag', array( 'slug' => 'wp_update_post_tag_3' ) );
-
- $post_id = self::factory()->post->create(
- array(
- 'tags_input' => array( $tag_1['term_id'], $tag_2['term_id'] ),
- )
- );
-
- $post = get_post( $post_id );
-
- $tags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
- $this->assertSameSets( array( $tag_1['term_id'], $tag_2['term_id'] ), $tags );
-
- wp_update_post( $post );
-
- $tags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
- $this->assertSameSets( array( $tag_1['term_id'], $tag_2['term_id'] ), $tags );
-
- wp_update_post(
- array(
- 'ID' => $post->ID,
- 'tags_input' => array( $tag_2['term_id'], $tag_3['term_id'] ),
- )
- );
-
- $tags = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
- $this->assertSameSets( array( $tag_2['term_id'], $tag_3['term_id'] ), $tags );
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * @ticket 52187
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_insert_empty_post_date() {
- $post_date_gmt = '2020-12-29 10:11:45';
- $invalid_date = '2020-12-41 14:15:27';
-
- // Empty post_date_gmt with floating status
- $post_id = self::factory()->post->create(
- array(
- 'post_status' => 'draft',
- )
- );
- $post = get_post( $post_id );
- $this->assertEqualsWithDelta(
- strtotime( gmdate( 'Y-m-d H:i:s' ) ),
- strtotime( $post->post_date ),
- 2,
- 'The dates should be equal'
- );
- $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_date_gmt' => '0000-00-00 00:00:00',
- 'post_status' => 'draft',
- )
- );
- $post = get_post( $post_id );
- $this->assertEqualsWithDelta(
- strtotime( gmdate( 'Y-m-d H:i:s' ) ),
- strtotime( $post->post_date ),
- 2,
- 'The dates should be equal'
- );
- $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
-
- // Empty post_date_gmt without floating status
- $post_id = self::factory()->post->create(
- array(
- 'post_status' => 'publish',
- )
- );
- $post = get_post( $post_id );
- $this->assertEqualsWithDelta(
- strtotime( gmdate( 'Y-m-d H:i:s' ) ),
- strtotime( $post->post_date ),
- 2,
- 'The dates should be equal'
- );
- $this->assertEqualsWithDelta(
- strtotime( gmdate( 'Y-m-d H:i:s' ) ),
- strtotime( get_gmt_from_date( $post->post_date ) ),
- 2,
- 'The dates should be equal'
- );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_date_gmt' => '0000-00-00 00:00:00',
- 'post_status' => 'publish',
- )
- );
- $post = get_post( $post_id );
- $this->assertEqualsWithDelta(
- strtotime( gmdate( 'Y-m-d H:i:s' ) ),
- strtotime( $post->post_date ),
- 2,
- 'The dates should be equal'
- );
- $this->assertEqualsWithDelta(
- strtotime( gmdate( 'Y-m-d H:i:s' ) ),
- strtotime( get_gmt_from_date( $post->post_date ) ),
- 2,
- 'The dates should be equal'
- );
-
- // Valid post_date_gmt
- $post_id = self::factory()->post->create(
- array(
- 'post_date_gmt' => $post_date_gmt,
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( get_date_from_gmt( $post_date_gmt ), $post->post_date );
- $this->assertSame( $post_date_gmt, $post->post_date_gmt );
-
- // Invalid post_date_gmt
- $post_id = self::factory()->post->create(
- array(
- 'post_date_gmt' => $invalid_date,
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( '1970-01-01 00:00:00', $post->post_date );
- $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
- }
-
- /**
- * @ticket 52187
- */
- public function test_insert_valid_post_date() {
- $post_date = '2020-12-28 11:26:35';
- $post_date_gmt = '2020-12-29 10:11:45';
- $invalid_date = '2020-12-41 14:15:27';
-
- // Empty post_date_gmt with floating status
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $post_date,
- 'post_status' => 'draft',
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( $post_date, $post->post_date );
- $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $post_date,
- 'post_date_gmt' => '0000-00-00 00:00:00',
- 'post_status' => 'draft',
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( $post_date, $post->post_date );
- $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
-
- // Empty post_date_gmt without floating status
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $post_date,
- 'post_status' => 'publish',
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( $post_date, $post->post_date );
- $this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $post_date,
- 'post_date_gmt' => '0000-00-00 00:00:00',
- 'post_status' => 'publish',
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( $post_date, $post->post_date );
- $this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
-
- // Valid post_date_gmt
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $post_date,
- 'post_date_gmt' => $post_date_gmt,
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( $post_date, $post->post_date );
- $this->assertSame( $post_date_gmt, $post->post_date_gmt );
-
- // Invalid post_date_gmt
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $post_date,
- 'post_date_gmt' => $invalid_date,
- )
- );
- $post = get_post( $post_id );
- $this->assertSame( $post_date, $post->post_date );
- $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
- }
-
- /**
- * @ticket 52187
- */
- public function test_insert_invalid_post_date() {
- $post_date = '2020-12-28 11:26:35';
- $post_date_gmt = '2020-12-29 10:11:45';
- $invalid_date = '2020-12-41 14:15:27';
-
- // Empty post_date_gmt with floating status
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $invalid_date,
- 'post_status' => 'draft',
- )
- );
- $this->assertSame( 0, $post_id );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $invalid_date,
- 'post_date_gmt' => '0000-00-00 00:00:00',
- 'post_status' => 'draft',
- )
- );
- $this->assertSame( 0, $post_id );
-
- // Empty post_date_gmt without floating status
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $invalid_date,
- 'post_status' => 'publish',
- )
- );
- $this->assertSame( 0, $post_id );
-
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $invalid_date,
- 'post_date_gmt' => '0000-00-00 00:00:00',
- 'post_status' => 'publish',
- )
- );
- $this->assertSame( 0, $post_id );
-
- // Valid post_date_gmt
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $invalid_date,
- 'post_date_gmt' => $post_date_gmt,
- )
- );
- $this->assertSame( 0, $post_id );
-
- // Invalid post_date_gmt
- $post_id = self::factory()->post->create(
- array(
- 'post_date' => $invalid_date,
- 'post_date_gmt' => $invalid_date,
- )
- );
- $this->assertSame( 0, $post_id );
- }
-
- /**
- * @ticket 52187
- */
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_wp_resolve_post_date() {
</span><span class="cx" style="display: block; padding: 0 10px"> $post_date = '2020-12-28 11:26:35';
</span><span class="cx" style="display: block; padding: 0 10px"> $post_date_gmt = '2020-12-29 10:11:45';
</span></span></pre>
</div>
</div>
</body>
</html>