Add coverage tests, convert croaks to exceptions.

This commit is contained in:
Colin Kuskie 2008-03-05 23:34:53 +00:00
parent cd55ff1a9e
commit d27ac7a629
4 changed files with 55 additions and 10 deletions

View file

@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 27;
my $tests = 29;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -220,6 +220,23 @@ cmp_bag(
'Returned shippers have the right data'
);
#######################################################################
#
# getOptions
#
#######################################################################
eval { $shippers = WebGUI::Shop::Ship->getOptions(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'getOptions takes exception to not giving it a session object');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'getOptions takes exception to not giving it a session object',
);
}
#----------------------------------------------------------------------------

View file

@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 39;
my $tests = 42;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -302,10 +302,35 @@ is($driver->getId, $driverCopy->getId, 'same id');
is($driver->className, $driverCopy->className, 'same className');
cmp_deeply($driver->options, $driverCopy->options, 'same options');
TODO: {
local $TODO = 'tests for new';
ok(0, 'Test broken options in the db');
}
my $brokenDriver = WebGUI::Shop::ShipDriver->create($session, {label=>'to be broken', enabled=>'0'});
$session->db->write('update shipper set options=NULL where shipperId=?',[$brokenDriver->getId]);
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, $brokenDriver->getId); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new croaks if the options column in the db is null');
cmp_deeply(
$e,
methods(
error => re('Options property for \S{22} was broken in the db'),
param => undef,
),
'new croaks if the options column in the db is null',
);
$session->db->write(q{update shipper set options='' where shipperId=?},[$brokenDriver->getId]);
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, $brokenDriver->getId); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new croaks if the options column in the db is empty string');
cmp_deeply(
$e,
methods(
error => re('Options property for \S{22} was broken in the db'),
param => '',
),
'new croaks if the options column in the db is empty string',
);
#######################################################################
#