pattern-directory icon indicating copy to clipboard operation
pattern-directory copied to clipboard

Pattern directory: Add pattern endpoint test matching schema

Open ryelle opened this issue 1 year ago • 0 comments

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 https://github.com/WordPress/wordpress.org/pull/393

How to test the changes in this Pull Request:

  1. Start up the wp-env
  2. Run yarn test:php or yarn test:php -- --group rest-api for just this test
  3. It should pass ✅
  4. Comment out the array_values fix in plugins/pattern-directory/includes/pattern-post-type.php
  5. Run the test again
  6. It should fail ❌

ryelle avatar Oct 07 '24 22:10 ryelle