Added Upsell Collection Unit Test
This commit is contained in:
parent
f80474b76f
commit
fbebfa7616
|
@ -1173,4 +1173,35 @@ class ProductCollection extends \WP_UnitTestCase {
|
|||
$this->assertEqualsCanonicalizing( $expected_product_ids, $result_frontend['post__in'] );
|
||||
$this->assertEqualsCanonicalizing( $expected_product_ids, $result_editor['post__in'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the upsells collection handler works as expected.
|
||||
*/
|
||||
public function test_collection_upsells() {
|
||||
$expected_product_ids = array( 2, 3, 4 );
|
||||
$test_product = WC_Helper_Product::create_simple_product( false );
|
||||
$test_product->set_upsell_ids( $expected_product_ids );
|
||||
$test_product->save();
|
||||
|
||||
// Frontend.
|
||||
$parsed_block = $this->get_base_parsed_block();
|
||||
$parsed_block['attrs']['collection'] = 'woocommerce/product-collection/upsells';
|
||||
$parsed_block['attrs']['query']['productReference'] = $test_product->get_id();
|
||||
$result_frontend = $this->initialize_merged_query( $parsed_block );
|
||||
|
||||
// Editor.
|
||||
$request = $this->build_request(
|
||||
array( 'productReference' => $test_product->get_id() )
|
||||
);
|
||||
$request->set_param(
|
||||
'productCollectionQueryContext',
|
||||
array(
|
||||
'collection' => 'woocommerce/product-collection/upsells',
|
||||
)
|
||||
);
|
||||
$result_editor = $this->block_instance->update_rest_query_in_editor( array(), $request );
|
||||
|
||||
$this->assertEqualsCanonicalizing( $expected_product_ids, $result_frontend['post__in'] );
|
||||
$this->assertEqualsCanonicalizing( $expected_product_ids, $result_editor['post__in'] );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue