WordPress.org

Make WordPress Core

Ticket #39561: 39561.5.diff

File 39561.5.diff, 36.4 KB (added by jnylen0, 15 months ago)

Just the new tests (and the QUnit fix)

  • new file tests/qunit/fixtures/js-widgets-endpoint.js

    diff --git a/tests/qunit/fixtures/js-widgets-endpoint.js b/tests/qunit/fixtures/js-widgets-endpoint.js
    new file mode 100644
    index 0000000..56fb603
    - +  
     1var jsWidgetsEndpointSchema =
     2{
     3    "namespace": "js-widgets\/v1",
     4    "routes": {
     5        "\/js-widgets\/v1": {
     6            "namespace": "js-widgets\/v1",
     7            "methods": ["GET"],
     8            "endpoints": [{
     9                "methods": ["GET"],
     10                "args": {
     11                    "namespace": { "required": false, "default": "js-widgets\/v1" },
     12                    "context": { "required": false, "default": "view" }
     13                }
     14            }],
     15            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1" }
     16        },
     17        "\/js-widgets\/v1\/widgets\/pages": {
     18            "namespace": "js-widgets\/v1",
     19            "methods": ["GET", "POST"],
     20            "endpoints": [{
     21                "methods": ["GET"],
     22                "args": {
     23                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     24                }
     25            }, {
     26                "methods": ["POST"],
     27                "args": {
     28                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     29                    "sortby": { "required": false, "default": "menu_order", "enum": ["post_title", "menu_order", "ID"], "description": "How to sort the pages.", "type": "string" },
     30                    "exclude": { "required": false, "default": [], "description": "Page IDs to exclude.", "type": ["array", "string"] }
     31                }
     32            }],
     33            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/pages" }
     34        },
     35        "\/js-widgets\/v1\/widgets\/pages\/(?P<widget_number>\\d+)": {
     36            "namespace": "js-widgets\/v1",
     37            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     38            "endpoints": [{
     39                "methods": ["GET"],
     40                "args": {
     41                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     42                }
     43            }, {
     44                "methods": ["POST", "PUT", "PATCH"],
     45                "args": {
     46                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     47                    "sortby": { "required": false, "default": "menu_order", "enum": ["post_title", "menu_order", "ID"], "description": "How to sort the pages.", "type": "string" },
     48                    "exclude": { "required": false, "default": [], "description": "Page IDs to exclude.", "type": ["array", "string"] }
     49                }
     50            }, {
     51                "methods": ["DELETE"],
     52                "args": {
     53                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     54                    "sortby": { "required": false, "enum": ["post_title", "menu_order", "ID"], "description": "How to sort the pages.", "type": "string" },
     55                    "exclude": { "required": false, "description": "Page IDs to exclude.", "type": ["array", "string"] }
     56                }
     57            }]
     58        },
     59        "\/js-widgets\/v1\/widgets\/calendar": {
     60            "namespace": "js-widgets\/v1",
     61            "methods": ["GET", "POST"],
     62            "endpoints": [{
     63                "methods": ["GET"],
     64                "args": {
     65                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     66                }
     67            }, {
     68                "methods": ["POST"],
     69                "args": {
     70                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     71                }
     72            }],
     73            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/calendar" }
     74        },
     75        "\/js-widgets\/v1\/widgets\/calendar\/(?P<widget_number>\\d+)": {
     76            "namespace": "js-widgets\/v1",
     77            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     78            "endpoints": [{
     79                "methods": ["GET"],
     80                "args": {
     81                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     82                }
     83            }, {
     84                "methods": ["POST", "PUT", "PATCH"],
     85                "args": {
     86                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     87                }
     88            }, {
     89                "methods": ["DELETE"],
     90                "args": {
     91                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     92                }
     93            }]
     94        },
     95        "\/js-widgets\/v1\/widgets\/archives": {
     96            "namespace": "js-widgets\/v1",
     97            "methods": ["GET", "POST"],
     98            "endpoints": [{
     99                "methods": ["GET"],
     100                "args": {
     101                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     102                }
     103            }, {
     104                "methods": ["POST"],
     105                "args": {
     106                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     107                    "dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
     108                    "count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" }
     109                }
     110            }],
     111            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/archives" }
     112        },
     113        "\/js-widgets\/v1\/widgets\/archives\/(?P<widget_number>\\d+)": {
     114            "namespace": "js-widgets\/v1",
     115            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     116            "endpoints": [{
     117                "methods": ["GET"],
     118                "args": {
     119                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     120                }
     121            }, {
     122                "methods": ["POST", "PUT", "PATCH"],
     123                "args": {
     124                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     125                    "dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
     126                    "count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" }
     127                }
     128            }, {
     129                "methods": ["DELETE"],
     130                "args": {
     131                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     132                    "dropdown": { "required": false, "description": "Display as dropdown", "type": "boolean" },
     133                    "count": { "required": false, "description": "Show post counts", "type": "boolean" }
     134                }
     135            }]
     136        },
     137        "\/js-widgets\/v1\/widgets\/meta": {
     138            "namespace": "js-widgets\/v1",
     139            "methods": ["GET", "POST"],
     140            "endpoints": [{
     141                "methods": ["GET"],
     142                "args": {
     143                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     144                }
     145            }, {
     146                "methods": ["POST"],
     147                "args": {
     148                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     149                }
     150            }],
     151            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/meta" }
     152        },
     153        "\/js-widgets\/v1\/widgets\/meta\/(?P<widget_number>\\d+)": {
     154            "namespace": "js-widgets\/v1",
     155            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     156            "endpoints": [{
     157                "methods": ["GET"],
     158                "args": {
     159                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     160                }
     161            }, {
     162                "methods": ["POST", "PUT", "PATCH"],
     163                "args": {
     164                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     165                }
     166            }, {
     167                "methods": ["DELETE"],
     168                "args": {
     169                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     170                }
     171            }]
     172        },
     173        "\/js-widgets\/v1\/widgets\/search": {
     174            "namespace": "js-widgets\/v1",
     175            "methods": ["GET", "POST"],
     176            "endpoints": [{
     177                "methods": ["GET"],
     178                "args": {
     179                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     180                }
     181            }, {
     182                "methods": ["POST"],
     183                "args": {
     184                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     185                }
     186            }],
     187            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/search" }
     188        },
     189        "\/js-widgets\/v1\/widgets\/search\/(?P<widget_number>\\d+)": {
     190            "namespace": "js-widgets\/v1",
     191            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     192            "endpoints": [{
     193                "methods": ["GET"],
     194                "args": {
     195                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     196                }
     197            }, {
     198                "methods": ["POST", "PUT", "PATCH"],
     199                "args": {
     200                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     201                }
     202            }, {
     203                "methods": ["DELETE"],
     204                "args": {
     205                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] }
     206                }
     207            }]
     208        },
     209        "\/js-widgets\/v1\/widgets\/text": {
     210            "namespace": "js-widgets\/v1",
     211            "methods": ["GET", "POST"],
     212            "endpoints": [{
     213                "methods": ["GET"],
     214                "args": {
     215                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     216                }
     217            }, {
     218                "methods": ["POST"],
     219                "args": {
     220                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     221                    "text": { "required": false, "description": "The content for the widget.", "type": ["string", "object"] },
     222                    "filter": { "required": false, "default": false, "description": "Whether paragraphs will be added for double line breaks (wpautop).", "type": "boolean" }
     223                }
     224            }],
     225            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/text" }
     226        },
     227        "\/js-widgets\/v1\/widgets\/text\/(?P<widget_number>\\d+)": {
     228            "namespace": "js-widgets\/v1",
     229            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     230            "endpoints": [{
     231                "methods": ["GET"],
     232                "args": {
     233                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     234                }
     235            }, {
     236                "methods": ["POST", "PUT", "PATCH"],
     237                "args": {
     238                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     239                    "text": { "required": false, "description": "The content for the widget.", "type": ["string", "object"] },
     240                    "filter": { "required": false, "default": false, "description": "Whether paragraphs will be added for double line breaks (wpautop).", "type": "boolean" }
     241                }
     242            }, {
     243                "methods": ["DELETE"],
     244                "args": {
     245                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     246                    "text": { "required": false, "description": "The content for the widget.", "type": ["string", "object"] },
     247                    "filter": { "required": false, "description": "Whether paragraphs will be added for double line breaks (wpautop).", "type": "boolean" }
     248                }
     249            }]
     250        },
     251        "\/js-widgets\/v1\/widgets\/categories": {
     252            "namespace": "js-widgets\/v1",
     253            "methods": ["GET", "POST"],
     254            "endpoints": [{
     255                "methods": ["GET"],
     256                "args": {
     257                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     258                }
     259            }, {
     260                "methods": ["POST"],
     261                "args": {
     262                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     263                    "dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
     264                    "count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" },
     265                    "hierarchical": { "required": false, "default": false, "description": "Show hierarchy", "type": "boolean" }
     266                }
     267            }],
     268            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/categories" }
     269        },
     270        "\/js-widgets\/v1\/widgets\/categories\/(?P<widget_number>\\d+)": {
     271            "namespace": "js-widgets\/v1",
     272            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     273            "endpoints": [{
     274                "methods": ["GET"],
     275                "args": {
     276                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     277                }
     278            }, {
     279                "methods": ["POST", "PUT", "PATCH"],
     280                "args": {
     281                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     282                    "dropdown": { "required": false, "default": false, "description": "Display as dropdown", "type": "boolean" },
     283                    "count": { "required": false, "default": false, "description": "Show post counts", "type": "boolean" },
     284                    "hierarchical": { "required": false, "default": false, "description": "Show hierarchy", "type": "boolean" }
     285                }
     286            }, {
     287                "methods": ["DELETE"],
     288                "args": {
     289                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     290                    "dropdown": { "required": false, "description": "Display as dropdown", "type": "boolean" },
     291                    "count": { "required": false, "description": "Show post counts", "type": "boolean" },
     292                    "hierarchical": { "required": false, "description": "Show hierarchy", "type": "boolean" }
     293                }
     294            }]
     295        },
     296        "\/js-widgets\/v1\/widgets\/recent-posts": {
     297            "namespace": "js-widgets\/v1",
     298            "methods": ["GET", "POST"],
     299            "endpoints": [{
     300                "methods": ["GET"],
     301                "args": {
     302                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     303                }
     304            }, {
     305                "methods": ["POST"],
     306                "args": {
     307                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     308                    "number": { "required": false, "default": 5, "description": "The number of posts to display.", "type": "integer" },
     309                    "show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
     310                }
     311            }],
     312            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/recent-posts" }
     313        },
     314        "\/js-widgets\/v1\/widgets\/recent-posts\/(?P<widget_number>\\d+)": {
     315            "namespace": "js-widgets\/v1",
     316            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     317            "endpoints": [{
     318                "methods": ["GET"],
     319                "args": {
     320                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     321                }
     322            }, {
     323                "methods": ["POST", "PUT", "PATCH"],
     324                "args": {
     325                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     326                    "number": { "required": false, "default": 5, "description": "The number of posts to display.", "type": "integer" },
     327                    "show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
     328                }
     329            }, {
     330                "methods": ["DELETE"],
     331                "args": {
     332                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     333                    "number": { "required": false, "description": "The number of posts to display.", "type": "integer" },
     334                    "show_date": { "required": false, "description": "Whether the date should be shown.", "type": "boolean" }
     335                }
     336            }]
     337        },
     338        "\/js-widgets\/v1\/widgets\/recent-comments": {
     339            "namespace": "js-widgets\/v1",
     340            "methods": ["GET", "POST"],
     341            "endpoints": [{
     342                "methods": ["GET"],
     343                "args": {
     344                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     345                }
     346            }, {
     347                "methods": ["POST"],
     348                "args": {
     349                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     350                    "number": { "required": false, "default": 5, "description": "The number of comments to display.", "type": "integer" }
     351                }
     352            }],
     353            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/recent-comments" }
     354        },
     355        "\/js-widgets\/v1\/widgets\/recent-comments\/(?P<widget_number>\\d+)": {
     356            "namespace": "js-widgets\/v1",
     357            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     358            "endpoints": [{
     359                "methods": ["GET"],
     360                "args": {
     361                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     362                }
     363            }, {
     364                "methods": ["POST", "PUT", "PATCH"],
     365                "args": {
     366                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     367                    "number": { "required": false, "default": 5, "description": "The number of comments to display.", "type": "integer" }
     368                }
     369            }, {
     370                "methods": ["DELETE"],
     371                "args": {
     372                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     373                    "number": { "required": false, "description": "The number of comments to display.", "type": "integer" }
     374                }
     375            }]
     376        },
     377        "\/js-widgets\/v1\/widgets\/rss": {
     378            "namespace": "js-widgets\/v1",
     379            "methods": ["GET", "POST"],
     380            "endpoints": [{
     381                "methods": ["GET"],
     382                "args": {
     383                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     384                }
     385            }, {
     386                "methods": ["POST"],
     387                "args": {
     388                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     389                    "url": { "required": false, "default": "", "description": "The RSS feed URL.", "type": "string" },
     390                    "items": { "required": false, "default": 10, "description": "The number of RSS items to display.", "type": "integer" },
     391                    "show_summary": { "required": false, "default": false, "description": "Whether the summary should be shown.", "type": "boolean" },
     392                    "show_author": { "required": false, "default": false, "description": "Whether the author should be shown.", "type": "boolean" },
     393                    "show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
     394                }
     395            }],
     396            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/rss" }
     397        },
     398        "\/js-widgets\/v1\/widgets\/rss\/(?P<widget_number>\\d+)": {
     399            "namespace": "js-widgets\/v1",
     400            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     401            "endpoints": [{
     402                "methods": ["GET"],
     403                "args": {
     404                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     405                }
     406            }, {
     407                "methods": ["POST", "PUT", "PATCH"],
     408                "args": {
     409                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     410                    "url": { "required": false, "default": "", "description": "The RSS feed URL.", "type": "string" },
     411                    "items": { "required": false, "default": 10, "description": "The number of RSS items to display.", "type": "integer" },
     412                    "show_summary": { "required": false, "default": false, "description": "Whether the summary should be shown.", "type": "boolean" },
     413                    "show_author": { "required": false, "default": false, "description": "Whether the author should be shown.", "type": "boolean" },
     414                    "show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" }
     415                }
     416            }, {
     417                "methods": ["DELETE"],
     418                "args": {
     419                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     420                    "url": { "required": false, "description": "The RSS feed URL.", "type": "string" },
     421                    "items": { "required": false, "description": "The number of RSS items to display.", "type": "integer" },
     422                    "show_summary": { "required": false, "description": "Whether the summary should be shown.", "type": "boolean" },
     423                    "show_author": { "required": false, "description": "Whether the author should be shown.", "type": "boolean" },
     424                    "show_date": { "required": false, "description": "Whether the date should be shown.", "type": "boolean" }
     425                }
     426            }]
     427        },
     428        "\/js-widgets\/v1\/widgets\/tag_cloud": {
     429            "namespace": "js-widgets\/v1",
     430            "methods": ["GET", "POST"],
     431            "endpoints": [{
     432                "methods": ["GET"],
     433                "args": {
     434                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     435                }
     436            }, {
     437                "methods": ["POST"],
     438                "args": {
     439                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     440                    "taxonomy": { "required": false, "default": "post_tag", "enum": ["category", "post_tag"], "description": "Taxonomy", "type": "string" }
     441                }
     442            }],
     443            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/tag_cloud" }
     444        },
     445        "\/js-widgets\/v1\/widgets\/tag_cloud\/(?P<widget_number>\\d+)": {
     446            "namespace": "js-widgets\/v1",
     447            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     448            "endpoints": [{
     449                "methods": ["GET"],
     450                "args": {
     451                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     452                }
     453            }, {
     454                "methods": ["POST", "PUT", "PATCH"],
     455                "args": {
     456                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     457                    "taxonomy": { "required": false, "default": "post_tag", "enum": ["category", "post_tag"], "description": "Taxonomy", "type": "string" }
     458                }
     459            }, {
     460                "methods": ["DELETE"],
     461                "args": {
     462                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     463                    "taxonomy": { "required": false, "enum": ["category", "post_tag"], "description": "Taxonomy", "type": "string" }
     464                }
     465            }]
     466        },
     467        "\/js-widgets\/v1\/widgets\/nav_menu": {
     468            "namespace": "js-widgets\/v1",
     469            "methods": ["GET", "POST"],
     470            "endpoints": [{
     471                "methods": ["GET"],
     472                "args": {
     473                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     474                }
     475            }, {
     476                "methods": ["POST"],
     477                "args": {
     478                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     479                    "nav_menu": { "required": false, "default": 0, "description": "Selected nav menu", "type": "integer" }
     480                }
     481            }],
     482            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/nav_menu" }
     483        },
     484        "\/js-widgets\/v1\/widgets\/nav_menu\/(?P<widget_number>\\d+)": {
     485            "namespace": "js-widgets\/v1",
     486            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     487            "endpoints": [{
     488                "methods": ["GET"],
     489                "args": {
     490                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     491                }
     492            }, {
     493                "methods": ["POST", "PUT", "PATCH"],
     494                "args": {
     495                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     496                    "nav_menu": { "required": false, "default": 0, "description": "Selected nav menu", "type": "integer" }
     497                }
     498            }, {
     499                "methods": ["DELETE"],
     500                "args": {
     501                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     502                    "nav_menu": { "required": false, "description": "Selected nav menu", "type": "integer" }
     503                }
     504            }]
     505        },
     506        "\/js-widgets\/v1\/widgets\/post-collection": {
     507            "namespace": "js-widgets\/v1",
     508            "methods": ["GET", "POST"],
     509            "endpoints": [{
     510                "methods": ["GET"],
     511                "args": {
     512                    "context": { "required": false, "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     513                }
     514            }, {
     515                "methods": ["POST"],
     516                "args": {
     517                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     518                    "show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" },
     519                    "show_featured_image": { "required": false, "default": false, "description": "Whether the featured image is shown.", "type": "boolean" },
     520                    "show_author": { "required": false, "default": false, "description": "Whether the author is shown.", "type": "boolean" },
     521                    "posts": { "required": false, "default": [], "description": "The IDs for the collected posts.", "type": "array" }
     522                }
     523            }],
     524            "_links": { "self": "http:\/\/newtest.localhost\/wp-json\/js-widgets\/v1\/widgets\/post-collection" }
     525        },
     526        "\/js-widgets\/v1\/widgets\/post-collection\/(?P<widget_number>\\d+)": {
     527            "namespace": "js-widgets\/v1",
     528            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
     529            "endpoints": [{
     530                "methods": ["GET"],
     531                "args": {
     532                    "context": { "required": false, "default": "view", "enum": ["view", "embed", "edit"], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }
     533                }
     534            }, {
     535                "methods": ["POST", "PUT", "PATCH"],
     536                "args": {
     537                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     538                    "show_date": { "required": false, "default": false, "description": "Whether the date should be shown.", "type": "boolean" },
     539                    "show_featured_image": { "required": false, "default": false, "description": "Whether the featured image is shown.", "type": "boolean" },
     540                    "show_author": { "required": false, "default": false, "description": "Whether the author is shown.", "type": "boolean" },
     541                    "posts": { "required": false, "default": [], "description": "The IDs for the collected posts.", "type": "array" }
     542                }
     543            }, {
     544                "methods": ["DELETE"],
     545                "args": {
     546                    "title": { "required": false, "description": "The title for the widget.", "type": ["string", "object"] },
     547                    "show_date": { "required": false, "description": "Whether the date should be shown.", "type": "boolean" },
     548                    "show_featured_image": { "required": false, "description": "Whether the featured image is shown.", "type": "boolean" },
     549                    "show_author": { "required": false, "description": "Whether the author is shown.", "type": "boolean" },
     550                    "posts": { "required": false, "description": "The IDs for the collected posts.", "type": "array" }
     551                }
     552            }]
     553        }
     554    },
     555    "_links": {
     556        "up": [
     557            { "href": "http:\/\/newtest.localhost\/wp-json\/" }
     558        ]
     559    }
     560};
  • tests/qunit/fixtures/wp-api.js

    diff --git a/tests/qunit/fixtures/wp-api.js b/tests/qunit/fixtures/wp-api.js
    index cbbc484..41e6cd7 100644
    a b var pathToData = { 
    2323        'wp-json/wp/v2/user': mockedApiResponse.UserModel,
    2424        'wp-json/wp/v2/taxonomy': mockedApiResponse.TaxonomyModel,
    2525        'wp-json/wp/v2/status': mockedApiResponse.StatusModel,
    26         'wp-json/wp/v2/type': mockedApiResponse.TypeModel
     26        'wp-json/wp/v2/type': mockedApiResponse.TypeModel,
     27        'wp-json/js-widgets/v1/': jsWidgetsEndpointSchema
    2728};
    2829
    2930/**
  • tests/qunit/index.html

    diff --git a/tests/qunit/index.html b/tests/qunit/index.html
    index 0b6930f..0c9d820 100644
    a b  
    4040                        <script src="fixtures/customize-menus.js"></script>
    4141                        <script src="fixtures/customize-widgets.js"></script>
    4242                        <script src="fixtures/wp-api-generated.js"></script>
     43                        <script src="fixtures/js-widgets-endpoint.js"></script>
    4344                        <script src="fixtures/wp-api.js"></script>
    4445                </div>
    4546                <p><a href="editor">TinyMCE tests</a></p>
  • tests/qunit/wp-admin/js/nav-menu.js

    diff --git a/tests/qunit/wp-admin/js/nav-menu.js b/tests/qunit/wp-admin/js/nav-menu.js
    index bd24b63..819c8bb 100644
    a b  
    77
    88        // Fail if we don't see the expected number of events triggered in 1500 ms.
    99        setTimeout( function() {
    10                 assert.equal(
     10                // QUnit may load this file without running it, in which case `assert`
     11                // will never be set to `assertPassed` below.
     12                assert && assert.equal(
    1113                        eventsFired,
    1214                        eventsExpected,
    1315                        eventsExpected + ' wpNavMenu events should fire.'
  • tests/qunit/wp-includes/js/wp-api.js

    diff --git a/tests/qunit/wp-includes/js/wp-api.js b/tests/qunit/wp-includes/js/wp-api.js
    index 5225d9e..acca461 100644
    a b  
    192192                } );
    193193        } );
    194194
     195// Test the jswidget custom namespace and endpoints.
     196wp.api.init( {
     197        'versionString': 'js-widgets/v1/'
     198} ).done( function() {
     199                var customClasses = [
     200                        'WidgetsArchives',
     201                        'WidgetsCalendar',
     202                        'WidgetsCategories',
     203                        'WidgetsMeta',
     204                        'WidgetsNav_menu',
     205                        'WidgetsPages',
     206                        'WidgetsPostCollection',
     207                        'WidgetsRecentComments',
     208                        'WidgetsRecentPosts',
     209                        'WidgetsRss',
     210                        'WidgetsSearch',
     211                        'WidgetsTag_cloud',
     212                        'WidgetsText'
     213                ];
     214
     215                // Check that we have and can get each model type.
     216                _.each( customClasses, function( className ) {
     217                        QUnit.test( 'Checking ' + className + ' class name.' , function( assert ) {
     218                                var done = assert.async();
     219
     220                                assert.expect( 2 );
     221
     222                                wp.api.loadPromise.done( function() {
     223                                        var theModel = new wp.api.models[ className ]();
     224                                        assert.ok( theModel, 'We can instantiate wp.api.models.' + className );
     225                                        var theCollection = new wp.api.collections[ className ]();
     226                                        assert.ok( theCollection, 'We can instantiate wp.api.collections.' + className );
     227                                        // Trigger Qunit async completion.
     228                                        done();
     229                                } );
     230                        } );
     231                } );
     232
     233        } );
     234
    195235} )( window.QUnit );