From d85d41cefb12f522b0e871133c8477698710e739 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 2 Oct 2018 12:34:25 -0300 Subject: [PATCH] Bug 21474: Add the Koha::Subscription->frequency method And the 2 modules for the subscriptions' frequencies Test plan: prove t/db_dependent/Koha/Subscription.t must return green Signed-off-by: Josef Moravec https://bugs.koha-community.org/show_bug.cgi?id=21467 --- Koha/Subscription.pm | 15 ++++++++++++ Koha/Subscription/Frequencies.pm | 50 ++++++++++++++++++++++++++++++++++++++ Koha/Subscription/Frequency.pm | 44 +++++++++++++++++++++++++++++++++ t/db_dependent/Koha/Subscription.t | 15 +++++++++++- 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 Koha/Subscription/Frequencies.pm create mode 100644 Koha/Subscription/Frequency.pm diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 512e018..27d926d 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -24,6 +24,7 @@ use Carp; use Koha::Database; use Koha::Biblios; use Koha::Acquisition::Booksellers; +use Koha::Subscription::Frequencies; use base qw(Koha::Object); @@ -106,6 +107,20 @@ sub remove_subscriber { $subscriber->delete if $subscriber; } +=head3 frequency + +my $frequency = $subscription->frequency + +Return the subscription frequency + +=cut + +sub frequency { + my($self)=@_; + my $frequency_rs= $self->_result->periodicity; + return Koha::Subscription::Frequency->_new_from_dbic($frequency_rs); +} + =head3 type =cut diff --git a/Koha/Subscription/Frequencies.pm b/Koha/Subscription/Frequencies.pm new file mode 100644 index 0000000..27489a6 --- /dev/null +++ b/Koha/Subscription/Frequencies.pm @@ -0,0 +1,50 @@ +package Koha::Subscription::Frequencies; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Subscription::Frequency; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Subscription::Frequencies - Koha Subscription Frequency Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +sub object_class { + return 'Koha::Subscription::Frequency'; +} + +1; diff --git a/Koha/Subscription/Frequency.pm b/Koha/Subscription/Frequency.pm new file mode 100644 index 0000000..4450715 --- /dev/null +++ b/Koha/Subscription/Frequency.pm @@ -0,0 +1,44 @@ +package Koha::Subscription::Frequency; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Subscription::Frequency - Koha Subscription Frequency Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +1; diff --git a/t/db_dependent/Koha/Subscription.t b/t/db_dependent/Koha/Subscription.t index a8c1a4c..1218e05 100644 --- a/t/db_dependent/Koha/Subscription.t +++ b/t/db_dependent/Koha/Subscription.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Koha::Subscriptions; use Koha::Biblio; @@ -88,6 +88,19 @@ subtest 'Koha::Subscription->vendor' => sub { is( $object->vendor->id, $subscription->{aqbooksellerid}, 'Koha::Subscription->vendor should return the correct vendor' ); }; +subtest 'Koha::Subscription->frequency' => sub { + plan tests => 2; + my $frequency = $builder->build_object( { class => 'Koha::Subscription::Frequencies' } ); + my $subscription = $builder->build_object( + { + class => 'Koha::Subscriptions', + value => { periodicity => $frequency->id } + } + ); + is( ref($subscription->frequency), 'Koha::Subscription::Frequency', 'Koha::Subscription->frequency should return a Koha::Subscription::Frequency' ); + is( $subscription->frequency->id, $frequency->id, 'Koha::Subscription->frequency should return the correct frequency' ); +}; + $schema->storage->txn_rollback; 1; -- 2.1.4