Fix tests due to generated names
This commit is contained in:
parent
2346af1816
commit
21300951f1
|
@ -96,11 +96,17 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
|||
$product->set_date_created( current_time( 'timestamp', true ) );
|
||||
}
|
||||
|
||||
$new_title = $this->generate_product_title( $product );
|
||||
|
||||
if ( $product->get_name( 'edit' ) !== $new_title ) {
|
||||
$product->set_name( $new_title );
|
||||
}
|
||||
|
||||
$id = wp_insert_post( apply_filters( 'woocommerce_new_product_variation_data', array(
|
||||
'post_type' => 'product_variation',
|
||||
'post_status' => $product->get_status() ? $product->get_status() : 'publish',
|
||||
'post_author' => get_current_user_id(),
|
||||
'post_title' => $this->generate_product_title( $product ),
|
||||
'post_title' => $product->get_name( 'edit' ),
|
||||
'post_content' => '',
|
||||
'post_parent' => $product->get_parent_id(),
|
||||
'comment_status' => 'closed',
|
||||
|
@ -137,21 +143,25 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
|||
*/
|
||||
public function update( &$product ) {
|
||||
$product->save_meta_data();
|
||||
$changes = $product->get_changes();
|
||||
$title = $this->generate_product_title( $product );
|
||||
$changes = $product->get_changes();
|
||||
$new_title = $this->generate_product_title( $product );
|
||||
|
||||
if ( $product->get_name( 'edit' ) !== $new_title ) {
|
||||
$product->set_name( $new_title );
|
||||
}
|
||||
|
||||
// Only update the post when the post data changes.
|
||||
if ( $title !== $product->get_name( 'edit' ) || array_intersect( array( 'parent_id', 'status', 'menu_order', 'date_created', 'date_modified' ), array_keys( $changes ) ) ) {
|
||||
if ( array_intersect( array( 'name', 'parent_id', 'status', 'menu_order', 'date_created', 'date_modified' ), array_keys( $changes ) ) ) {
|
||||
$post_data = array(
|
||||
'post_title' => $title,
|
||||
'post_title' => $product->get_name( 'edit' ),
|
||||
'post_parent' => $product->get_parent_id( 'edit' ),
|
||||
'comment_status' => 'closed',
|
||||
'post_status' => $product->get_status( 'edit' ) ? $product->get_status( 'edit' ) : 'publish',
|
||||
'menu_order' => $product->get_menu_order( 'edit' ),
|
||||
'post_date' => gmdate( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $product->get_date_created( 'edit' )->getTimestamp() ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $product->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
|
||||
'post_date' => gmdate( 'Y-m-d H :i:s', $product->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||
'post_date_gmt' => gmdate( 'Y-m-d H :i:s', $product->get_date_created( 'edit' )->getTimestamp() ),
|
||||
'post_modified' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H :i:s', $product->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
|
||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H :i:s', $product->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
@ -247,7 +247,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 'Variable Product', $product->get_name() );
|
||||
|
||||
$variation = new WC_Product_Variation;
|
||||
$variation->set_name( 'Variation #1 of Dummy Variable CRUD Product' );
|
||||
$variation->set_parent_id( $product->get_id() );
|
||||
$variation->set_regular_price( 10 );
|
||||
$variation->set_sku( 'CRUD DUMMY SKU VARIABLE GREEN' );
|
||||
|
@ -258,7 +257,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$variation->set_attributes( array( 'pa_color' => 'green' ) );
|
||||
$variation->save();
|
||||
|
||||
$this->assertEquals( 'Variation #1 of Dummy Variable CRUD Product', $variation->get_name() );
|
||||
$this->assertEquals( 'CRUD DUMMY SKU VARIABLE GREEN', $variation->get_sku() );
|
||||
$this->assertEquals( 10, $variation->get_price() );
|
||||
|
||||
|
@ -270,7 +268,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( $expected_attributes, $product->get_variation_attributes() );
|
||||
|
||||
$variation_2 = new WC_Product_Variation;
|
||||
$variation_2->set_name( 'Variation #2 of Dummy Variable CRUD Product' );
|
||||
$variation_2->set_parent_id( $product->get_id() );
|
||||
$variation_2->set_regular_price( 10 );
|
||||
$variation_2->set_sku( 'CRUD DUMMY SKU VARIABLE RED' );
|
||||
|
@ -281,7 +278,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$variation_2->set_attributes( array( 'pa_color' => 'red' ) );
|
||||
$variation_2->save();
|
||||
|
||||
$this->assertEquals( 'Variation #2 of Dummy Variable CRUD Product', $variation_2->get_name() );
|
||||
$this->assertEquals( 'CRUD DUMMY SKU VARIABLE RED', $variation_2->get_sku() );
|
||||
$this->assertEquals( 10, $variation_2->get_price() );
|
||||
|
||||
|
@ -293,7 +289,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$expected_attributes = array( 'pa_color' => array( 'green', 'red' ) );
|
||||
$this->assertEquals( $expected_attributes, $product->get_variation_attributes() );
|
||||
|
||||
$variation_2->set_name( 'UPDATED - Variation #2 of Dummy Variable CRUD Product' );
|
||||
$variation_2->set_regular_price( 15 );
|
||||
$variation_2->set_sale_price( 9.99 );
|
||||
$variation_2->set_date_on_sale_to( '32532537600' );
|
||||
|
@ -308,7 +303,6 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$expected_prices['sale_price'][ $children[1] ] = 9.99;
|
||||
|
||||
$this->assertEquals( $expected_prices, $product->get_variation_prices() );
|
||||
$this->assertEquals( 'UPDATED - Variation #2 of Dummy Variable CRUD Product', $variation_2->get_name() );
|
||||
|
||||
$product->set_name( 'Renamed Variable Product' );
|
||||
$product->save();
|
||||
|
@ -469,16 +463,13 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
|
|||
$multiword_attribute_variation->save();
|
||||
|
||||
// Check the one attribute variation title.
|
||||
$loaded_variation = wc_get_product( $one_attribute_variation->get_id() );
|
||||
$this->assertEquals( "Test Product - Green", $loaded_variation->get_name() );
|
||||
$this->assertEquals( "Test Product - Green", $one_attribute_variation->get_name() );
|
||||
|
||||
// Check the two attribute variation title.
|
||||
$loaded_variation = wc_get_product( $two_attribute_variation->get_id() );
|
||||
$this->assertEquals( "Test Product - Green, Large", $loaded_variation->get_name() );
|
||||
$this->assertEquals( "Test Product - Green, Large", $two_attribute_variation->get_name() );
|
||||
|
||||
// Check the variation with a multiword attribute name.
|
||||
$loaded_variation = wc_get_product( $multiword_attribute_variation->get_id() );
|
||||
$this->assertEquals( "Test Product", $loaded_variation->get_name() );
|
||||
$this->assertEquals( "Test Product", $multiword_attribute_variation->get_name() );
|
||||
}
|
||||
|
||||
function test_generate_product_title_disable() {
|
||||
|
|
Loading…
Reference in New Issue