From 112da861ca12bd91eaa5250ed844332d582d424b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 7 Jun 2008 22:35:55 +0000 Subject: [PATCH] add missing collateral from previous commit, add more tests for import --- t/Shop/Products.t | 75 ++++++++++++++++++- .../productTables/secondProductTable.csv | 7 ++ .../productTables/thirdProductTable.csv | 5 ++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 t/supporting_collateral/productTables/secondProductTable.csv create mode 100644 t/supporting_collateral/productTables/thirdProductTable.csv diff --git a/t/Shop/Products.t b/t/Shop/Products.t index 76627f42f..20b68f1c6 100644 --- a/t/Shop/Products.t +++ b/t/Shop/Products.t @@ -33,7 +33,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 36; +my $tests = 41; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -225,15 +225,15 @@ SKIP: { ####################################################################### # - # export, part 2 + # import, part 2 # ####################################################################### - my $pass = WebGUI::Shop::Products::importProducts( + $pass = WebGUI::Shop::Products::importProducts( $session, WebGUI::Test->getTestCollateralPath('productTables/secondProductTable.csv'), ); - ok($pass, 'Products imported'); + ok($pass, 'Products imported for the second time'); my $count = $session->db->quickScalar('select count(*) from Product'); is($count, 3, 'three products were imported'); @@ -298,6 +298,73 @@ SKIP: { 'collateral set correctly for classical record' ); + ####################################################################### + # + # import, part 3 + # + ####################################################################### + + $pass = WebGUI::Shop::Products::importProducts( + $session, + WebGUI::Test->getTestCollateralPath('productTables/thirdProductTable.csv'), + ); + ok($pass, 'Products imported for the third time'); + + my $count = $session->db->quickScalar('select count(*) from Product'); + is($count, 3, 'still have 3 products, nothing new added'); + + my $soda = WebGUI::Asset::Sku->newBySku($session, 'soda'); + is($soda->getTitle(), 'Sweet Soda-totally organic', 'Title updated correctly for soda'); + $shirt = WebGUI::Asset::Sku->newBySku($session, 't-shirt'); + my $shirtCollateral = $shirt->getAllCollateral('variantsJSON'); + cmp_deeply( + $shirtCollateral, + [ + { + sku => 'red-t-shirt', + shortdesc => 'Red T-Shirt', + price => '5.00', + weight => '1.33', + quantity => '500', + variantId => ignore(), + }, + { + sku => 'blue-t-shirt', + shortdesc => 'Blue T-Shirt', + price => '5.25', + weight => '1.33', + quantity => '2000', + variantId => ignore(), + }, + ], + 'collateral updated correctly for shirt' + ); + + my $record = WebGUI::Asset::Sku->newBySku($session, 'classical-records-1'); + my $recordCollateral = $record->getAllCollateral('variantsJSON'); + cmp_deeply( + $recordCollateral, + [ + { + sku => 'track-16', + shortdesc => 'Track 16', + price => '3.25', + weight => '0.00', + quantity => 50, + variantId => ignore(), + }, + { + sku => 'track-9', + shortdesc => 'Track 9', + price => '3.25', + weight => '0.00', + quantity => 55, + variantId => ignore(), + }, + ], + 'collateral added correctly for classical record' + ); + } diff --git a/t/supporting_collateral/productTables/secondProductTable.csv b/t/supporting_collateral/productTables/secondProductTable.csv new file mode 100644 index 000000000..d89899ba8 --- /dev/null +++ b/t/supporting_collateral/productTables/secondProductTable.csv @@ -0,0 +1,7 @@ +mastersku,sku,title,shortdescription,price,weight,quantity +##alter existing with two collateral +t-shirt,red-t-shirt,Colored T-Shirts,Red T-Shirt,5.00,1.33,500 +##alter existing with one collateral +soda,soda-sweet,Sweet Soda-bottled in Oregon,Sweet Soda,1.00,0.85,500 +##add a new one +classical-records-1,track-16,The Marriage of Figaro,Track 16,3.25,0.00,50 diff --git a/t/supporting_collateral/productTables/thirdProductTable.csv b/t/supporting_collateral/productTables/thirdProductTable.csv new file mode 100644 index 000000000..e7d0a51fc --- /dev/null +++ b/t/supporting_collateral/productTables/thirdProductTable.csv @@ -0,0 +1,5 @@ +mastersku,sku,title,shortdescription,price,weight,quantity +##alter a title +soda,soda-sweet,Sweet Soda-totally organic,Sweet Soda,1.00,0.85,500 +##add new collateral to an existing product +classical-records-1,track-9,The Marriage of Figaro,Track 9,3.25,0.00,55