@@ -, +, @@ --- t/db_dependent/Koha/Patrons.t | 47 ++++++++++++++++- t/db_dependent/Koha/Subscription/Routinglists.t | 69 +++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 t/db_dependent/Koha/Subscription/Routinglists.t --- a/t/db_dependent/Koha/Patrons.t +++ a/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 25; +use Test::More tests => 26; use Test::Warn; use Time::Fake; use DateTime; @@ -518,6 +518,51 @@ subtest 'checkouts + get_overdues + old_checkouts' => sub { $module->unmock('userenv'); }; +subtest 'get_routinglists' => sub { + plan tests => 5; + + my $biblio = Koha::Biblio->new()->store(); + my $subscription = Koha::Subscription->new({ + biblionumber => $biblio->biblionumber, + } + )->store; + + my $patron = $builder->build( { source => 'Borrower' } ); + $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + + is( $patron->get_routinglists, 0, 'Retrieves correct number of routing lists: 0' ); + + my $routinglist_count = Koha::Subscription::Routinglists->count; + my $routinglist = Koha::Subscription::Routinglist->new({ + borrowernumber => $patron->borrowernumber, + ranking => 5, + subscriptionid => $subscription->subscriptionid + })->store; + + is ($patron->get_routinglists, 1, "Retrieves correct number of routing lists: 1"); + + my @routinglists = $patron->get_routinglists; + is ($routinglists[0]->ranking, 5, "Retrieves ranking: 5"); + is( ref($routinglists[0]), 'Koha::Subscription::Routinglist', 'get_routinglists returns Koha::Subscription::Routinglist objects' ); + + my $subscription2 = Koha::Subscription->new({ + biblionumber => $biblio->biblionumber, + } + )->store; + my $routinglist2 = Koha::Subscription::Routinglist->new({ + borrowernumber => $patron->borrowernumber, + ranking => 1, + subscriptionid => $subscription2->subscriptionid + })->store; + + is ($patron->get_routinglists, 2, "Retrieves correct number of routing lists: 2"); + + + + $patron->delete; # Clean up for later tests + +}; + subtest 'get_age' => sub { plan tests => 7; --- a/t/db_dependent/Koha/Subscription/Routinglists.t +++ a/t/db_dependent/Koha/Subscription/Routinglists.t @@ -0,0 +1,69 @@ +#!/usr/bin/perl + +# 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 +# WIT HOUT 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 vcshould have received a copy of the GNU General Public License +# al ong with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 1; +use t::lib::TestBuilder; + +use C4::Biblio; + +use Koha::Database; +use Koha::Patrons; +use Koha::Subscriptions; +use Koha::Subscription::Routinglists; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $biblio = Koha::Biblio->new()->store(); +my $subscription = Koha::Subscription->new({ + biblionumber => $biblio->biblionumber, + } +)->store; + +my $builder = t::lib::TestBuilder->new; +my $library = $builder->build({source => 'Branch' }); +my $category = $builder->build({source => 'Category' }); + +my $patron = $builder->build( { source => 'Borrower' } ); +$patron = Koha::Patrons->find( $patron->{borrowernumber} ); + +subtest 'new() tests' => sub { + plan tests => 4; + + my $routinglist_count = Koha::Subscription::Routinglists->count; + my $routinglist = Koha::Subscription::Routinglist->new({ + borrowernumber => $patron->borrowernumber, + ranking => 1, + subscriptionid => $subscription->subscriptionid + })->store; + + is( Koha::Subscription::Routinglists->search->count, $routinglist_count +1, 'One routing list added' ); + + my $retrieved_routinglist = Koha::Subscription::Routinglists->find( $routinglist->routingid ); + is ( $retrieved_routinglist->routingid, $routinglist->routingid, "Find a routing list by id returns the correct routing list"); + + $routinglist->ranking(4)->update; + is ( $routinglist->ranking, 4, "Routing list ranking has been updated"); + + $routinglist->delete; + is ( Koha::Subscription::Routinglists->search->count, $routinglist_count, 'One subscription list deleted' ); + +}; + +$schema->storage->txn_rollback; --