@@ -, +, @@ prove t/db_dependent/Koha/Biblios.t --- Koha/Biblio.pm | 17 +++++++++++++++++ t/db_dependent/Koha/Biblios.t | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) --- a/Koha/Biblio.pm +++ a/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 --- a/t/db_dependent/Koha/Biblios.t +++ a/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; --