#39122 closed enhancement (fixed)
REST API: Add Term Meta Unit Test Coverage
Reported by: | timmydcrawford | Owned by: | kadamwhite |
---|---|---|---|
Milestone: | 4.9.9 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | |
Focuses: | Cc: |
Description
This is a follow up to #38989 where I had submitted a diff with some basic custom term + meta unit tests that didn't really apply to the issue at hand. @rachelbaker suggested ( https://core.trac.wordpress.org/ticket/38989#comment:4 ) that I add the tests in a new issue.
The tests assert that register_meta
on terms are properly included in term responses, and casted correctly for single=>true
and single=>false
. Additionally the tests act as documentation of sorts on how to interact with custom meta with terms in the REST API.
Attachments (4)
Change History (28)
This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.
8 years ago
#3
@
6 years ago
- Owner set to kadamwhite
- Resolution set to fixed
- Status changed from new to closed
In 43567:
#4
@
6 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Does not the ticket have to be moved from "Awaiting Review" to "Milestone 5.0.0"?
#5
@
6 years ago
Since the ticket has been reopen, 39122.2.diff contains some suggestions:
- Adjustments according to the WPCS.
- Removes duplicated array key assertion:
$this->assertArrayHasKey( 'meta', $data );
- Adds
@ticket
annotations. - Use
asserSame
instead ofassertEquals
, asnull
,false
and''
are equal underassertEquals
. - Use
assertFalse
instead ofassertEquals( false, ... )
Additional note: Instead of $this->assertEquals( false, isset( $meta['test_cat_meta'] ) );
, one could consider assertArrayNotHasKey
, but we note that it also returns true
for null
values. But I didn't change it in the patch to use assertArrayNotHasKey
.
#6
@
6 years ago
- Milestone changed from Awaiting Review to 5.0
[43567] also caused changes to the REST API fixtures, they need to be regenerated and committed.
#9
in reply to:
↑ 7
@
6 years ago
Replying to pento:
Nevermind, I accidentally committed the
wp-api-generated.js
update in [43571] .
@birgire: If you wouldn't mind refreshing your patch since [43571] auto-fixed a bunch of coding standards issues, we can get that committed.
yes sure, it looks like the WPCS has been fixed, so I updated the patch with 39122.3.diff.
When I was preparing the previous 39122.2.diff, I almost patched the changes to the auto generated wp-api-generated.js
too :-) I suspect we will see more of such patches in the future :-)
#12
follow-up:
↓ 16
@
6 years ago
- Keywords has-patch commit added
39122.3.diff should be committed and backported.
#14
@
6 years ago
@pento: [43646] was committed to the 4.9 branch, to fix an issue with the tests added in [43637], which depend on the test_tag_single
fixture added here.
If the ticket is set to 5.0, should [43637] and [43646] be reverted from the 4.9 branch? Or should be keep them and bring the ticket back to 4.9.9?
#16
in reply to:
↑ 12
@
6 years ago
Replying to SergeyBiryukov:
39122.3.diff should be committed and backported.
Moved to a separate ticket for easier management: #45077 (as trunk is currently closed for commits).
#18
follow-up:
↓ 19
@
6 years ago
@SergeyBiryukov - in r43713 the wp-api-generated.js file is changed because of leftover meta fields set up with register_meta
in the setUp
function of rest-tags-controller.php
. In the tearDown
function we can use unregister_meta
to remove these and the fixture would not need to change.
#19
in reply to:
↑ 18
@
6 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Replying to adamsilverstein:
in r43713 the wp-api-generated.js file is changed because of leftover meta fields set up with
register_meta
in thesetUp
function ofrest-tags-controller.php
.e.
Somehow I get different results when running grunt phpunit:restapi-jsclient
vs. phpunit --group restapi
: the latter includes these extra keys, the former does not.
Noticed after @atimmer pointed out that running grunt prerelease
leads to a modified wp-api-generated.js
file (in trunk and both 4.9 and 5.0 branches).
Reopening for investigation.
Expanded patch to cover the tags controller, and to test the new
register_term_meta
functions to ensure term meta can be limited to a single taxonomy's endpoint.