Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Jan 5, 2024
1 parent 8e9a4ca commit 4246ac1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
30 changes: 15 additions & 15 deletions tests/Helpers/ProductHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ public static function create_simple_product( $args = array(), $save = true ) {
'name' => 'Dummy Product',
'regular_price' => 10,
'price' => 10,
'sku' => 'DUMMY SKU',
'sku' => uniqid( 'DUMMY SKU' ),
'manage_stock' => false,
'tax_status' => 'taxable',
'downloadable' => false,
'virtual' => false,
'stock_status' => 'instock',
'weight' => '1.1',
);

// Merge default properties with user-provided args
$props = wp_parse_args( $args, $defaults );

$product = new WC_Product_Simple();
$product->set_props( $props );

if ( $save ) {
$product->save();

Expand All @@ -72,7 +72,7 @@ public static function create_simple_product( $args = array(), $save = true ) {

return $product;
}


/**
* Create external product.
Expand All @@ -87,7 +87,7 @@ public static function create_external_product() {
array(
'name' => 'Dummy External Product',
'regular_price' => 10,
'sku' => 'DUMMY EXTERNAL SKU',
'sku' => uniqid( 'DUMMY EXTERNAL SKU' ),
'product_url' => 'http://woocommerce.com',
'button_text' => 'Buy external product',
)
Expand All @@ -111,7 +111,7 @@ public static function create_grouped_product() {
$product->set_props(
array(
'name' => 'Dummy Grouped Product',
'sku' => 'DUMMY GROUPED SKU',
'sku' => uniqid( 'DUMMY GROUPED SKU' ),
)
);
$product->set_children( array( $simple_product_1->get_id(), $simple_product_2->get_id() ) );
Expand All @@ -132,7 +132,7 @@ public static function create_variation_product() {
$product->set_props(
array(
'name' => 'Dummy Variable Product',
'sku' => 'DUMMY VARIABLE SKU',
'sku' => uniqid( 'DUMMY VARIABLE SKU' ),
)
);

Expand All @@ -154,7 +154,7 @@ public static function create_variation_product() {
$variation_1->set_props(
array(
'parent_id' => $product->get_id(),
'sku' => 'DUMMY SKU VARIABLE SMALL',
'sku' => uniqid( 'DUMMY SKU VARIABLE SMALL' ),
'regular_price' => 10,
)
);
Expand All @@ -165,7 +165,7 @@ public static function create_variation_product() {
$variation_2->set_props(
array(
'parent_id' => $product->get_id(),
'sku' => 'DUMMY SKU VARIABLE LARGE',
'sku' => uniqid( 'DUMMY SKU VARIABLE LARGE' ),
'regular_price' => 15,
)
);
Expand Down Expand Up @@ -322,7 +322,7 @@ public static function create_product_review( $product_id, $review_content = 'Re
public static function save_post_test_update_meta_data_direct( $id ): void {
update_post_meta( $id, '_test2', 'world' );
}

/**
* Create a product category.
*
Expand All @@ -333,7 +333,7 @@ public static function save_post_test_update_meta_data_direct( $id ): void {
*/
public static function create_product_category( string $name, ?int $parent = null ) {
// Create a new product category
$args = $parent ? array('parent' => $parent) : array();
$args = $parent ? array( 'parent' => $parent ) : array();

return wp_insert_term( $name, 'product_cat', $args );
}
Expand All @@ -348,7 +348,7 @@ public static function create_product_category( string $name, ?int $parent = nul
*/
public static function delete_product_category( int $term_id, bool $force = false ) {
// Delete the product category
return wp_delete_term( $term_id, 'product_cat', array('force_default' => $force) );
return wp_delete_term( $term_id, 'product_cat', array( 'force_default' => $force ) );
}

/**
Expand All @@ -361,7 +361,7 @@ public static function delete_product_category( int $term_id, bool $force = fals
*/
public static function create_product_tag( string $name, ?int $parent = null ) {
// Create a new product tag
$args = $parent ? array('parent' => $parent) : array();
$args = $parent ? array( 'parent' => $parent ) : array();

return wp_insert_term( $name, 'product_tag', $args );
}
Expand All @@ -376,6 +376,6 @@ public static function create_product_tag( string $name, ?int $parent = null ) {
*/
public static function delete_product_tag( int $term_id, bool $force = false ) {
// Delete the product category
return wp_delete_term( $term_id, 'product_tag', array('force_default' => $force) );
return wp_delete_term( $term_id, 'product_tag', array( 'force_default' => $force ) );
}
}
2 changes: 1 addition & 1 deletion tests/includes/API/Test_Orders_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public function test_order_search_by_billing_first_name_with_excludes() {
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 0, \count( $data ) );
$this->assertEquals( 1, \count( $data ) );

$ids = wp_list_pluck( $data, 'id' );
$this->assertEquals( array( $order2->get_id() ), $ids );
Expand Down
9 changes: 5 additions & 4 deletions tests/includes/API/Test_Product_Variations_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ public function test_variation_response_contains_sku_barcode(): void {
$data = $response->get_data();

$this->assertEquals( 200, $response->get_status() );

$this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $data['barcode'] );
$this->assertStringStartsWith( 'DUMMY SKU VARIABLE SMALL', $data['barcode'] );
}

public function test_variation_response_contains_barcode(): void {
Expand Down Expand Up @@ -273,7 +272,8 @@ public function test_variation_orderby_sku(): void {
$data = $response->get_data();
$skus = wp_list_pluck( $data, 'sku' );

$this->assertEquals( $skus, array( 'DUMMY SKU VARIABLE LARGE', 'DUMMY SKU VARIABLE SMALL' ) );
$this->assertStringStartsWith( 'DUMMY SKU VARIABLE LARGE', $skus[0] );
$this->assertStringStartsWith( 'DUMMY SKU VARIABLE SMALL', $skus[1] );

// reverse order
$request->set_query_params(
Expand All @@ -286,7 +286,8 @@ public function test_variation_orderby_sku(): void {
$data = $response->get_data();
$skus = wp_list_pluck( $data, 'sku' );

$this->assertEquals( $skus, array( 'DUMMY SKU VARIABLE SMALL', 'DUMMY SKU VARIABLE LARGE' ) );
$this->assertStringStartsWith( 'DUMMY SKU VARIABLE SMALL', $skus[0] );
$this->assertStringStartsWith( 'DUMMY SKU VARIABLE LARGE', $skus[1] );
}

public function test_variation_orderby_barcode(): void {
Expand Down

0 comments on commit 4246ac1

Please sign in to comment.