<!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>[46252] trunk: REST API: Introduce date_floating property on status endpoint response objects.</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/46252">46252</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/46252","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>kadamwhite</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-09-23 17:39:36 +0000 (Mon, 23 Sep 2019)</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'>REST API: Introduce date_floating property on status endpoint response objects.
Expose a date_floating property on all status objects to permit clients (including the block editor) to make correct decisions about date handling for posts of varying status.
Props mnelson4, earnjam, kadamwhite, jnylen0, nerrad, pento.
See <a href="https://core.trac.wordpress.org/ticket/39953">#39953</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpoststatusescontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpoststatusescontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestpostscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php</a></li>
<li><a href="#trunktestsqunitfixtureswpapigeneratedjs">trunk/tests/qunit/fixtures/wp-api-generated.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php 2019-09-23 17:34:20 UTC (rev 46251)
+++ trunk/src/wp-includes/post.php 2019-09-23 17:39:36 UTC (rev 46252)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -337,14 +337,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> register_post_status(
</span><span class="cx" style="display: block; padding: 0 10px"> 'draft',
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'label' => _x( 'Draft', 'post status' ),
- 'protected' => true,
- '_builtin' => true, /* internal use only. */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'label' => _x( 'Draft', 'post status' ),
+ 'protected' => true,
+ '_builtin' => true, /* internal use only. */
</ins><span class="cx" style="display: block; padding: 0 10px"> /* translators: %s: Number of draft posts. */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'label_count' => _n_noop(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'label_count' => _n_noop(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'Draft <span class="count">(%s)</span>',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Drafts <span class="count">(%s)</span>'
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'date_floating' => 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">@@ -394,9 +395,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> register_post_status(
</span><span class="cx" style="display: block; padding: 0 10px"> 'auto-draft',
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'label' => 'auto-draft',
- 'internal' => true,
- '_builtin' => true, /* internal use only. */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'label' => 'auto-draft',
+ 'internal' => true,
+ '_builtin' => true, /* internal use only. */
+ 'date_floating' => 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">@@ -1018,6 +1020,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * the top of the edit listings,
</span><span class="cx" style="display: block; padding: 0 10px"> * e.g. All (12) | Published (9) | My Custom Status (2)
</span><span class="cx" style="display: block; padding: 0 10px"> * Default is value of $internal.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type bool $date_floating Whether the post has a floating creation date.
+ * Default to false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @return object
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1041,6 +1045,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'publicly_queryable' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_in_admin_status_list' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'show_in_admin_all_list' => null,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'date_floating' => null,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $args = wp_parse_args( $args, $defaults );
</span><span class="cx" style="display: block; padding: 0 10px"> $args = (object) $args;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1085,6 +1090,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $args->show_in_admin_status_list = ! $args->internal;
</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">+ if ( null === $args->date_floating ) {
+ $args->date_floating = false;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( false === $args->label ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $args->label = $post_status;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpoststatusescontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php 2019-09-23 17:34:20 UTC (rev 46251)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php 2019-09-23 17:39:36 UTC (rev 46252)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,6 +234,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $data['slug'] = $status->name;
</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">+ if ( in_array( 'date_floating', $fields, true ) ) {
+ $data['date_floating'] = $status->date_floating;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
</span><span class="cx" style="display: block; padding: 0 10px"> $data = $this->add_additional_fields_to_object( $data, $request );
</span><span class="cx" style="display: block; padding: 0 10px"> $data = $this->filter_response_by_context( $data, $context );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -277,48 +281,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => 'status',
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'object',
</span><span class="cx" style="display: block; padding: 0 10px"> 'properties' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'name' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'name' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'The title for the status.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'embed', 'view', 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</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' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'private' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Whether posts with this status should be private.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'boolean',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</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' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'protected' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Whether posts with this status should be protected.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'boolean',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</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' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'public' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'boolean',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'view', 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'queryable' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'queryable' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Whether posts with this status should be publicly-queryable.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'boolean',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'view', 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'show_in_list' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'show_in_list' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Whether to include posts in the edit listing for their post type.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'boolean',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'slug' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'slug' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'An alphanumeric identifier for the status.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'embed', 'view', 'edit' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'date_floating' => array(
+ 'description' => __( 'Whether posts of this status may have floating published dates.' ),
+ 'type' => 'boolean',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => 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></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestpostscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2019-09-23 17:34:20 UTC (rev 46251)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2019-09-23 17:39:36 UTC (rev 46252)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1021,16 +1021,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Post date.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $schema['properties']['date'] ) && ! empty( $request['date'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $date_data = rest_get_date_with_gmt( $request['date'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date : false;
+ $date_data = rest_get_date_with_gmt( $request['date'] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $date_data ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $date_data ) && $current_date !== $date_data[0] ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
</span><span class="cx" style="display: block; padding: 0 10px"> $prepared_post->edit_date = true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( ! empty( $schema['properties']['date_gmt'] ) && ! empty( $request['date_gmt'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $date_data = rest_get_date_with_gmt( $request['date_gmt'], true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date_gmt : false;
+ $date_data = rest_get_date_with_gmt( $request['date_gmt'], true );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $date_data ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $date_data ) && $current_date !== $date_data[1] ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
</span><span class="cx" style="display: block; padding: 0 10px"> $prepared_post->edit_date = true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpoststatusescontrollerphp"></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/rest-api/rest-post-statuses-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php 2019-09-23 17:34:20 UTC (rev 46251)
+++ trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php 2019-09-23 17:39:36 UTC (rev 46252)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -153,7 +153,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_get_server()->dispatch( $request );
</span><span class="cx" style="display: block; padding: 0 10px"> $data = $response->get_data();
</span><span class="cx" style="display: block; padding: 0 10px"> $properties = $data['schema']['properties'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertEquals( 7, count( $properties ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( 8, count( $properties ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'name', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'private', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'protected', $properties );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -161,6 +161,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'queryable', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'show_in_list', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'slug', $properties );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertArrayhasKey( 'date_floating', $properties );
</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"> public function test_get_additional_field_registration() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -217,6 +218,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> array_keys( $links )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( $status_obj->date_floating, $data['date_floating'] );
</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"> protected function check_post_status_object_response( $response ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestpostscontrollerphp"></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/rest-api/rest-posts-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php 2019-09-23 17:34:20 UTC (rev 46251)
+++ trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php 2019-09-23 17:39:36 UTC (rev 46252)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4413,6 +4413,119 @@
</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">+ public function test_putting_same_publish_date_does_not_remove_floating_date() {
+
+ wp_set_current_user( self::$superadmin_id );
+
+ $time = date( 'Y-m-d H:i:s' );
+
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_status' => 'draft',
+ 'post_date' => $time,
+ )
+ );
+
+ $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+ $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" );
+ $get->set_query_params( array( 'context' => 'edit' ) );
+
+ $get = rest_get_server()->dispatch( $get );
+ $get_body = $get->get_data();
+
+ $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" );
+ $put->set_body_params( $get_body );
+
+ $response = rest_get_server()->dispatch( $put );
+ $body = $response->get_data();
+
+ $this->assertEquals( $get_body['date'], $body['date'] );
+ $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] );
+
+ $this->assertEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
+ }
+
+ public function test_putting_different_publish_date_removes_floating_date() {
+
+ wp_set_current_user( self::$superadmin_id );
+
+ $time = date( 'Y-m-d H:i:s' );
+ $new_time = date( 'Y-m-d H:i:s', strtotime( '+1 week' ) );
+
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_status' => 'draft',
+ 'post_date' => $time,
+ )
+ );
+
+ $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+ $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" );
+ $get->set_query_params( array( 'context' => 'edit' ) );
+
+ $get = rest_get_server()->dispatch( $get );
+ $get_body = $get->get_data();
+
+ $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" );
+ $put->set_body_params(
+ array_merge(
+ $get_body,
+ array(
+ 'date' => mysql_to_rfc3339( $new_time ),
+ )
+ )
+ );
+
+ $response = rest_get_server()->dispatch( $put );
+ $body = $response->get_data();
+
+ $this->assertEquals( mysql_to_rfc3339( $new_time ), $body['date'] );
+
+ $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
+ }
+
+ public function test_publishing_post_with_same_date_removes_floating_date() {
+
+ wp_set_current_user( self::$superadmin_id );
+
+ $time = date( 'Y-m-d H:i:s' );
+
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_status' => 'draft',
+ 'post_date' => $time,
+ )
+ );
+
+ $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
+
+ $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" );
+ $get->set_query_params( array( 'context' => 'edit' ) );
+
+ $get = rest_get_server()->dispatch( $get );
+ $get_body = $get->get_data();
+
+ $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" );
+ $put->set_body_params(
+ array_merge(
+ $get_body,
+ array(
+ 'status' => 'publish',
+ )
+ )
+ );
+
+ $response = rest_get_server()->dispatch( $put );
+ $body = $response->get_data();
+
+ $this->assertEquals( $get_body['date'], $body['date'] );
+ $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] );
+
+ $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function tearDown() {
</span><span class="cx" style="display: block; padding: 0 10px"> _unregister_post_type( 'private-post' );
</span><span class="cx" style="display: block; padding: 0 10px"> _unregister_post_type( 'youseeme' );
</span></span></pre></div>
<a id="trunktestsqunitfixtureswpapigeneratedjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/fixtures/wp-api-generated.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/fixtures/wp-api-generated.js 2019-09-23 17:34:20 UTC (rev 46251)
+++ trunk/tests/qunit/fixtures/wp-api-generated.js 2019-09-23 17:39:36 UTC (rev 46252)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7392,6 +7392,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "public": true,
</span><span class="cx" style="display: block; padding: 0 10px"> "queryable": true,
</span><span class="cx" style="display: block; padding: 0 10px"> "slug": "publish",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "date_floating": false,
</ins><span class="cx" style="display: block; padding: 0 10px"> "_links": {
</span><span class="cx" style="display: block; padding: 0 10px"> "archives": [
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7405,6 +7406,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "public": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "queryable": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "slug": "future",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "date_floating": false,
</ins><span class="cx" style="display: block; padding: 0 10px"> "_links": {
</span><span class="cx" style="display: block; padding: 0 10px"> "archives": [
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7418,6 +7420,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "public": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "queryable": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "slug": "draft",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "date_floating": true,
</ins><span class="cx" style="display: block; padding: 0 10px"> "_links": {
</span><span class="cx" style="display: block; padding: 0 10px"> "archives": [
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7431,6 +7434,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "public": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "queryable": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "slug": "pending",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "date_floating": false,
</ins><span class="cx" style="display: block; padding: 0 10px"> "_links": {
</span><span class="cx" style="display: block; padding: 0 10px"> "archives": [
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7444,6 +7448,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "public": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "queryable": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "slug": "private",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "date_floating": false,
</ins><span class="cx" style="display: block; padding: 0 10px"> "_links": {
</span><span class="cx" style="display: block; padding: 0 10px"> "archives": [
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7457,6 +7462,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "public": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "queryable": false,
</span><span class="cx" style="display: block; padding: 0 10px"> "slug": "trash",
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "date_floating": false,
</ins><span class="cx" style="display: block; padding: 0 10px"> "_links": {
</span><span class="cx" style="display: block; padding: 0 10px"> "archives": [
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7471,7 +7477,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "name": "Published",
</span><span class="cx" style="display: block; padding: 0 10px"> "public": true,
</span><span class="cx" style="display: block; padding: 0 10px"> "queryable": true,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "slug": "publish"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "slug": "publish",
+ "date_floating": false
</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"> mockedApiResponse.TaxonomiesCollection = {
</span></span></pre>
</div>
</div>
</body>
</html>