Added unit tests for importer and exporter
This commit is contained in:
parent
37777432d4
commit
156b061602
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for the WC_Product_CSV_Exporter_Test class.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Tests\Exporter.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WC_Product_CSV_Exporter_Test
|
||||||
|
*/
|
||||||
|
class WC_Product_CSV_Exporter_Test extends \WC_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product IDs.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $product_ids = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load up the exporter classes since they aren't loaded by default.
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$bootstrap = \WC_Unit_Tests_Bootstrap::instance();
|
||||||
|
require_once $bootstrap->plugin_dir . '/includes/export/class-wc-product-csv-exporter.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to set product export query args.
|
||||||
|
*
|
||||||
|
* @param array $args Query args.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function set_export_product_query_args( $args ) {
|
||||||
|
$args['include'] = $this->product_ids;
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox variations should use draft status from parent product
|
||||||
|
*/
|
||||||
|
public function test_get_column_value_published() {
|
||||||
|
$product = WC_Helper_Product::create_variation_product();
|
||||||
|
$product->set_status( 'draft' );
|
||||||
|
$product->save();
|
||||||
|
|
||||||
|
$reflected_exporter = new ReflectionClass( WC_Product_CSV_Exporter::class );
|
||||||
|
$get_data_to_export = $reflected_exporter->getMethod( 'get_data_to_export' );
|
||||||
|
$get_data_to_export->setAccessible( true );
|
||||||
|
|
||||||
|
$this->product_ids = array_merge( array( $product->get_id() ), $product->get_children( 'edit' ) );
|
||||||
|
|
||||||
|
add_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
|
||||||
|
$exporter = new WC_Product_CSV_Exporter();
|
||||||
|
$exporter->prepare_data_to_export();
|
||||||
|
$data = $get_data_to_export->invoke( $exporter );
|
||||||
|
|
||||||
|
foreach ( $data as $row ) {
|
||||||
|
$this->assertEquals( -1, $row['published'] );
|
||||||
|
}
|
||||||
|
remove_filter( 'woocommerce_product_export_product_query_args', array( $this, 'set_export_product_query_args' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for the WC_Product_CSV_Importer_Test class.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\Tests\Importer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class WC_Product_CSV_Importer_Test
|
||||||
|
*/
|
||||||
|
class WC_Product_CSV_Importer_Test extends \WC_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load up the importer classes since they aren't loaded by default.
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$bootstrap = \WC_Unit_Tests_Bootstrap::instance();
|
||||||
|
require_once $bootstrap->plugin_dir . '/includes/import/class-wc-product-csv-importer.php';
|
||||||
|
require_once $bootstrap->plugin_dir . '/includes/admin/importers/class-wc-product-csv-importer-controller.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox variations need to set the status back to published if parent product is a draft
|
||||||
|
*/
|
||||||
|
public function test_expand_data_with_draft_variable() {
|
||||||
|
$csv_file = dirname( __FILE__ ) . '/sample.csv';
|
||||||
|
$raw_data = array(
|
||||||
|
array(
|
||||||
|
'type' => 'variable',
|
||||||
|
'published' => -1,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'type' => 'variation',
|
||||||
|
'published' => -1,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$reflected_importer = new ReflectionClass( WC_Product_CSV_Importer::class );
|
||||||
|
$expand_data = $reflected_importer->getMethod( 'expand_data' );
|
||||||
|
$expand_data->setAccessible( true );
|
||||||
|
|
||||||
|
$importer = new WC_Product_CSV_Importer( $csv_file );
|
||||||
|
$variable = $expand_data->invoke(
|
||||||
|
$importer,
|
||||||
|
array(
|
||||||
|
'type' => array( 'variable' ),
|
||||||
|
'published' => -1,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$variation = $expand_data->invoke(
|
||||||
|
$importer,
|
||||||
|
array(
|
||||||
|
'type' => array( 'variation' ),
|
||||||
|
'published' => -1,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals( 'draft', $variable['status'] );
|
||||||
|
$this->assertEquals( 'publish', $variation['status'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
Type,SKU,Name,Published,Is featured?,Visibility in catalog,Short description,Description,Date sale price starts,Date sale price ends,Tax status,Tax class,In stock?,Stock,Backorders allowed?,Sold individually?,Weight (kg),Length (cm),Width (cm),Height (cm),Allow customer reviews?,Purchase note,Sale price,Regular price,Categories,Tags,Shipping class,Images,Download limit,Download expiry days,Parent,Upsells,Cross-sells,Grouped products,External URL,BUTTON TEXT,Position,Attribute 1 Name,Attribute 1 Value(s),Attribute 2 name,Attribute 2 value(s),Attribute 1 default,Attribute 2 default,Download 1 name,Download 1 URL
|
||||||
|
simple,WOOLOGO,Woo Logo,1,,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",2017-01-01,2030-01-01 0:00:00,taxable,standard,1,5,notify,1,1,1,20,40,1,Lorem ipsum dolor sit amet.,18,20,"Clothing, Clothing > T-shirts",,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_back.jpg",,,,WOOALBUM,WOOALBUM,,,,0,Color,Red,,,,,,
|
||||||
|
"simple, downloadable, virtual",WOOALBUM,Woo Album #1,1,1,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,,,,,,,,1,Lorem ipsum dolor sit amet.,,5,"Music > Albums, Music",Woo,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_flat.jpg",10,90,,WOOLOGO,WOOLOGO,,,,1,Label,WooCommerce,Vinyl,180-Gram,,,Album flac,http://woo.dev/albums/album.flac
|
||||||
|
external,,WooCommerce Product CSV Suite,1,,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,,,,,,,,0,Lorem ipsum dolor sit amet.,,199,Software,WooCommerce,,,,,,,,,https://woocommerce.com/products/product-csv-import-suite/,Buy on WooCommerce.com,2,,,,,,,,
|
||||||
|
variable,WOOIDEA,Ship Your Idea,1,,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,,,,,,,,,,,1,Lorem ipsum dolor sit amet.,,,"Clothing, Clothing > T-shirts",,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg",,,,,,,,,3,Color,"Black, Green",Size,"M, L",Green,L,,
|
||||||
|
variation,,,1,,visible,,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,6,0,,1,2,25,55,,,,20,,,,http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg,,,WOOIDEA,,,,,,1,Color,Black,Size,M,,,,
|
||||||
|
variation,,,1,,visible,,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,taxable,standard,1,10,1,,1,2,25,55,,,17.99,20,,,,http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg,,,WOOIDEA,,,,,,2,Color,Green,Size,L,,,,
|
||||||
|
grouped,,Best Woo Products,1,1,visible,"Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.","Lorem ipsum dolor sit amet, at exerci civibus appetere sit, iuvaret hendrerit mea no. Eam integre feugait liberavisse an.",,,,,1,,,,,,,,,,,,"Clothing, Clothing > T-shirts, Music > Albums, Music",,,"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_1_front.jpg, http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_1_angle.jpg",,,,,,"WOOLOGO, WOOALBUM",,,4,,,,,,,,
|
|
Loading…
Reference in New Issue