add more export products tests, along with several bug fixes
This commit is contained in:
parent
47921b969c
commit
090e4c7adf
2 changed files with 10 additions and 4 deletions
|
|
@ -39,16 +39,17 @@ file will be named siteProductData.csv.
|
||||||
|
|
||||||
sub exportProducts {
|
sub exportProducts {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my @columns = qw{sku title shortdescription price weight quantity};
|
my @columns = qw{sku shortdescription price weight quantity};
|
||||||
my $productData = WebGUI::Text::joinCSV('mastersku', @columns) . "\n";
|
my $productData = WebGUI::Text::joinCSV(qw{mastersku title}, @columns) . "\n";
|
||||||
@columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns;
|
@columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns;
|
||||||
my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session);
|
my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session);
|
||||||
while (my $product = $getAProduct->()) {
|
while (my $product = $getAProduct->()) {
|
||||||
my $mastersku = $product->get('sku');
|
my $mastersku = $product->get('sku');
|
||||||
|
my $title = $product->getTitle;
|
||||||
my $collateri = $product->getAllCollateral('variantsJSON');
|
my $collateri = $product->getAllCollateral('variantsJSON');
|
||||||
foreach my $collateral (@{ $collateri }) {
|
foreach my $collateral (@{ $collateri }) {
|
||||||
my @productFields = @{ $collateral }{ @columns };
|
my @productFields = @{ $collateral }{ @columns };
|
||||||
$productData .= WebGUI::Text::joinCSV($mastersku, @productFields);
|
$productData .= WebGUI::Text::joinCSV($mastersku, $title, @productFields);
|
||||||
$productData .= "\n";
|
$productData .= "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 25;
|
my $tests = 27;
|
||||||
plan tests => 1 + $tests;
|
plan tests => 1 + $tests;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -199,6 +199,11 @@ SKIP: {
|
||||||
isa_ok($products, 'WebGUI::Storage', 'exportProducts returns a Storage object');
|
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 }, 1, 'The storage contains just 1 file...');
|
||||||
is(scalar $products->getFiles->[0], 'siteProductData.csv', '...with the correct filename');
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue