Added Upsell Collection Unit Test

This commit is contained in:
Christopher Allford 2024-09-16 13:29:12 -07:00
parent f80474b76f
commit fbebfa7616
No known key found for this signature in database
GPG Key ID: 80E44C778F08A88E
1 changed files with 31 additions and 0 deletions

View File

@ -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'] );
}
}