mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
REST API: JS client - QUnit tests for custom namespace route discovery.
Add QUnit tests for the parsing of custom namespace routes. Add a custom schema fixture based on the `wp-js-widgets` plugin. Test that the client can parse the widget namespace in the schema and correctly construct the expected group of models and collections. Also includes a small unrelated QUnit fix to ensure nav-menu test passes when it is loaded without its tests executing as well as a small jshint fix, adding a missing semicolon since [40107]. Props jnylen0. Fixes #39561. git-svn-id: https://develop.svn.wordpress.org/trunk@40109 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4414e3c20a
commit
ddc4850a04
@ -1928,7 +1928,7 @@ themes.RunInstaller = {
|
|||||||
// Open the theme preview.
|
// Open the theme preview.
|
||||||
self.view.collection.once( 'query:success', function() {
|
self.view.collection.once( 'query:success', function() {
|
||||||
$( 'div[data-slug="' + slug + '"]' ).trigger( 'click' );
|
$( 'div[data-slug="' + slug + '"]' ).trigger( 'click' );
|
||||||
})
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
562
tests/qunit/fixtures/js-widgets-endpoint.js
Normal file
562
tests/qunit/fixtures/js-widgets-endpoint.js
Normal file
@ -0,0 +1,562 @@
|
|||||||
|
/* jshint -W109 */
|
||||||
|
/* jshint unused:false */
|
||||||
|
var jsWidgetsEndpointSchema =
|
||||||
|
{
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"routes": {
|
||||||
|
"\/js-widgets\/v1": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"namespace": { "required": false, "default": "js-widgets\/v1" },
|
||||||
|
"context": { "required": false, "default": "view" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/pages": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"sortby": { "required": false, "default": "menu_order", "enum": ["post_title", "menu_order", "ID"], "description": "How to sort the pages.", "type": "string" },
|
||||||
|
"exclude": { "required": false, "default": [], "description": "Page IDs to exclude.", "type": ["array", "string"] }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/pages" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/pages\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"sortby": { "required": false, "default": "menu_order", "enum": ["post_title", "menu_order", "ID"], "description": "How to sort the pages.", "type": "string" },
|
||||||
|
"exclude": { "required": false, "default": [], "description": "Page IDs to exclude.", "type": ["array", "string"] }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"sortby": { "required": false, "enum": ["post_title", "menu_order", "ID"], "description": "How to sort the pages.", "type": "string" },
|
||||||
|
"exclude": { "required": false, "description": "Page IDs to exclude.", "type": ["array", "string"] }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/calendar": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/calendar" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/calendar\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/archives": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
|
||||||
|
"count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/archives" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/archives\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
|
||||||
|
"count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"dropdown": { "required": false, "description": "Display as dropdown", "type": "boolean" },
|
||||||
|
"count": { "required": false, "description": "Show post counts", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/meta": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/meta" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/meta\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/search": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/search" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/search\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/text": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"text": { "required": false, "description": "The content for the widget.", "type": ["string", "object"] },
|
||||||
|
"filter": { "required": false, "default": false, "description": "Whether paragraphs will be added for double line breaks (wpautop).", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/text" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/text\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"text": { "required": false, "description": "The content for the widget.", "type": ["string", "object"] },
|
||||||
|
"filter": { "required": false, "default": false, "description": "Whether paragraphs will be added for double line breaks (wpautop).", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"text": { "required": false, "description": "The content for the widget.", "type": ["string", "object"] },
|
||||||
|
"filter": { "required": false, "description": "Whether paragraphs will be added for double line breaks (wpautop).", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/categories": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
|
||||||
|
"count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" },
|
||||||
|
"hierarchical": { "required": false, "default": false, "description": "Show hierarchy", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/categories" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/categories\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
|
||||||
|
"count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" },
|
||||||
|
"hierarchical": { "required": false, "default": false, "description": "Show hierarchy", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"dropdown": { "required": false, "description": "Display as dropdown", "type": "boolean" },
|
||||||
|
"count": { "required": false, "description": "Show post counts", "type": "boolean" },
|
||||||
|
"hierarchical": { "required": false, "description": "Show hierarchy", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/recent-posts": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"number": { "required": false, "default": 5, "description": "The number of posts to display.", "type": "integer" },
|
||||||
|
"show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/recent-posts" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/recent-posts\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"number": { "required": false, "default": 5, "description": "The number of posts to display.", "type": "integer" },
|
||||||
|
"show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"number": { "required": false, "description": "The number of posts to display.", "type": "integer" },
|
||||||
|
"show_date": { "required": false, "description": "Whether the date should be shown.", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/recent-comments": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"number": { "required": false, "default": 5, "description": "The number of comments to display.", "type": "integer" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/recent-comments" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/recent-comments\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"number": { "required": false, "default": 5, "description": "The number of comments to display.", "type": "integer" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"number": { "required": false, "description": "The number of comments to display.", "type": "integer" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/rss": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"url": { "required": false, "default": "", "description": "The RSS feed URL.", "type": "string" },
|
||||||
|
"items": { "required": false, "default": 10, "description": "The number of RSS items to display.", "type": "integer" },
|
||||||
|
"show_summary": { "required": false, "default": false, "description": "Whether the summary should be shown.", "type": "boolean" },
|
||||||
|
"show_author": { "required": false, "default": false, "description": "Whether the author should be shown.", "type": "boolean" },
|
||||||
|
"show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/rss" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/rss\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"url": { "required": false, "default": "", "description": "The RSS feed URL.", "type": "string" },
|
||||||
|
"items": { "required": false, "default": 10, "description": "The number of RSS items to display.", "type": "integer" },
|
||||||
|
"show_summary": { "required": false, "default": false, "description": "Whether the summary should be shown.", "type": "boolean" },
|
||||||
|
"show_author": { "required": false, "default": false, "description": "Whether the author should be shown.", "type": "boolean" },
|
||||||
|
"show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"url": { "required": false, "description": "The RSS feed URL.", "type": "string" },
|
||||||
|
"items": { "required": false, "description": "The number of RSS items to display.", "type": "integer" },
|
||||||
|
"show_summary": { "required": false, "description": "Whether the summary should be shown.", "type": "boolean" },
|
||||||
|
"show_author": { "required": false, "description": "Whether the author should be shown.", "type": "boolean" },
|
||||||
|
"show_date": { "required": false, "description": "Whether the date should be shown.", "type": "boolean" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/tag_cloud": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"taxonomy": { "required": false, "default": "post_tag", "enum": ["category", "post_tag"], "description": "Taxonomy", "type": "string" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/tag_cloud" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/tag_cloud\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"taxonomy": { "required": false, "default": "post_tag", "enum": ["category", "post_tag"], "description": "Taxonomy", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"taxonomy": { "required": false, "enum": ["category", "post_tag"], "description": "Taxonomy", "type": "string" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/nav_menu": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"nav_menu": { "required": false, "default": 0, "description": "Selected nav menu", "type": "integer" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/nav_menu" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/nav_menu\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"nav_menu": { "required": false, "default": 0, "description": "Selected nav menu", "type": "integer" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"nav_menu": { "required": false, "description": "Selected nav menu", "type": "integer" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/post-collection": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" },
|
||||||
|
"show_featured_image": { "required": false, "default": false, "description": "Whether the featured image is shown.", "type": "boolean" },
|
||||||
|
"show_author": { "required": false, "default": false, "description": "Whether the author is shown.", "type": "boolean" },
|
||||||
|
"posts": { "required": false, "default": [], "description": "The IDs for the collected posts.", "type": "array" }
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/post-collection" }
|
||||||
|
},
|
||||||
|
"\/js-widgets\/v1\/widgets\/post-collection\/(?P<widget_number>\\d+)": {
|
||||||
|
"namespace": "js-widgets\/v1",
|
||||||
|
"methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
||||||
|
"endpoints": [{
|
||||||
|
"methods": ["GET"],
|
||||||
|
"args": {
|
||||||
|
"context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["POST", "PUT", "PATCH"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" },
|
||||||
|
"show_featured_image": { "required": false, "default": false, "description": "Whether the featured image is shown.", "type": "boolean" },
|
||||||
|
"show_author": { "required": false, "default": false, "description": "Whether the author is shown.", "type": "boolean" },
|
||||||
|
"posts": { "required": false, "default": [], "description": "The IDs for the collected posts.", "type": "array" }
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"methods": ["DELETE"],
|
||||||
|
"args": {
|
||||||
|
"title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
|
||||||
|
"show_date": { "required": false, "description": "Whether the date should be shown.", "type": "boolean" },
|
||||||
|
"show_featured_image": { "required": false, "description": "Whether the featured image is shown.", "type": "boolean" },
|
||||||
|
"show_author": { "required": false, "description": "Whether the author is shown.", "type": "boolean" },
|
||||||
|
"posts": { "required": false, "description": "The IDs for the collected posts.", "type": "array" }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"_links": {
|
||||||
|
"up": [
|
||||||
|
{ "href": "http:\/\/newtest.localhost\/wp-json\/" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
@ -1,4 +1,4 @@
|
|||||||
/* global mockedApiResponse, Backbone */
|
/* global mockedApiResponse, Backbone, jsWidgetsEndpointSchema */
|
||||||
/**
|
/**
|
||||||
* @var mockedApiResponse defined in wp-api-generated.js
|
* @var mockedApiResponse defined in wp-api-generated.js
|
||||||
*/
|
*/
|
||||||
@ -23,7 +23,8 @@ var pathToData = {
|
|||||||
'wp-json/wp/v2/user': mockedApiResponse.UserModel,
|
'wp-json/wp/v2/user': mockedApiResponse.UserModel,
|
||||||
'wp-json/wp/v2/taxonomy': mockedApiResponse.TaxonomyModel,
|
'wp-json/wp/v2/taxonomy': mockedApiResponse.TaxonomyModel,
|
||||||
'wp-json/wp/v2/status': mockedApiResponse.StatusModel,
|
'wp-json/wp/v2/status': mockedApiResponse.StatusModel,
|
||||||
'wp-json/wp/v2/type': mockedApiResponse.TypeModel
|
'wp-json/wp/v2/type': mockedApiResponse.TypeModel,
|
||||||
|
'wp-json/js-widgets/v1/': jsWidgetsEndpointSchema
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
<script src="fixtures/customize-menus.js"></script>
|
<script src="fixtures/customize-menus.js"></script>
|
||||||
<script src="fixtures/customize-widgets.js"></script>
|
<script src="fixtures/customize-widgets.js"></script>
|
||||||
<script src="fixtures/wp-api-generated.js"></script>
|
<script src="fixtures/wp-api-generated.js"></script>
|
||||||
|
<script src="fixtures/js-widgets-endpoint.js"></script>
|
||||||
<script src="fixtures/wp-api.js"></script>
|
<script src="fixtures/wp-api.js"></script>
|
||||||
</div>
|
</div>
|
||||||
<p><a href="editor">TinyMCE tests</a></p>
|
<p><a href="editor">TinyMCE tests</a></p>
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
// Fail if we don't see the expected number of events triggered in 1500 ms.
|
// Fail if we don't see the expected number of events triggered in 1500 ms.
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
assert.equal(
|
// QUnit may load this file without running it, in which case `assert`
|
||||||
|
// will never be set to `assertPassed` below.
|
||||||
|
assert && assert.equal(
|
||||||
eventsFired,
|
eventsFired,
|
||||||
eventsExpected,
|
eventsExpected,
|
||||||
eventsExpected + ' wpNavMenu events should fire.'
|
eventsExpected + ' wpNavMenu events should fire.'
|
||||||
|
@ -192,4 +192,44 @@
|
|||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// Test the jswidget custom namespace and endpoints.
|
||||||
|
wp.api.init( {
|
||||||
|
'versionString': 'js-widgets/v1/'
|
||||||
|
} ).done( function() {
|
||||||
|
var customClasses = [
|
||||||
|
'WidgetsArchives',
|
||||||
|
'WidgetsCalendar',
|
||||||
|
'WidgetsCategories',
|
||||||
|
'WidgetsMeta',
|
||||||
|
'WidgetsNav_menu',
|
||||||
|
'WidgetsPages',
|
||||||
|
'WidgetsPostCollection',
|
||||||
|
'WidgetsRecentComments',
|
||||||
|
'WidgetsRecentPosts',
|
||||||
|
'WidgetsRss',
|
||||||
|
'WidgetsSearch',
|
||||||
|
'WidgetsTag_cloud',
|
||||||
|
'WidgetsText'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Check that we have and can get each model type.
|
||||||
|
_.each( customClasses, function( className ) {
|
||||||
|
QUnit.test( 'Checking ' + className + ' class name.' , function( assert ) {
|
||||||
|
var done = assert.async();
|
||||||
|
|
||||||
|
assert.expect( 2 );
|
||||||
|
|
||||||
|
wp.api.loadPromise.done( function() {
|
||||||
|
var theModel = new wp.api.models[ className ]();
|
||||||
|
assert.ok( theModel, 'We can instantiate wp.api.models.' + className );
|
||||||
|
var theCollection = new wp.api.collections[ className ]();
|
||||||
|
assert.ok( theCollection, 'We can instantiate wp.api.collections.' + className );
|
||||||
|
// Trigger Qunit async completion.
|
||||||
|
done();
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
} )( window.QUnit );
|
} )( window.QUnit );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user