woocommerce/tests/unit-tests/product
Timon Davis af308da6b9 Fix bug #15103 where site operator cannot assign a variation with value of '0' as the default choice on the customer facing form.
The WC_Product::set_default_attributes function uses an array_filter (using the default callback for filtration)
to remove null and false values from the defaults array for a given product.  The issue here is that, in the above use case,
the array_filter will evaluate '0' as 0 and therefore as false.  Ultimately, array_filter then prevents the value from being
recorded, moving forward.

I've added a new filter callback to includes/wc-attribute-functions which will disregard all FALSE PHP equivalents except for
'0' (as a a string).  Also, I've updated the filter_array call in WC_Product::set_default_attributes so that it uses this new callback,
instead of the PHP default. Finally, I've added a phpunit test to assert that, when storing default variations / attributes on a product,
the false/true PHP synonyms are evaluating and storing like one would normally expect, with the exception that (string) '0'
evaluates as true in this special case.

This solution could potentially be broadened to facililate similar rules elsewhere, but the need raised in the bug is specific and
this is a specific solution.
2017-05-18 02:43:14 -07:00
..
data-store.php Fix bug #15103 where site operator cannot assign a variation with value of '0' as the default choice on the customer facing form. 2017-05-18 02:43:14 -07:00
data.php Changed version 2.7 to 3.0 2017-03-15 13:36:53 -03:00
factory.php Changed version 2.7 to 3.0 2017-03-15 13:36:53 -03:00
functions.php Fix test 2017-05-08 19:14:33 +01:00
product-simple.php WIP - Product CRUD (#12065) 2016-11-16 12:38:24 +00:00
product-variation.php Clean up test 2017-04-05 11:13:31 -07:00