From f20d06c1ef9643fe4c67b387ce8ba00cc05663ef Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 17 Jan 2020 11:17:33 -0300 Subject: [PATCH] Bug 24448: Unit tests This patch adds tests for the new method to be introduced. It also moves the tests for Koha::Biblio->subscriptions to the Biblio.t where it really belongs. To test, run this tests along with the patch implementing the new method. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- t/db_dependent/Koha/Biblio.t | 37 ++++++++++++++++++++++++++++++++++++- t/db_dependent/Koha/Biblios.t | 18 +----------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 59dc5a550d..363a080abf 100644 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 12; use C4::Biblio; use Koha::Database; @@ -541,3 +541,38 @@ subtest 'orders() and active_orders_count() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'subscriptions() and subscriptions_count() tests' => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio; + + my $subscriptions = $biblio->subscriptions; + is( ref($subscriptions), 'Koha::Subscriptions', + 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object' + ); + is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions'); + is( $biblio->subscriptions_count, 0, 'subscriptions_count returns the correct number' ); + + # Add two subscriptions + foreach (1..2) { + $builder->build_object( + { + class => 'Koha::Subscriptions', + value => { biblionumber => $biblio->biblionumber } + } + ); + } + + $subscriptions = $biblio->subscriptions; + is( ref($subscriptions), 'Koha::Subscriptions', + 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object' + ); + is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions'); + is( $biblio->subscriptions_count, 2, 'subscriptions_count returns the correct number' ); + + $schema->storage->txn_rollback; +}; diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t index d44d566924..2d5acbba8f 100644 --- a/t/db_dependent/Koha/Biblios.t +++ b/t/db_dependent/Koha/Biblios.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 5; use Test::Exception; use MARC::Field; @@ -81,22 +81,6 @@ subtest 'holds + current_holds' => sub { }; -subtest 'subscriptions' => sub { - plan tests => 2; - $builder->build( - { source => 'Subscription', value => { biblionumber => $biblio->id } } - ); - $builder->build( - { source => 'Subscription', value => { biblionumber => $biblio->id } } - ); - my $biblio = Koha::Biblios->find( $biblio->id ); - my $subscriptions = $biblio->subscriptions; - is( ref($subscriptions), 'Koha::Subscriptions', - 'Koha::Biblio->subscriptions should return a Koha::Subscriptions object' - ); - is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions'); -}; - subtest 'waiting_or_in_transit' => sub { plan tests => 4; my $biblio = $builder->build( { source => 'Biblio' } ); -- 2.11.0