From fb0079536ba9bc7be6e4278361214ac7af6eea2b Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Sat, 17 Mar 2018 21:25:35 +0100 Subject: [PATCH] Bug 20400: Add unit tests prove t/db_dependent/Koha/Subscription/Routinglists.t prove t/db_dependent/Koha/Patrons.t --- t/db_dependent/Koha/Patrons.t | 45 ++++++++++++++++- t/db_dependent/Koha/Subscription/Routinglists.t | 67 +++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 t/db_dependent/Koha/Subscription/Routinglists.t diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 0b6e122703..ea57389b80 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 29; +use Test::More tests => 30; use Test::Warn; use Time::Fake; use DateTime; @@ -529,6 +529,49 @@ subtest 'checkouts + pending_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; diff --git a/t/db_dependent/Koha/Subscription/Routinglists.t b/t/db_dependent/Koha/Subscription/Routinglists.t new file mode 100644 index 0000000000..01dc77698d --- /dev/null +++ b/t/db_dependent/Koha/Subscription/Routinglists.t @@ -0,0 +1,67 @@ +#!/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; +my $builder = t::lib::TestBuilder->new; + +subtest 'new() tests' => sub { + plan tests => 4; + + $schema->storage->txn_begin; + + my $biblio = Koha::Biblio->new()->store(); + my $subscription = Koha::Subscription->new({ + biblionumber => $biblio->biblionumber, + } + )->store; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->id } }); + + 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; -- 2.14.1