diff --git a/lib/WebGUI/Shop/Ship.pm b/lib/WebGUI/Shop/Ship.pm index a9fc76743..8d058c1de 100644 --- a/lib/WebGUI/Shop/Ship.pm +++ b/lib/WebGUI/Shop/Ship.pm @@ -127,6 +127,14 @@ sub getShippers { my $session = shift; WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable}) unless ref $session eq 'WebGUI::Session'; + my $drivers; + my $sth = $session->db->prepare('select shipperId from shipper'); + $sth->execute(); + while (my $driver = $sth->hashRef()) { + push @{ $drivers }, WebGUI::Shop::Ship->new($session, $driver->{shipperId}); + } + $sth->finish; + return $drivers; } #------------------------------------------------------------------- diff --git a/t/Shop/Ship.t b/t/Shop/Ship.t index 02cf18f7d..6ea90c626 100644 --- a/t/Shop/Ship.t +++ b/t/Shop/Ship.t @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 25; +my $tests = 27; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -195,6 +195,7 @@ cmp_deeply($driverCopy->options, $driver->options, 'same options'); ####################################################################### my $shippers; +my $driver2 = WebGUI::Shop::Ship->create($session, 'WebGUI::Shop::ShipDriver::FlatRate', { enabled=>1, label=>q{Tommy's cut-rate shipping}}); eval { $shippers = WebGUI::Shop::Ship->getShippers(); }; $e = Exception::Class->caught(); @@ -207,7 +208,16 @@ cmp_deeply( 'getShippers takes exception to not giving it a session object', ); -$shippers = WebGUI::Shop::Ship->getShippers(); + +$shippers = WebGUI::Shop::Ship->getShippers($session); +is(scalar @{$shippers}, 2, 'getShippers: got both shippers'); + +my @shipperNames = map { $_->options()->{label} } @{ $shippers }; +cmp_bag( + \@shipperNames, + [q{Jake's Jailbird Airmail},q{Tommy's cut-rate shipping}], + 'Returned shippers have the right data' +); }