Merge pull request #12417 from woocommerce/try/product_attributes_test

Add a test for variation attributes on update
This commit is contained in:
Mike Jolley 2016-11-21 11:12:00 +00:00 committed by GitHub
commit e2dc93c710
1 changed files with 32 additions and 0 deletions

View File

@ -316,4 +316,36 @@ class WC_Tests_Product_Data_Store extends WC_Unit_Test_Case {
$product->delete();
}
function test_varation_save_attributes() {
// Create a variable product with a color attribute.
$product = new WC_Product_Variable;
$attribute = new WC_Product_Attribute();
$attribute->set_id( 0 );
$attribute->set_name( 'color' );
$attribute->set_options( explode( WC_DELIMITER, 'green | red' ) );
$attribute->set_visible( true );
$attribute->set_variation( true );
$product->set_attributes( array( $attribute ) );
$product->save();
// Create a new variation with the color 'green'.
$variation = new WC_Product_Variation;
$variation->set_parent_id( $product->get_id() );
$variation->set_attributes( array( 'color' => 'green' ) );
$variation->set_status( 'private' );
$variation->save();
// Now update some value unrelated to attributes.
$variation = wc_get_product( $variation->get_id() );
$variation->set_status( 'publish' );
$variation->save();
// Load up the updated variation and verify that the saved state is correct.
$loaded_variation = wc_get_product( $variation->get_id() );
$this->assertEquals( 'publish', $loaded_variation->get_status( 'edit' ) );
$this->assertEquals( 'green', $loaded_variation->get_attributes( 'edit' )[ 'attribute_color' ] );
}
}