OrdersV2: Add test for line items meta_data
This currently fails because it's not implemented yet.
This commit is contained in:
parent
871a9e0b8f
commit
a9bf6b71ac
|
@ -68,6 +68,57 @@ class WC_Tests_API_Orders_V2 extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( 401, $response->get_status() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests line items have the expected meta_data properties when getting a single order.
|
||||
*/
|
||||
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();
|
||||
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v2/orders/' . $order->get_id() ) );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEquals( $order->get_id(), $data['id'] );
|
||||
|
||||
$last_line_item = array_slice( $data['line_items'], -1 )[0];
|
||||
|
||||
$size_meta_data = $last_line_item['meta_data'][0];
|
||||
$this->assertEquals( $line_item->get_meta_data()[0]->id, $size_meta_data['id'] );
|
||||
$this->assertEquals( 'pa_size', $size_meta_data['key'] );
|
||||
$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'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getting a single order.
|
||||
* @since 3.0.0
|
||||
|
|
Loading…
Reference in New Issue