Creating Test Pages With WP-CLI
By: Ryan Kienstra on: June 24, 2018 in: Plugins
When you’re developing a new feature, it sometimes helps to write a a WP-CLI script to create a test page.
This helps with:
- Your development
- Code reviews
Here are some examples where creating test pages with WP-CLI can help.
Embed Test Page
Weston Ruter created a WP-CLI script that can add them to a post.
bash bin/create-gutenberg-test-post.sh in VVV produces this test page:
In some cases, it would have been easy to simply paste the embed URLs into the post content. But this script helps with the embeds and shortcodes with dynamic content, like the video playlist above.
Gutenberg Test Page
Luckily, Gutenberg has a great set of test fixtures, covering most blocks.
The script simply outputs those test fixtures, with slight changes:
There are often permutations that you’ll need to test. For example, a “Categories” block with a dropdown (shown above). This function adds some.
Creating test widgets with a script can be really useful. We needed to test all Core widgets, and several permutations of them.
This WP-CLI script adds the widgets.
It also prevents duplication by checking if a widget with the same values already exists.
Test Pages With WP-CLI
These can seem like too much for simple features. But they’re really useful when:
- There are several iterations of development (the embed support spanned several GitHub issues and developers)
- You’re testing in several environments
- You need to later test for regressions
This investment can save you a lot of time in testing and development.