From fc128aea70cc936fd6ee8cdb33baa4be332a7036 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 30 Sep 2020 14:40:36 -0300 Subject: [PATCH] Bug 26582: Unit tests Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- t/db_dependent/Koha/Acquisition/Basket.t | 76 +++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Acquisition/Basket.t b/t/db_dependent/Koha/Acquisition/Basket.t index cd2e09d3f0..0570e244d4 100755 --- a/t/db_dependent/Koha/Acquisition/Basket.t +++ b/t/db_dependent/Koha/Acquisition/Basket.t @@ -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; +}; -- 2.11.0