Bugzilla – Attachment 58479 Details for
Bug 17569
Move GetUpcomingMembershipExpires to Koha::Patrons
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17569: Move tests to the patron module test file
Bug-17569-Move-tests-to-the-patron-module-test-fil.patch (text/plain), 9.39 KB, created by
Jonathan Druart
on 2016-12-29 09:32:20 UTC
(
hide
)
Description:
Bug 17569: Move tests to the patron module test file
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-12-29 09:32:20 UTC
Size:
9.39 KB
patch
obsolete
>From 1a50c3e2710b7f89209d19a83259fe844079f8fb Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 7 Nov 2016 15:34:32 +0100 >Subject: [PATCH] Bug 17569: Move tests to the patron module test file > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/db_dependent/Koha/Patrons.t | 76 ++++++++++++++- > .../Members/GetUpcomingMembershipExpires.t | 103 --------------------- > 2 files changed, 75 insertions(+), 104 deletions(-) > delete mode 100644 t/db_dependent/Members/GetUpcomingMembershipExpires.t > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 82b6b33..51a4785 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 => 18; >+use Test::More tests => 19; > use Test::Warn; > use DateTime; > >@@ -522,6 +522,80 @@ subtest 'account' => sub { > $patron->delete; > }; > >+subtest 'search_upcoming_membership_expires' => sub { >+ plan tests => 9; >+ >+ my $expiry_days = 15; >+ t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', $expiry_days ); >+ my $nb_of_days_before = 1; >+ my $nb_of_days_after = 2; >+ >+ my $builder = t::lib::TestBuilder->new(); >+ >+ my $library = $builder->build({ source => 'Branch' }); >+ >+ # before we add borrowers to this branch, add the expires we have now >+ # note that this pertains to the current mocked setting of the pref >+ # for this reason we add the new branchcode to most of the tests >+ my $nb_of_expires = Koha::Patrons->search_upcoming_membership_expires->count; >+ >+ my $patron_1 = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $library->{branchcode}, >+ dateexpiry => dt_from_string->add( days => $expiry_days ) >+ }, >+ }); >+ >+ my $patron_2 = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $library->{branchcode}, >+ dateexpiry => dt_from_string->add( days => $expiry_days - $nb_of_days_before ) >+ }, >+ }); >+ >+ my $patron_3 = $builder->build({ >+ source => 'Borrower', >+ value => { >+ branchcode => $library->{branchcode}, >+ dateexpiry => dt_from_string->add( days => $expiry_days + $nb_of_days_after ) >+ }, >+ }); >+ >+ # Test without extra parameters >+ my $upcoming_mem_expires = Koha::Patrons->search_upcoming_membership_expires(); >+ is( $upcoming_mem_expires->count, $nb_of_expires + 1, 'Get upcoming membership expires should return one new borrower.' ); >+ >+ # Test with branch >+ $upcoming_mem_expires = Koha::Patrons->search_upcoming_membership_expires({ 'me.branchcode' => $library->{branchcode} }); >+ is( $upcoming_mem_expires->count, 1, ); >+ my $expired = $upcoming_mem_expires->next; >+ is( $expired->surname, $patron_1->{surname}, 'Get upcoming membership expires should return the correct patron.' ); >+ is( $expired->library->branchemail, $library->{branchemail}, 'Get upcoming membership expires should return the correct patron.' ); >+ is( $expired->branchcode, $patron_1->{branchcode}, 'Get upcoming membership expires should return the correct patron.' ); >+ >+ t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 0 ); >+ $upcoming_mem_expires = Koha::Patrons->search_upcoming_membership_expires({ 'me.branchcode' => $library->{branchcode} }); >+ is( $upcoming_mem_expires->count, 0, 'Get upcoming membership expires with MembershipExpiryDaysNotice==0 should not return new records.' ); >+ >+ # Test MembershipExpiryDaysNotice == undef >+ t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', undef ); >+ $upcoming_mem_expires = Koha::Patrons->search_upcoming_membership_expires({ 'me.branchcode' => $library->{branchcode} }); >+ is( $upcoming_mem_expires->count, 0, 'Get upcoming membership expires without MembershipExpiryDaysNotice should not return new records.' ); >+ >+ # Test the before parameter >+ t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 15 ); >+ $upcoming_mem_expires = Koha::Patrons->search_upcoming_membership_expires({ 'me.branchcode' => $library->{branchcode}, before => $nb_of_days_before }); >+ # Expect 29/6 and 30/6 >+ is( $upcoming_mem_expires->count, 2, 'Expect two results for before==1'); >+ # Test after parameter also >+ $upcoming_mem_expires = Koha::Patrons->search_upcoming_membership_expires({ 'me.branchcode' => $library->{branchcode}, before => $nb_of_days_before, after => $nb_of_days_after }); >+ # Expect 29/6, 30/6 and 2/7 >+ is( $upcoming_mem_expires->count, 3, 'Expect three results when adding after' ); >+ Koha::Patrons->search({ borrowernumber => { in => [ $patron_1->{borrowernumber}, $patron_2->{borrowernumber}, $patron_3->{borrowernumber} ] } })->delete; >+}; >+ > $retrieved_patron_1->delete; > is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); > >diff --git a/t/db_dependent/Members/GetUpcomingMembershipExpires.t b/t/db_dependent/Members/GetUpcomingMembershipExpires.t >deleted file mode 100644 >index 106f565..0000000 >--- a/t/db_dependent/Members/GetUpcomingMembershipExpires.t >+++ /dev/null >@@ -1,103 +0,0 @@ >-#!/usr/bin/perl >- >-# Tests for C4::Members::GetUpcomingMembershipExpires >- >-# This file is part of Koha. >-# >-# Copyright 2015 Biblibre >-# >-# 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, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::MockModule; >-use Test::More tests => 6; >- >-use C4::Members qw|GetUpcomingMembershipExpires|; >-use Koha::Database; >-use Koha::DateUtils; >-use t::lib::TestBuilder; >-use t::lib::Mocks qw( mock_preference ); >- >-my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >- >-my $expiry_days = 15; >-t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', $expiry_days ); >-my $nb_of_days_before = 1; >-my $nb_of_days_after = 2; >- >-my $builder = t::lib::TestBuilder->new(); >- >-my $library = $builder->build({ source => 'Branch' }); >- >-# before we add borrowers to this branch, add the expires we have now >-# note that this pertains to the current mocked setting of the pref >-# for this reason we add the new branchcode to most of the tests >-my $expires = scalar @{ GetUpcomingMembershipExpires() }; >- >-my $patron_1 = $builder->build({ >- source => 'Borrower', >- value => { >- branchcode => $library->{branchcode}, >- dateexpiry => dt_from_string->add( days => $expiry_days ) >- }, >-}); >- >-my $patron_2 = $builder->build({ >- source => 'Borrower', >- value => { >- branchcode => $library->{branchcode}, >- dateexpiry => dt_from_string->add( days => $expiry_days - $nb_of_days_before ) >- }, >-}); >- >-my $patron_3 = $builder->build({ >- source => 'Borrower', >- value => { >- branchcode => $library->{branchcode}, >- dateexpiry => dt_from_string->add( days => $expiry_days + $nb_of_days_after ) >- }, >-}); >- >-# Test without extra parameters >-my $upcoming_mem_expires = GetUpcomingMembershipExpires(); >-is( scalar(@$upcoming_mem_expires), $expires + 1, 'Get upcoming membership expires should return one new borrower.' ); >- >-# Test with branch >-$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode} }); >-is( @$upcoming_mem_expires==1 && $upcoming_mem_expires->[0]{surname} eq $patron_1->{surname},1 , 'Get upcoming membership expires should return the correct patron.' ); >- >-# Test MembershipExpiryDaysNotice == 0 >-t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 0 ); >-$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode} }); >-is( scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires with MembershipExpiryDaysNotice==0 should not return new records.' ); >- >-# Test MembershipExpiryDaysNotice == undef >-t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', undef ); >-$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode} }); >-is( scalar(@$upcoming_mem_expires), 0, 'Get upcoming membership expires without MembershipExpiryDaysNotice should not return new records.' ); >- >-# Test the before parameter >-t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 15 ); >-$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode}, before => $nb_of_days_before }); >-# Expect 29/6 and 30/6 >-is( scalar(@$upcoming_mem_expires), 2, 'Expect two results for before==1'); >-# Test after parameter also >-$upcoming_mem_expires = GetUpcomingMembershipExpires({ branch => $library->{branchcode}, before => $nb_of_days_before, after => $nb_of_days_after }); >-# Expect 29/6, 30/6 and 2/7 >-is( scalar(@$upcoming_mem_expires), 3, 'Expect three results when adding after' ); >- >-# End >-$schema->storage->txn_rollback; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17569
:
57265
|
57266
|
57267
|
57294
|
57295
|
57315
|
57316
|
57317
|
57318
|
57319
|
57894
|
57895
|
57896
|
57897
|
57898
|
57908
|
57909
|
57910
|
57911
|
57912
|
57913
|
58478
| 58479 |
58480
|
58481
|
58482
|
58483