-
Notifications
You must be signed in to change notification settings - Fork 47
Refactor weak assertions in test-form-wc-order.php
#335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…a summary: ## Summary Refactored 5 weak `assertTrue(true)` assertions in `test-form-wc-order.php` with meaningful assertions: | Test | Before | After | |------|--------|-------| | `test_add_meta_boxes_returns_early_for_null_order` | `assertTrue(true)` | `assertFalse(has_action(...))` - verifies the action is NOT added when order is null | | `test_order_edit_form_top_uses_correct_post_id_format` | `assertTrue(true)` | `assertStringContainsString()` - verifies output contains `woo_order_456` and `acf-form-data` container | | `test_render_meta_box_handles_wp_post` | `assertTrue(true)` | `assertEquals()` via `acf/render_fields` action hook - verifies post_id is `woo_order_789` | | `test_render_meta_box_handles_wc_order` | `assertTrue(true)` | `assertEquals()` via `acf/render_fields` action hook - verifies post_id is `woo_order_321` | | `test_save_order_requires_hpos` | `assertTrue(true)` | `assertNotFalse(has_action(...))` - verifies action is NOT removed when HPOS is disabled | All 23 tests pass with 28 assertions (up from 23 assertions before).
**Issues found and fixed:** 1. **Action callback leaks** - The `acf/render_fields` action callbacks were added but never removed, potentially polluting other tests. Fixed by storing the callback in a variable and calling `remove_action()` after the test. 2. **No verification that action was called** - The tests would pass even if `acf/render_fields` was never fired (e.g., if `acf_get_fields` returned empty). Added `assertNotNull($rendered_post_id)` to verify the action was actually triggered. 3. **Unused `$output` variable** - The `ob_get_clean()` result was stored but never used. Changed to just `ob_get_clean()` without assignment. **Final state:** - 23 tests, 30 assertions (up from original 23 assertions) - All tests pass - Lint passes - Tests are now more honest and properly isolated
**Refactoring done:** - Consolidated `test_render_meta_box_handles_wp_post` and `test_render_meta_box_handles_wc_order` into a single data-provider-driven test `test_render_meta_box_uses_correct_post_id_format` - Reduced code duplication by ~30 lines - Same test coverage (23 tests, 30 assertions)
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #335 +/- ##
=========================================
Coverage 25.13% 25.13%
Complexity 4410 4410
=========================================
Files 291 291
Lines 36916 36916
=========================================
Hits 9278 9278
Misses 27638 27638
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
test-form-wc-order.php
What
Closes #334.
Replaces weak
assertTrue(true)assertions in WC_Order form with behavior testing.Why
To make tests more meaningful.
How
Refactoring 5 tests to use specific assertions:
test_add_meta_boxes_returns_early_for_null_order: Verifying theorder_edit_form_topaction is not added when order is null.test_order_edit_form_top_uses_correct_post_id_format: Checking output containswoo_order_{id}format and theacf-form-datacontainer.test_render_meta_box_uses_correct_post_id_format: Using a data provider to test both WP_Post and WC_Order inputs, verifying theacf/render_fieldsaction receives the correct post_id format.test_save_order_requires_hpos: Confirming the action is not removed when HPOS is disabled (early return).Consolidating two similar render_meta_box tests into a single data-provider-driven test to reduce duplication.
Testing Instructions
Run the WC_Order form tests: