WC_Tests_API_Orders: Add test data for site-level attributes

This commit is contained in:
Shiki 2020-07-30 15:15:06 -06:00 committed by vedanshujain
parent dc2a4d1ccc
commit 2a01aa968f
1 changed files with 20 additions and 0 deletions

View File

@ -152,11 +152,24 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
public function test_get_item_with_line_items_meta_data() {
wp_set_current_user( $this->user );
$site_level_attribute_id = wc_create_attribute( array( 'name' => 'Site Level Color' ) );
$site_level_attribute_slug = wc_attribute_taxonomy_name_by_id( $site_level_attribute_id );
// Register the attribute so that wp_insert_term will be successful
register_taxonomy( $site_level_attribute_slug, array( 'product' ), array() );
$site_level_term_insertion_result = wp_insert_term( 'Site Level Value - Blue', $site_level_attribute_slug );
$site_level_term = get_term( $site_level_term_insertion_result['term_id'] );
$product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
$variation = wc_get_product( $product->get_children()[0] );
$line_item = new WC_Order_Item_Product();
$line_item->set_product( $variation );
$line_item->set_props( array(
'variation' => array( "attribute_{$site_level_attribute_slug}" => $site_level_term->slug )
) );
$order = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order();
$order->add_item( $line_item );
$order->save();
@ -175,6 +188,13 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
$this->assertEquals( 'size', $size_meta_data['display_key'] );
$this->assertEquals( 'small', $size_meta_data['value'] );
$this->assertEquals( 'small', $size_meta_data['display_value'] );
$color_meta_data = $last_line_item['meta_data'][1];
$this->assertEquals( $line_item->get_meta_data()[1]->id, $color_meta_data['id'] );
$this->assertEquals( $site_level_attribute_slug, $color_meta_data['key'] );
$this->assertEquals( 'Site Level Color', $color_meta_data['display_key'] );
$this->assertEquals( $site_level_term->slug, $color_meta_data['value'] );
$this->assertEquals( 'Site Level Value - Blue', $color_meta_data['display_value'] );
}
/**