diff --git a/lib/WebGUI/Shop/Tax.pm b/lib/WebGUI/Shop/Tax.pm index 020922305..1592fe91c 100644 --- a/lib/WebGUI/Shop/Tax.pm +++ b/lib/WebGUI/Shop/Tax.pm @@ -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 diff --git a/t/Shop/Tax.t b/t/Shop/Tax.t index f351b0f81..7326eed1b 100644 --- a/t/Shop/Tax.t +++ b/t/Shop/Tax.t @@ -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; }