From 948f33def9fdeba136c58f630fee39a06048d635 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Apr 2018 18:12:50 -0300 Subject: [PATCH] Bug 20599: Add the Koha::Subscription->vendor method Test plan: prove t/db_dependent/Koha/Subscription.t must return green NOTE: My preference is for $subscription to be object, and perhaps something like $built_subscription to be from the builder. Because, $object is a poor variable name. Signed-off-by: Mark Tompsett --- Koha/Subscription.pm | 12 ++++++++++++ t/db_dependent/Koha/Subscription.t | 24 +++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 2a793e5..d585ba8 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -23,6 +23,7 @@ use Carp; use Koha::Database; use Koha::Biblios; +use Koha::Acquisition::Booksellers; use base qw(Koha::Object); @@ -48,6 +49,17 @@ sub biblio { return scalar Koha::Biblios->find($self->biblionumber); } +=head3 vendor + +Returns the vendor/supplier linked to this subscription as a Koha::Acquisition::Bookseller object + +=cut + +sub vendor { + my ($self) = @_; + return scalar Koha::Acquisition::Booksellers->find($self->aqbooksellerid); +} + =head3 type =cut diff --git a/t/db_dependent/Koha/Subscription.t b/t/db_dependent/Koha/Subscription.t index 46256d3..81c5563 100644 --- a/t/db_dependent/Koha/Subscription.t +++ b/t/db_dependent/Koha/Subscription.t @@ -19,15 +19,19 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; -use Koha::Subscription; +use Koha::Subscriptions; use Koha::Biblio; +use t::lib::TestBuilder; + my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; -subtest 'Koha::Subscription::biblio' => sub { +my $builder = t::lib::TestBuilder->new; + +subtest 'Koha::Subscription->biblio' => sub { plan tests => 1; my $biblio = Koha::Biblio->new()->store(); @@ -39,6 +43,20 @@ subtest 'Koha::Subscription::biblio' => sub { is($b->biblionumber, $biblio->biblionumber, 'Koha::Subscription::biblio returns the correct biblio'); }; +subtest 'Koha::Subscription->vendor' => sub { + plan tests => 2; + my $vendor = $builder->build( { source => 'Aqbookseller' } ); + my $subscription = $builder->build( + { + source => 'Subscription', + value => { aqbooksellerid => $vendor->{id} } + } + ); + my $object = Koha::Subscriptions->find( $subscription->{subscriptionid} ); + is( ref($object->vendor), 'Koha::Acquisition::Bookseller', 'Koha::Subscription->vendor should return a Koha::Acquisition::Bookseller' ); + is( $object->vendor->id, $subscription->{aqbooksellerid}, 'Koha::Subscription->vendor should return the correct vendor' ); +}; + $schema->storage->txn_rollback; 1; -- 2.1.4