Pattern directory: Add pattern endpoint test matching schema#712
Open
Pattern directory: Add pattern endpoint test matching schema#712
Conversation
| $result = rest_validate_value_from_schema( $pattern, $schema ); | ||
| $this->assertTrue( $result ); | ||
|
|
||
| // Pattern content should always exist. |
Collaborator
There was a problem hiding this comment.
Should these comments be passed as messages in the assert functions?
| // Pattern content should always exist. | ||
| $this->assertNotEmpty( $pattern['pattern_content'] ); | ||
|
|
||
| // Check that these arrays are sequential, not associative arrays. |
Collaborator
There was a problem hiding this comment.
Assuming yes, but can't these be empty? Do we need to test for that?
Contributor
Author
There was a problem hiding this comment.
They can be, and as long as they're arrays it shouldn't cause any issues in the core API, so I don't think we need to test that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We recently had an issue causing errors on client WP sites because the Patterns API returned malformed category data — see #711. We did not have any tests to catch that change. This adds a very simple test to check the pattern API response against its own schema. This is not a perfect check (since the validation normalizes arrays), so I've also added some extra checks to make sure the pattern content is never empty, and the two array values used in core (
category_slugs&meta.wpop_block_types) are sequential arrays.See related tests in WordPress/wordpress.org#393
How to test the changes in this Pull Request:
yarn test:phporyarn test:php -- --group rest-apifor just this testarray_valuesfix in plugins/pattern-directory/includes/pattern-post-type.php