Fixed unit tests

This commit is contained in:
Mike Jolley 2019-02-06 21:00:07 +00:00
parent e604a3ae24
commit 4b485eba13
2 changed files with 25 additions and 9 deletions

View File

@ -627,9 +627,10 @@ function wc_get_product_class( $class = '', $product_id = null ) {
// Include attributes and any extra taxonomies only if enabled via the hook - this is a performance issue.
if ( apply_filters( 'woocommerce_get_product_class_include_taxonomies', false ) ) {
$taxonomies = get_taxonomies( array( 'public' => true ) );
$type = 'variation' === $product->get_type() ? 'product_variation' : 'product';
foreach ( (array) $taxonomies as $taxonomy ) {
if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) && ! in_array( $taxonomy, array( 'product_cat', 'product_tag' ), true ) ) {
$classes = array_merge( $classes, wc_get_product_taxonomy_class( (array) get_the_terms( $post->ID, $taxonomy ), $taxonomy ) );
if ( is_object_in_taxonomy( $type, $taxonomy ) && ! in_array( $taxonomy, array( 'product_cat', 'product_tag' ), true ) ) {
$classes = array_merge( $classes, wc_get_product_taxonomy_class( (array) get_the_terms( $product->get_id(), $taxonomy ), $taxonomy ) );
}
}
}

View File

@ -1,11 +1,14 @@
<?php
/**
* Test template funcitons.
*
* @package WooCommerce/Tests/Templates
* @since 3.4.0
*/
/**
* WC_Tests_Template_Functions class.
*/
class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
/**
@ -26,52 +29,61 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
$product->set_category_ids( array( $category['term_id'] ) );
$product->save();
$product = wc_get_product( $product ); // Reload so status is current.
$expected = array(
'foo',
'post-' . $product->get_id(),
'product',
'type-product',
'post-' . $product->get_id(),
'status-publish',
'product_cat-some-category',
'first',
'instock',
'product_cat-some-category',
'sale',
'virtual',
'purchasable',
'product-type-simple',
);
$actual = array_values( wc_get_product_class( 'foo', $product ) );
$this->assertEquals( $expected, array_values( wc_get_product_class( 'foo', $product ) ) );
$this->assertEquals( $expected, $actual, print_r( $actual, true ) );
// All taxonomies.
add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_true' );
$expected = array(
'foo',
'post-' . $product->get_id(),
'product',
'type-product',
'post-' . $product->get_id(),
'status-publish',
'product_cat-some-category',
'instock',
'product_cat-some-category',
'sale',
'virtual',
'purchasable',
'product-type-simple',
);
$actual = array_values( wc_get_product_class( 'foo', $product ) );
$this->assertEquals( $expected, array_values( wc_get_product_class( 'foo', $product ) ) );
$this->assertEquals( $expected, $actual, print_r( $actual, true ) );
add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_false' );
$product->delete( true );
wp_delete_term( $category['term_id'], 'product_cat' );
}
/**
* Test: test_wc_dropdown_variation_attribute_options_no_attributes.
*/
public function test_wc_dropdown_variation_attribute_options_no_attributes() {
$this->expectOutputString( '<select id="" class="" name="attribute_" data-attribute_name="attribute_" data-show_option_none="yes"><option value="">Choose an option</option></select>' );
wc_dropdown_variation_attribute_options();
}
/**
* Test: test_wc_dropdown_variation_attribute_options_should_return_attributes_list.
*/
public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list() {
$product = WC_Helper_Product::create_variation_product();
@ -85,6 +97,9 @@ class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
);
}
/**
* Test: test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element.
*/
public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element() {
$product = WC_Helper_Product::create_variation_product();
$_REQUEST['attribute_pa_size'] = 'large';