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> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
da064f1387
commit
c1e62ceaf7
2 changed files with 75 additions and 104 deletions
|
@ -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' );
|
||||
|
||||
|
|
|
@ -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;
|
Loading…
Reference in a new issue