Added the export method.

Basic tests for the export method.  Need to check the CSV file
to make sure it's created correctly.
This commit is contained in:
Colin Kuskie 2008-02-16 17:11:10 +00:00
parent c3e9e5f5c3
commit 6415b9186f
2 changed files with 41 additions and 1 deletions

View file

@ -4,6 +4,8 @@ use strict;
use Class::InsideOut qw{ :std };
use Carp qw(croak);
use WebGUI::Text;
use WebGUI::Storage;
=head1 NAME
@ -102,6 +104,30 @@ sub delete {
#-------------------------------------------------------------------
=head2 export ( )
Creates a tab deliniated file containing all the information from
the tax table. Returns a temporary WebGUI::Storage object containing
the file. The file will be named "siteTaxData.csv".
=cut
sub export {
my $self = shift;
my $taxIterator = $self->getItems;
my @columns = qw{ field value taxRate };
my $taxData = WebGUI::Text::joinCSV(@columns) . "\n";
while (my $taxRow = $taxIterator->hashRef() ) {
my @taxData = @{ $taxRow }{@columns};
$taxData .= WebGUI::Text::joinCSV(@taxData) . "\n";
}
my $storage = WebGUI::Storage->createTemp($self->session);
$storage->addFileFromScalar('siteTaxData.csv', $taxData);
return $storage;
}
#-------------------------------------------------------------------
=head2 getItems ( )
Returns a WebGUI::SQL::Result object for accessing all of the data in the tax table. This

View file

@ -28,7 +28,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 24;
my $tests = 27;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -36,6 +36,8 @@ plan tests => 1 + $tests;
my $loaded = use_ok('WebGUI::Shop::Tax');
my $storage;
SKIP: {
skip 'Unable to load module WebGUI::Shop::Tax', $tests unless $loaded;
@ -188,6 +190,17 @@ $taxIterator = $taxer->getItems;
is($taxIterator->rows, 1, 'No rows were deleted from the table since the requested id does not exist');
is($taxIterator->hashRef->{taxId}, $wisconsinTaxId, 'The correct tax information was deleted');
#######################################################################
#
# export
#
#######################################################################
$storage = $taxer->export();
isa_ok($storage, 'WebGUI::Storage', 'export returns a WebGUI::Storage object');
is($storage->{_part1}, 'temp', 'The storage object is in the temporary area');
ok(-e $storage->getPath('siteTaxData.csv'), 'siteTaxData.csv file exists in the storage object');
}
@ -195,4 +208,5 @@ is($taxIterator->hashRef->{taxId}, $wisconsinTaxId, 'The correct tax information
# Cleanup
END {
$session->db->write('delete from tax');
$storage->delete;
}