Bug 26582: Unit tests

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2020-09-30 14:40:36 -03:00 committed by Jonathan Druart
parent cb3753d292
commit bea89005ca
1 changed files with 75 additions and 1 deletions

View File

@ -19,7 +19,9 @@
use Modern::Perl;
use Test::More tests => 10;
use Test::More tests => 12;
use Test::Exception;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -300,3 +302,75 @@ subtest 'orders' => sub {
$schema->storage->txn_rollback;
};
subtest 'closed() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $open_basket = $builder->build_object(
{
class => 'Koha::Acquisition::Baskets',
value => {
closedate => undef
}
}
);
my $closed_basket = $builder->build_object(
{
class => 'Koha::Acquisition::Baskets',
value => {
closedate => \'NOW()'
}
}
);
ok( $closed_basket->closed, 'Closed basket is tested as closed' );
ok( !$open_basket->closed, 'Open basket is tested as open' );
$schema->storage->txn_rollback;
};
subtest 'close() tests' => sub {
plan tests => 3;
$schema->storage->txn_begin;
# Create an open basket
my $basket = $builder->build_object(
{
class => 'Koha::Acquisition::Baskets',
value => {
closedate => undef
}
}
);
for my $status ( qw( new ordered partial complete cancelled ) ) {
$builder->build_object(
{
class => 'Koha::Acquisition::Orders',
value => {
basketno => $basket->id,
orderstatus => $status
}
}
);
}
$basket->close;
ok( $basket->closed, 'Basket is closed' );
my $ordered_orders = $basket->orders->search({ orderstatus => 'ordered' });
is( $ordered_orders->count, 3, 'Only open orders have been marked as ordered' );
throws_ok
{ $basket->close; }
'Koha::Exceptions::Acquisition::Basket::AlreadyClosed',
'Trying to close an already closed basket throws an exception';
$schema->storage->txn_rollback;
};