add more export products tests, along with several bug fixes

This commit is contained in:
Colin Kuskie 2008-06-06 23:11:38 +00:00
parent 47921b969c
commit 090e4c7adf
2 changed files with 10 additions and 4 deletions

View file

@ -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";
}
}

View file

@ -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;
}