This document provides comprehensive test cases for verifying the exact ratio distribution feature for coupons and refunds in batch mode.
- WordPress installation with WooCommerce
- WC Smooth Generator plugin installed
- WP-CLI access
- Some products already generated (run
wp wc generate products 50if needed)
wp wc generate orders 100 --coupon-ratio=0.5Expected Result: Exactly 50 orders with coupons
Verification:
# Count orders with coupons via database
wp db query "SELECT COUNT(DISTINCT order_id) FROM wp_woocommerce_order_items WHERE order_item_type = 'coupon'"wp wc generate orders 50 --coupon-ratio=0.0Expected Result: 0 orders with coupons
wp wc generate orders 50 --coupon-ratio=1.0Expected Result: Exactly 50 orders with coupons
wp wc generate orders 11 --coupon-ratio=0.5Expected Result: Exactly 6 orders with coupons (5.5 rounds to 6)
wp wc generate orders 100 --status=completed --refund-ratio=0.4Expected Result:
- Total: 40 refunds
- Distribution: ~20 full, ~10 single partial, ~10 multi-partial
Verification:
# Count total refunds
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type = 'shop_order_refund'"
# Count full refunds (orders with status 'refunded')
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type = 'shop_order' AND post_status = 'wc-refunded'"wp wc generate orders 50 --status=completed --refund-ratio=0.0Expected Result: 0 refunds
wp wc generate orders 50 --status=completed --refund-ratio=1.0Expected Result: Exactly 50 refunds (distributed 50/25/25)
wp wc generate orders 11 --status=completed --refund-ratio=0.4Expected Result:
- Total: 4 refunds (rounded)
- Distribution: ~2 full, ~1 partial, ~1 multi (remainder)
wp wc generate orders 20 --couponsExpected Result: All 20 orders have coupons (legacy behavior preserved)
wp wc generate orders 100 --coupon-ratio=0.3Expected Result: Exactly 30 orders with coupons
wp wc generate orders 100 --coupons --coupon-ratio=0.3Expected Result: All 100 orders have coupons (--coupons takes precedence)
# Run multiple times to verify probabilistic behavior
wp wc generate orders 1 --coupon-ratio=0.5
wp wc generate orders 1 --coupon-ratio=0.5
wp wc generate orders 1 --coupon-ratio=0.5Expected Result: Approximately 50% of single orders will have coupons (varies each run)
# Generate orders and check distribution
wp wc generate orders 200 --status=completed --refund-ratio=0.5Expected Result:
- Total refunds: 100
- Full refunds (~50): Orders with status "refunded"
- Single partial (~25): Orders with 1 refund, status still "completed"
- Multi-partial (~25): Orders with 2 refunds, status still "completed"
Manual Verification:
- Check a sample of fully refunded orders in WP Admin
- Check a sample of partially refunded orders
- Count number of refund entries per order
wp wc generate orders 100 --date-start=2024-01-01 --date-end=2024-12-31 --status=completed --coupon-ratio=0.4 --refund-ratio=0.3Expected Result:
- Orders spread across date range
- Exactly 40 orders with coupons
- Exactly 30 orders with refunds (distributed 50/25/25)
# If products are missing or invalid, some orders may fail
wp wc generate orders 100 --coupon-ratio=0.5Expected Result:
- Count only successful orders
- If only 95 orders succeed, there should be exactly 47-48 with coupons (based on 95, not 100)
wp db query "SELECT COUNT(DISTINCT order_id) FROM wp_woocommerce_order_items WHERE order_item_type = 'coupon'"wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type = 'shop_order_refund'"wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type = 'shop_order' AND post_status = 'wc-refunded'"wp db query "
SELECT COUNT(*) as partial_refund_orders
FROM (
SELECT p.ID, COUNT(r.ID) as refund_count
FROM wp_posts p
LEFT JOIN wp_posts r ON r.post_parent = p.ID AND r.post_type = 'shop_order_refund'
WHERE p.post_type = 'shop_order' AND p.post_status = 'wc-completed'
GROUP BY p.ID
HAVING refund_count > 0
) as refunded_completed
"wp db query "
SELECT COUNT(*) as multi_partial_orders
FROM (
SELECT p.ID, COUNT(r.ID) as refund_count
FROM wp_posts p
LEFT JOIN wp_posts r ON r.post_parent = p.ID AND r.post_type = 'shop_order_refund'
WHERE p.post_type = 'shop_order'
GROUP BY p.ID
HAVING refund_count = 2
) as multi_refunded
"- All exact ratio tests assume successful order generation
- Exact ratio distribution uses O(1) memory via dynamic counters (selection without replacement algorithm)
- Works for any batch size without memory constraints
- Ratios are rounded using PHP's
round()function for odd numbers