<!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>[41678] trunk: WP-API JS Client: Improve support for meta.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41678">41678</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/41678","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>adamsilverstein</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-10-02 18:39:30 +0000 (Mon, 02 Oct 2017)</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'>WP-API JS Client: Improve support for meta.

* Add/fix `getMeta`, `getMetas`, `setMeta` and `setMetas` helpers for models that support meta.
* Add tests for new helpers, verify meta support for `Posts`, `Comments`, `Tags` and `Users`.
* Include meta data in fixture generation and fixture file driving tests.

Fixes <a href="https://core.trac.wordpress.org/ticket/41055">#41055</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjswpapijs">trunk/src/wp-includes/js/wp-api.js</a></li>
<li><a href="#trunktestsphpunittestsrestapirestschemasetupphp">trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php</a></li>
<li><a href="#trunktestsqunitfixtureswpapigeneratedjs">trunk/tests/qunit/fixtures/wp-api-generated.js</a></li>
<li><a href="#trunktestsqunitwpincludesjswpapijs">trunk/tests/qunit/wp-includes/js/wp-api.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjswpapijs"></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/js/wp-api.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/wp-api.js        2017-10-02 18:39:10 UTC (rev 41677)
+++ trunk/src/wp-includes/js/wp-api.js  2017-10-02 18:39:30 UTC (rev 41678)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -501,8 +501,49 @@
</span><span class="cx" style="display: block; padding: 0 10px">                         * Add a helper function to handle post Meta.
</span><span class="cx" style="display: block; padding: 0 10px">                         */
</span><span class="cx" style="display: block; padding: 0 10px">                        MetaMixin = {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                getMeta: function() {
-                                       return buildCollectionGetter( this, 'PostMeta', 'https://api.w.org/meta' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               /**
+                                * Get meta by key for a post.
+                                *
+                                * @param {string} key The meta key.
+                                *
+                                * @return {object} The post meta value.
+                                */
+                               getMeta: function( key ) {
+                                       var metas = this.get( 'meta' );
+                                       return metas[ key ];
+                               },
+
+                               /**
+                                * Get all meta key/values for a post.
+                                *
+                                * @return {object} The post metas, as a key value pair object.
+                                */
+                               getMetas: function() {
+                                       return this.get( 'meta' );
+                               },
+
+                               /**
+                                * Set a group of meta key/values for a post.
+                                *
+                                * @param {object} meta The post meta to set, as key/value pairs.
+                                */
+                               setMetas: function( meta ) {
+                                       var metas = this.get( 'meta' );
+                                       _.extend( metas, meta );
+                                       this.set( 'meta', metas );
+                               },
+
+                               /**
+                                * Set a single meta value for a post, by key.
+                                *
+                                * @param {string} key   The meta key.
+                                * @param {object} value The meta value.
+                                */
+                               setMeta: function( key, value ) {
+                                       var metas = this.get( 'meta' );
+                                       metas[ key ] = value;
+                                       this.set( 'meta', metas );
</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">@@ -734,8 +775,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        model = model.extend( CategoriesMixin );
</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">-                // Add the MetaMixin for models that support meta collections.
-               if ( ! _.isUndefined( loadingObjects.collections[ modelClassName + 'Meta' ] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Add the MetaMixin for models that support meta.
+               if ( ! _.isUndefined( model.prototype.args.meta ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         model = model.extend( MetaMixin );
</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="trunktestsphpunittestsrestapirestschemasetupphp"></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-schema-setup.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php  2017-10-02 18:39:10 UTC (rev 41677)
+++ trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php    2017-10-02 18:39:30 UTC (rev 41678)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -145,6 +145,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_excerpt'   => 'REST API Client Fixture: Post',
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_author'    => 0,
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 wp_update_post( array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'ID'           => $post_id,
</span><span class="cx" style="display: block; padding: 0 10px">                        'post_content' => 'Updated post content.',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -195,7 +196,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'comment_author_email' => 'lights@example.org',
</span><span class="cx" style="display: block; padding: 0 10px">                        'comment_author_url'   => 'http://lights.example.org/',
</span><span class="cx" style="display: block; padding: 0 10px">                ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $meta_args = array(
+                       'sanitize_callback' => 'sanitize_my_meta_key',
+                       'auth_callback'     => '__return_true',
+                       'type'              => 'string',
+                       'description'       => 'Test meta key',
+                       'single'            => true,
+                       'show_in_rest'      => true,
+               );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Set up meta.
+               register_meta( 'user', 'meta_key', $meta_args );
+               update_user_meta( 1, 'meta_key', 'meta_value' ); // Always use the first user.
+               register_meta( 'post', 'meta_key', $meta_args );
+               update_post_meta( $post_id, 'meta_key', 'meta_value' );
+               register_meta( 'comment', 'meta_key', $meta_args );
+               update_comment_meta( $comment_id, 'meta_key', 'meta_value' );
+               register_meta( 'term', 'meta_key', $meta_args );
+               update_term_meta( $tag_id, 'meta_key', 'meta_value' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Generate route data for subsequent QUnit tests.
</span><span class="cx" style="display: block; padding: 0 10px">                $routes_to_generate_data = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</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    2017-10-02 18:39:10 UTC (rev 41677)
+++ trunk/tests/qunit/fixtures/wp-api-generated.js      2017-10-02 18:39:30 UTC (rev 41678)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3560,7 +3560,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "sticky": false,
</span><span class="cx" style="display: block; padding: 0 10px">         "template": "",
</span><span class="cx" style="display: block; padding: 0 10px">         "format": "standard",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": "meta_value"
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "categories": [
</span><span class="cx" style="display: block; padding: 0 10px">             1
</span><span class="cx" style="display: block; padding: 0 10px">         ],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3651,7 +3653,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">     "sticky": false,
</span><span class="cx" style="display: block; padding: 0 10px">     "template": "",
</span><span class="cx" style="display: block; padding: 0 10px">     "format": "standard",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": "meta_value"
+    },
</ins><span class="cx" style="display: block; padding: 0 10px">     "categories": [
</span><span class="cx" style="display: block; padding: 0 10px">         1
</span><span class="cx" style="display: block; padding: 0 10px">     ],
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3745,7 +3749,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "comment_status": "closed",
</span><span class="cx" style="display: block; padding: 0 10px">         "ping_status": "closed",
</span><span class="cx" style="display: block; padding: 0 10px">         "template": "",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": ""
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "_links": {
</span><span class="cx" style="display: block; padding: 0 10px">             "self": [
</span><span class="cx" style="display: block; padding: 0 10px">                 {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3820,7 +3826,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">     "comment_status": "closed",
</span><span class="cx" style="display: block; padding: 0 10px">     "ping_status": "closed",
</span><span class="cx" style="display: block; padding: 0 10px">     "template": "",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": []
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": ""
+    }
</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.pageRevisions = [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3899,7 +3907,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "comment_status": "open",
</span><span class="cx" style="display: block; padding: 0 10px">         "ping_status": "closed",
</span><span class="cx" style="display: block; padding: 0 10px">         "template": "",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": ""
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "description": {
</span><span class="cx" style="display: block; padding: 0 10px">             "rendered": "<p class=\"attachment\"><!-- <a...><img.../></a> --></p>"
</span><span class="cx" style="display: block; padding: 0 10px">         },
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3958,7 +3968,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">     "comment_status": "open",
</span><span class="cx" style="display: block; padding: 0 10px">     "ping_status": "closed",
</span><span class="cx" style="display: block; padding: 0 10px">     "template": "",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": ""
+    },
</ins><span class="cx" style="display: block; padding: 0 10px">     "description": {
</span><span class="cx" style="display: block; padding: 0 10px">         "rendered": "<p class=\"attachment\"><!-- <a...><img.../></a> --></p>"
</span><span class="cx" style="display: block; padding: 0 10px">     },
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4242,7 +4254,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "slug": "uncategorized",
</span><span class="cx" style="display: block; padding: 0 10px">         "taxonomy": "category",
</span><span class="cx" style="display: block; padding: 0 10px">         "parent": 0,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": ""
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "_links": {
</span><span class="cx" style="display: block; padding: 0 10px">             "self": [
</span><span class="cx" style="display: block; padding: 0 10px">                 {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4284,7 +4298,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">     "slug": "uncategorized",
</span><span class="cx" style="display: block; padding: 0 10px">     "taxonomy": "category",
</span><span class="cx" style="display: block; padding: 0 10px">     "parent": 0,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": []
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": ""
+    }
</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.TagsCollection = [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4296,7 +4312,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "name": "REST API Client Fixture: Tag",
</span><span class="cx" style="display: block; padding: 0 10px">         "slug": "restapi-client-fixture-tag",
</span><span class="cx" style="display: block; padding: 0 10px">         "taxonomy": "post_tag",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": "meta_value"
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "_links": {
</span><span class="cx" style="display: block; padding: 0 10px">             "self": [
</span><span class="cx" style="display: block; padding: 0 10px">                 {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4337,7 +4355,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">     "name": "REST API Client Fixture: Tag",
</span><span class="cx" style="display: block; padding: 0 10px">     "slug": "restapi-client-fixture-tag",
</span><span class="cx" style="display: block; padding: 0 10px">     "taxonomy": "post_tag",
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": []
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": "meta_value"
+    }
</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.UsersCollection = [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4353,7 +4373,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">             "48": "http://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=48&d=mm&r=g",
</span><span class="cx" style="display: block; padding: 0 10px">             "96": "http://0.gravatar.com/avatar/96614ec98aa0c0d2ee75796dced6df54?s=96&d=mm&r=g"
</span><span class="cx" style="display: block; padding: 0 10px">         },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": "meta_value"
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "_links": {
</span><span class="cx" style="display: block; padding: 0 10px">             "self": [
</span><span class="cx" style="display: block; padding: 0 10px">                 {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4379,7 +4401,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">             "48": "http://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g",
</span><span class="cx" style="display: block; padding: 0 10px">             "96": "http://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g"
</span><span class="cx" style="display: block; padding: 0 10px">         },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": ""
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "_links": {
</span><span class="cx" style="display: block; padding: 0 10px">             "self": [
</span><span class="cx" style="display: block; padding: 0 10px">                 {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4407,7 +4431,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "48": "http://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g",
</span><span class="cx" style="display: block; padding: 0 10px">         "96": "http://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g"
</span><span class="cx" style="display: block; padding: 0 10px">     },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": []
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": ""
+    }
</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.me = {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4422,7 +4448,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "48": "http://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=48&d=mm&r=g",
</span><span class="cx" style="display: block; padding: 0 10px">         "96": "http://2.gravatar.com/avatar/57cbd982c963c7eb2294e2eee1b4448e?s=96&d=mm&r=g"
</span><span class="cx" style="display: block; padding: 0 10px">     },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": []
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": ""
+    }
</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.CommentsCollection = [
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4446,7 +4474,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">             "48": "http://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=48&d=mm&r=g",
</span><span class="cx" style="display: block; padding: 0 10px">             "96": "http://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=96&d=mm&r=g"
</span><span class="cx" style="display: block; padding: 0 10px">         },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        "meta": [],
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        "meta": {
+            "meta_key": "meta_value"
+        },
</ins><span class="cx" style="display: block; padding: 0 10px">         "_links": {
</span><span class="cx" style="display: block; padding: 0 10px">             "self": [
</span><span class="cx" style="display: block; padding: 0 10px">                 {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4489,7 +4519,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">         "48": "http://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=48&d=mm&r=g",
</span><span class="cx" style="display: block; padding: 0 10px">         "96": "http://2.gravatar.com/avatar/bd7c2b505bcf39cc71cfee564c614956?s=96&d=mm&r=g"
</span><span class="cx" style="display: block; padding: 0 10px">     },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-    "meta": []
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+    "meta": {
+        "meta_key": "meta_value"
+    }
</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.settings = {
</span></span></pre></div>
<a id="trunktestsqunitwpincludesjswpapijs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/wp-includes/js/wp-api.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/wp-includes/js/wp-api.js        2017-10-02 18:39:10 UTC (rev 41677)
+++ trunk/tests/qunit/wp-includes/js/wp-api.js  2017-10-02 18:39:30 UTC (rev 41678)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,4 +1,4 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/* global wp */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* global wp, JSON */
</ins><span class="cx" style="display: block; padding: 0 10px"> ( function( QUnit ) {
</span><span class="cx" style="display: block; padding: 0 10px">        module( 'wpapi' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -381,4 +381,44 @@
</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">+
+       var theModelTypesWithMeta = [
+               'Posts',
+               'Comments',
+               'Tags',
+               'Users'
+       ];
+
+       _.each( theModelTypesWithMeta, function( modelType ) {
+
+               // Test post meta.
+               wp.api.loadPromise.done( function() {
+                       QUnit.test( 'Check meta support for ' + modelType + '.', function( assert ) {
+                               var theModels = new wp.api.collections[ modelType ]();
+
+                               theModels.fetch().done( function() {
+
+                                       // Get the main endpoint.
+                                       var endpoint = theModels.at(0);
+
+                                       // Verify the meta object returned correctly from `getMetas()`.
+                                       assert.equal( JSON.stringify( endpoint.getMetas() ), '{"meta_key":"meta_value"}', 'Full meta key/values object should be readable.' );
+
+                                       // Verify single meta returned correctly from `getMeta()`
+                                       assert.equal( endpoint.getMeta( 'meta_key' ), 'meta_value', 'Single meta should be readable by key.' );
+
+                                       // Verify setting meta values with `setMetas()`.
+                                       endpoint.setMetas( { 'test_key':'test_value' } );
+                                       assert.equal( endpoint.getMeta( 'test_key' ), 'test_value', 'Multiple meta should be writable via setMetas.' );
+
+                                       // Verify setting a single meta value with `setMeta()`.
+                                       endpoint.setMeta( 'test_key2', 'test_value2' );
+                                       assert.equal( endpoint.getMeta( 'test_key2' ), 'test_value2', 'Single meta should be writable via setMeta.' );
+
+                               } );
+                       } );
+               } );
+       } );
+
+
</ins><span class="cx" style="display: block; padding: 0 10px"> } )( window.QUnit );
</span></span></pre>
</div>
</div>

</body>
</html>