From f06578b34e9a31ff9b2ee3575b3770a88fccdece Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 15 Jan 2020 16:25:19 -0300 Subject: [PATCH] Bug 24430: Unit tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Biblio.t | 49 +++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index e3a41399bb..03ddbef7ff 100644 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,10 +17,11 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use C4::Biblio; use Koha::Database; +use Koha::Acquisition::Orders; use t::lib::TestBuilder; use t::lib::Mocks; @@ -490,3 +491,49 @@ subtest 'suggestions() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'orders() and active_orders_count() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio(); + + my $orders = $biblio->orders; + my $active_orders_count = $biblio->active_orders_count; + + is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' ); + is( $orders->count, $active_orders_count, '->orders_count returns the count for the resultset' ); + + # Add a couple orders + foreach (1..2) { + $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + biblionumber => $biblio->biblionumber, + datecancellationprinted => '2019-12-31' + } + } + ); + } + + $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + biblionumber => $biblio->biblionumber, + datecancellationprinted => undef + } + } + ); + + $orders = $biblio->orders; + $active_orders_count = $biblio->active_orders_count; + + is( ref($orders), 'Koha::Acquisition::Orders', 'Result type is correct' ); + is( $orders->count, $active_orders_count + 2, '->active_orders_count returns the rigt count' ); + + $schema->storage->txn_rollback; +}; -- 2.20.1