Bugzilla – Attachment 57315 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]
[SIGNED-OFF] Bug 17569: Rewrite existing tests to make them reusable and more robust
SIGNED-OFF-Bug-17569-Rewrite-existing-tests-to-mak.patch (text/plain), 6.35 KB, created by
Josef Moravec
on 2016-11-08 12:38:31 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 17569: Rewrite existing tests to make them reusable and more robust
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-11-08 12:38:31 UTC
Size:
6.35 KB
patch
obsolete
>From 2a3d84777aa46d55a6cdcf0ea0f24917ad2934b5 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 7 Nov 2016 13:18:54 +0000 >Subject: [PATCH] [SIGNED-OFF] Bug 17569: Rewrite existing tests to make them > reusable and more robust > >In order not to cheat you, I am rewriting the tests in a separate >commit. >You can confirm that they pass with the other patches. > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > .../Members/GetUpcomingMembershipExpires.t | 77 +++++++--------------- > 1 file changed, 22 insertions(+), 55 deletions(-) > >diff --git a/t/db_dependent/Members/GetUpcomingMembershipExpires.t b/t/db_dependent/Members/GetUpcomingMembershipExpires.t >index c9f8508..106f565 100644 >--- a/t/db_dependent/Members/GetUpcomingMembershipExpires.t >+++ b/t/db_dependent/Members/GetUpcomingMembershipExpires.t >@@ -26,81 +26,48 @@ 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 $date_time = new Test::MockModule('DateTime'); >-$date_time->mock( >- 'now', sub { >- return DateTime->new( >- year => 2015, >- month => 6, >- day => 15, >- ); >-}); >- >-t::lib::Mocks::mock_preference( 'MembershipExpiryDaysNotice', 15 ); >+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(); >-$builder->build({ >- source => 'Category', >- value => { >- categorycode => 'AD', >- description => 'Adult', >- enrolmentperiod => 18, >- upperagelimit => 99, >- category_type => 'A', >- }, >-}); > >-my $branch = $builder->build({ >- source => 'Branch', >- value => { >- branchname => 'My branch', >- }, >-}); >-my $branchcode = $branch->{branchcode}; >+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() }; > >-$builder->build({ >+my $patron_1 = $builder->build({ > source => 'Borrower', > value => { >- firstname => 'Vincent', >- surname => 'Martin', >- cardnumber => '80808081', >- categorycode => 'AD', >- branchcode => $branchcode, >- dateexpiry => '2015-06-30' >+ branchcode => $library->{branchcode}, >+ dateexpiry => dt_from_string->add( days => $expiry_days ) > }, > }); > >-$builder->build({ >+my $patron_2 = $builder->build({ > source => 'Borrower', > value => { >- firstname => 'Claude', >- surname => 'Dupont', >- cardnumber => '80808082', >- categorycode => 'AD', >- branchcode => $branchcode, >- dateexpiry => '2015-06-29' >+ branchcode => $library->{branchcode}, >+ dateexpiry => dt_from_string->add( days => $expiry_days - $nb_of_days_before ) > }, > }); > >-$builder->build({ >+my $patron_3 = $builder->build({ > source => 'Borrower', > value => { >- firstname => 'Gilles', >- surname => 'Dupond', >- cardnumber => '80808083', >- categorycode => 'AD', >- branchcode => $branchcode, >- dateexpiry => '2015-07-02' >+ branchcode => $library->{branchcode}, >+ dateexpiry => dt_from_string->add( days => $expiry_days + $nb_of_days_after ) > }, > }); > >@@ -109,26 +76,26 @@ 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 => $branchcode }); >-is( @$upcoming_mem_expires==1 && $upcoming_mem_expires->[0]{surname} eq 'Martin',1 , 'Get upcoming membership expires should return borrower "Martin".' ); >+$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 => $branchcode }); >+$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 => $branchcode }); >+$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 => $branchcode, before => 1 }); >+$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 => $branchcode, before => 1, after => 2 }); >+$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' ); > >-- >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