More Vendor POD and tests. new and created are both basically tested.
This commit is contained in:
parent
dfefa8d871
commit
75cf3923ad
2 changed files with 85 additions and 5 deletions
|
|
@ -81,6 +81,16 @@ Returns a duplicated hash reference of this object
|
|||
|
||||
Any field returns the value of a field rather than the hash reference.
|
||||
|
||||
=head3 Additional properties
|
||||
|
||||
=head4 dateCreated
|
||||
|
||||
The date this vendor was created in the system.
|
||||
|
||||
=head4 vendorId
|
||||
|
||||
The id of this vendor from the database. Use getId() instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
|
|
@ -237,11 +247,11 @@ The vendor's url.
|
|||
|
||||
=head4 paymentInformation
|
||||
|
||||
The name of the vendor.
|
||||
????
|
||||
|
||||
=head4 preferredPaymentType
|
||||
|
||||
The name of the vendor.
|
||||
????
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 2;
|
||||
my $tests = 17;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -40,6 +40,8 @@ plan tests => 1 + $tests;
|
|||
my $loaded = use_ok('WebGUI::Shop::Vendor');
|
||||
|
||||
my $vendor;
|
||||
my $fence;
|
||||
my $fenceUser = WebGUI::User->new($session, 'new');
|
||||
|
||||
SKIP: {
|
||||
|
||||
|
|
@ -59,16 +61,84 @@ isa_ok($e, 'WebGUI::Error::InvalidObject', 'new takes an exception to not giving
|
|||
cmp_deeply(
|
||||
$e,
|
||||
methods(
|
||||
error => 'Need a session.',
|
||||
got => '',
|
||||
error => 'Need a session.',
|
||||
got => '',
|
||||
expected => 'WebGUI::Session',
|
||||
),
|
||||
'new: requires a session variable',
|
||||
);
|
||||
|
||||
eval { $vendor = WebGUI::Shop::Vendor->new($session); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes an exception to not giving it a vendor id to instanciate');
|
||||
cmp_deeply(
|
||||
$e,
|
||||
methods(
|
||||
error => 'Need a vendorId.',
|
||||
param => undef,
|
||||
),
|
||||
'new: requires a vendorId',
|
||||
);
|
||||
|
||||
eval { $vendor = WebGUI::Shop::Vendor->new($session, 'notAVendorId'); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok($e, 'WebGUI::Error::ObjectNotFound', 'new takes an exception to not giving it a vendor id that is not in the db');
|
||||
cmp_deeply(
|
||||
$e,
|
||||
methods(
|
||||
error => 'Vendor not found.',
|
||||
id => 'notAVendorId',
|
||||
),
|
||||
'new: requires a valid vendorId',
|
||||
);
|
||||
|
||||
eval { $vendor = WebGUI::Shop::Vendor->new($session, 'defaultvendor000000000'); };
|
||||
$e = Exception::Class->caught();
|
||||
ok(!$e, 'No exception thrown');
|
||||
isa_ok($vendor, 'WebGUI::Shop::Vendor', 'new returns correct type of object');
|
||||
|
||||
isa_ok($vendor->session, 'WebGUI::Session', 'session method returns a session object');
|
||||
|
||||
is($session->getId, $vendor->session->getId, 'session method returns OUR session object');
|
||||
|
||||
is($vendor->getId, 'defaultvendor000000000', 'new returned the correct vendor');
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# create
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
eval { $fence = WebGUI::Shop::Vendor->create(); };
|
||||
$e = Exception::Class->caught();
|
||||
isa_ok($e, 'WebGUI::Error::InvalidObject', 'new takes an exception to not giving it a session variable');
|
||||
cmp_deeply(
|
||||
$e,
|
||||
methods(
|
||||
error => 'Need a session.',
|
||||
got => '',
|
||||
expected => 'WebGUI::Session',
|
||||
),
|
||||
'create: requires a session variable',
|
||||
);
|
||||
|
||||
my $now = WebGUI::DateTime->new($session, time);
|
||||
|
||||
eval { $fence = WebGUI::Shop::Vendor->create($session, { userId => $fenceUser->userId, }); };
|
||||
$e = Exception::Class->caught();
|
||||
ok(!$e, 'No exception thrown by create');
|
||||
isa_ok($vendor, 'WebGUI::Shop::Vendor', 'create returns correct type of object');
|
||||
|
||||
ok($fence->get('dateCreated'), 'dateCreated is not null');
|
||||
my $dateCreated = WebGUI::DateTime->new($session, $fence->get('dateCreated'));
|
||||
my $deltaDC = $dateCreated - $now;
|
||||
cmp_ok( $deltaDC->seconds, '<=', 2, 'dateCreated is set properly');
|
||||
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$fence->delete;
|
||||
$fenceUser->delete;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue