From a61bd107fa891108e7b367123282cbffdfeabd57 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 29 Sep 2008 23:26:34 +0000 Subject: [PATCH] Add support for the original sku entry in the header. --- lib/WebGUI/Asset/Wobject/Shelf.pm | 1 + t/Asset/Wobject/Shelf.t | 26 ++++++++++++++++++- .../productTables/oldHeaderTable.csv | 4 +++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 t/supporting_collateral/productTables/oldHeaderTable.csv diff --git a/lib/WebGUI/Asset/Wobject/Shelf.pm b/lib/WebGUI/Asset/Wobject/Shelf.pm index 83dd7b82f..22e088667 100644 --- a/lib/WebGUI/Asset/Wobject/Shelf.pm +++ b/lib/WebGUI/Asset/Wobject/Shelf.pm @@ -159,6 +159,7 @@ sub importProducts { $headers = <$table>; chomp $headers; $headers =~ tr/\r//d; + $headers =~ s/\bsku\b/varSku/; my @headers = WebGUI::Text::splitCSV($headers); WebGUI::Error::InvalidFile->throw(error => qq{Bad header found in the CSV file}, brokenFile => $filePath) unless (join(q{-}, sort @headers) eq 'mastersku-price-quantity-shortdescription-title-varSku-weight') diff --git a/t/Asset/Wobject/Shelf.t b/t/Asset/Wobject/Shelf.t index 4b8d66f42..763449a0e 100644 --- a/t/Asset/Wobject/Shelf.t +++ b/t/Asset/Wobject/Shelf.t @@ -33,7 +33,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 48; +my $tests = 51; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -415,6 +415,30 @@ SKIP: { is($shelf2->getChildCount, 2, 'imported 2 children skus for shelf2 with windows line endings fields'); $shelf2->purge; + undef $shelf2; + + ####################################################################### + # + # import, old sku column header + # + ####################################################################### + + $shelf2 = WebGUI::Asset->getRoot($session)->addChild({className => $class}); + + $pass = 0; + eval { + $pass = $shelf2->importProducts( + WebGUI::Test->getTestCollateralPath('productTables/windowsTable.csv'), + ); + }; + ok($pass, 'Able to load a table with old style, sku instead of varSku'); + $e = Exception::Class->caught(); + is($e, '', 'No exception thrown on a file old headers'); + is($shelf2->getChildCount, 2, 'imported 2 children skus for shelf2 with old headers'); + + $shelf2->purge; + undef $shelf2; + } #---------------------------------------------------------------------------- diff --git a/t/supporting_collateral/productTables/oldHeaderTable.csv b/t/supporting_collateral/productTables/oldHeaderTable.csv new file mode 100644 index 000000000..8dcb05796 --- /dev/null +++ b/t/supporting_collateral/productTables/oldHeaderTable.csv @@ -0,0 +1,4 @@ +mastersku,sku,title,shortdescription,price,weight,quantity +Software,Windows-Vista,Windows Vista,Bad software,120,5.00,5000 +Software,Windows-XP,Windows XP,Mainly bad software,80,4.50,2000 +Hardware,X-box,X-box,Very expensive hardware,280,10,150