From 090e4c7adfe0075a3967d77734158ff2f9d26440 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 6 Jun 2008 23:11:38 +0000 Subject: [PATCH] add more export products tests, along with several bug fixes --- lib/WebGUI/Shop/Products.pm | 7 ++++--- t/Shop/Products.t | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/Shop/Products.pm b/lib/WebGUI/Shop/Products.pm index eb3ffb72a..25327394a 100644 --- a/lib/WebGUI/Shop/Products.pm +++ b/lib/WebGUI/Shop/Products.pm @@ -39,16 +39,17 @@ file will be named siteProductData.csv. sub exportProducts { my $session = shift; - my @columns = qw{sku title shortdescription price weight quantity}; - my $productData = WebGUI::Text::joinCSV('mastersku', @columns) . "\n"; + my @columns = qw{sku shortdescription price weight quantity}; + my $productData = WebGUI::Text::joinCSV(qw{mastersku title}, @columns) . "\n"; @columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns; my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session); while (my $product = $getAProduct->()) { my $mastersku = $product->get('sku'); + my $title = $product->getTitle; my $collateri = $product->getAllCollateral('variantsJSON'); foreach my $collateral (@{ $collateri }) { my @productFields = @{ $collateral }{ @columns }; - $productData .= WebGUI::Text::joinCSV($mastersku, @productFields); + $productData .= WebGUI::Text::joinCSV($mastersku, $title, @productFields); $productData .= "\n"; } } diff --git a/t/Shop/Products.t b/t/Shop/Products.t index 1d3005e68..d806a6380 100644 --- a/t/Shop/Products.t +++ b/t/Shop/Products.t @@ -33,7 +33,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 25; +my $tests = 27; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -199,6 +199,11 @@ SKIP: { isa_ok($products, 'WebGUI::Storage', 'exportProducts returns a Storage object'); is(scalar @{ $products->getFiles }, 1, 'The storage contains just 1 file...'); is(scalar $products->getFiles->[0], 'siteProductData.csv', '...with the correct filename'); + my $productData = $products->getFileContentsAsScalar($products->getFiles->[0]); + my @productData = split /\n/, $productData; + is(scalar @productData, 4, 'productData should have 4 entries, 1 header + 3 data'); + is($productData[0], 'mastersku,title,sku,shortdescription,price,weight,quantity', 'header line is okay'); + diag $productData; }