From 5651755e68a7c41d1646fa06e1d96b7bf32de5da Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 13 Mar 2017 15:27:06 -0300 Subject: [PATCH] Bug 18258: Add the Koha::Biblio->subscriptions method MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Test plan: prove t/db_dependent/Koha/Biblios.t should return green Signed-off-by: Marc Véron Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- Koha/Biblio.pm | 17 +++++++++++++++++ t/db_dependent/Koha/Biblios.t | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index d5ca37045b..a296cd597a 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -280,6 +280,23 @@ sub biblioitem { return $self->{_biblioitem}; } +=head3 subscriptions + +my $subscriptions = $self->subscriptions + +Returns the related Koha::Subscriptions object for this Biblio object + +=cut + +sub subscriptions { + my ($self) = @_; + + $self->{_subscriptions} ||= Koha::Subscriptions->search( { biblionumber => $self->biblionumber } ); + + return $self->{_subscriptions}; +} + + =head3 type =cut diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t index 2498b869fb..e16868f5bc 100644 --- a/t/db_dependent/Koha/Biblios.t +++ b/t/db_dependent/Koha/Biblios.t @@ -19,12 +19,13 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use C4::Reserves; use Koha::Biblios; use Koha::Patrons; +use Koha::Subscriptions; use t::lib::TestBuilder; use t::lib::Mocks; @@ -52,6 +53,22 @@ subtest 'holds' => sub { is( $holds->next->borrowernumber, $patron->borrowernumber, '->holds should return the correct hold' ); }; +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'); +}; + $schema->storage->txn_rollback; 1; -- 2.39.5