2018-04-06 17:47:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test template funcitons.
|
|
|
|
*
|
|
|
|
* @package WooCommerce/Tests/Templates
|
|
|
|
* @since 3.4.0
|
|
|
|
*/
|
|
|
|
class WC_Tests_Template_Functions extends WC_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_get_product_class().
|
|
|
|
*
|
2018-07-20 12:34:43 +00:00
|
|
|
* @covers ::wc_product_class()
|
|
|
|
* @covers ::wc_product_post_class()
|
|
|
|
* @covers ::wc_get_product_taxonomy_class()
|
2018-04-17 15:31:14 +00:00
|
|
|
* @since 3.4.0
|
2018-04-06 17:47:18 +00:00
|
|
|
*/
|
|
|
|
public function test_wc_get_product_class() {
|
2018-04-17 15:31:14 +00:00
|
|
|
$category = wp_insert_term( 'Some Category', 'product_cat' );
|
|
|
|
|
2018-04-06 17:47:18 +00:00
|
|
|
$product = new WC_Product_Simple();
|
|
|
|
$product->set_virtual( true );
|
|
|
|
$product->set_regular_price( '10' );
|
|
|
|
$product->set_sale_price( '5' );
|
2018-04-17 15:31:14 +00:00
|
|
|
$product->set_category_ids( array( $category['term_id'] ) );
|
2018-04-06 17:47:18 +00:00
|
|
|
$product->save();
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'foo',
|
|
|
|
'post-' . $product->get_id(),
|
|
|
|
'product',
|
|
|
|
'type-product',
|
|
|
|
'status-publish',
|
2018-04-17 15:31:14 +00:00
|
|
|
'product_cat-some-category',
|
2018-04-06 17:47:18 +00:00
|
|
|
'first',
|
|
|
|
'instock',
|
|
|
|
'sale',
|
|
|
|
'virtual',
|
|
|
|
'purchasable',
|
|
|
|
'product-type-simple',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, array_values( wc_get_product_class( 'foo', $product ) ) );
|
2018-04-06 17:49:20 +00:00
|
|
|
|
2018-04-17 15:31:14 +00:00
|
|
|
// All taxonomies.
|
|
|
|
add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_true' );
|
|
|
|
$expected = array(
|
|
|
|
'foo',
|
|
|
|
'post-' . $product->get_id(),
|
|
|
|
'product',
|
|
|
|
'type-product',
|
|
|
|
'status-publish',
|
|
|
|
'product_cat-some-category',
|
|
|
|
'instock',
|
|
|
|
'sale',
|
|
|
|
'virtual',
|
|
|
|
'purchasable',
|
|
|
|
'product-type-simple',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, array_values( wc_get_product_class( 'foo', $product ) ) );
|
|
|
|
add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_false' );
|
|
|
|
|
2018-04-06 17:49:20 +00:00
|
|
|
$product->delete( true );
|
2018-04-17 15:31:14 +00:00
|
|
|
wp_delete_term( $category['term_id'], 'product_cat' );
|
2018-04-06 17:47:18 +00:00
|
|
|
}
|
|
|
|
}
|