Bugzilla – Attachment 143760 Details for
Bug 31095
Remove Koha::Patron::Debarment::GetDebarments and use $patron->restrictions in preference
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31095: Remove GetDebarments from Borrower_Debarments.t
Bug-31095-Remove-GetDebarments-from-BorrowerDebarm.patch (text/plain), 10.55 KB, created by
Martin Renvoize (ashimema)
on 2022-11-11 08:35:28 UTC
(
hide
)
Description:
Bug 31095: Remove GetDebarments from Borrower_Debarments.t
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-11-11 08:35:28 UTC
Size:
10.55 KB
patch
obsolete
>From c5446331a4853b0616b499286a92446e1bb9cffa Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 25 Aug 2022 10:16:46 +0100 >Subject: [PATCH] Bug 31095: Remove GetDebarments from Borrower_Debarments.t > >This patch replaces calls to GetDebarments with teh >$patron->restritions->search() equivilents. > >Test plan >1. Run the test prior to the patch and confirm it passes >2. Run the test after the patch and confirm it passes >3. Confirm no tests were removed > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > t/db_dependent/Patron/Borrower_Debarments.t | 157 ++++++++++++-------- > 1 file changed, 92 insertions(+), 65 deletions(-) > >diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t >index 21a54eff23..562281e3d3 100755 >--- a/t/db_dependent/Patron/Borrower_Debarments.t >+++ b/t/db_dependent/Patron/Borrower_Debarments.t >@@ -8,7 +8,7 @@ use Koha::Patrons; > > use t::lib::TestBuilder; > >-use Test::More tests => 33; >+use Test::More tests => 34; > > use_ok('Koha::Patron::Debarments'); > >@@ -22,12 +22,18 @@ my $library = $builder->build({ > }); > > my $patron_category = $builder->build({ source => 'Category' }); >-my $borrowernumber = Koha::Patron->new({ >- firstname => 'my firstname', >- surname => 'my surname', >- categorycode => $patron_category->{categorycode}, >- branchcode => $library->{branchcode}, >-})->store->borrowernumber; >+my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { >+ firstname => 'my firstname', >+ surname => 'my surname', >+ categorycode => $patron_category->{categorycode}, >+ branchcode => $library->{branchcode}, >+ } >+ } >+); >+my $borrowernumber = $patron->borrowernumber; > > my $success = Koha::Patron::Debarments::AddDebarment({ > borrowernumber => $borrowernumber, >@@ -38,11 +44,12 @@ my $success = Koha::Patron::Debarments::AddDebarment({ > is( $success, 1, "AddDebarment returned true" ); > > >-my $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); >-is( @$debarments, 1, "GetDebarments returns 1 debarment" ); >-is( $debarments->[0]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); >-is( $debarments->[0]->{'expiration'}, '9999-06-10', "Correctly stored 'expiration'" ); >-is( $debarments->[0]->{'comment'}, 'Test 1', "Correctly stored 'comment'" ); >+my $restrictions = $patron->restrictions; >+my $THE_restriction = $restrictions->next; >+is( $restrictions->count, 1, '$patron->restrictions returns 1 restriction' ); >+is( $THE_restriction->type->code, 'MANUAL', "Correctly stored 'type'" ); >+is( $THE_restriction->expiration, '9999-06-10', "Correctly stored 'expiration'" ); >+is( $THE_restriction->comment, 'Test 1', "Correctly stored 'comment'" ); > > > $success = Koha::Patron::Debarments::AddDebarment({ >@@ -50,108 +57,128 @@ $success = Koha::Patron::Debarments::AddDebarment({ > comment => 'Test 2', > }); > >-$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); >-is( @$debarments, 2, "GetDebarments returns 2 debarments" ); >-is( $debarments->[1]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); >-is( $debarments->[1]->{'expiration'}, undef, "Correctly stored debarrment with no expiration" ); >-is( $debarments->[1]->{'comment'}, 'Test 2', "Correctly stored 'comment'" ); >+$restrictions = $patron->restrictions; >+$THE_restriction = $restrictions->last; >+is( $restrictions->count, 2, '$patron->restrictions returns 2 restrictions' ); >+is( $THE_restriction->type->code, 'MANUAL', "Correctly stored 'type'" ); >+is( $THE_restriction->expiration, undef, "Correctly stored debarrment with no expiration" ); >+is( $THE_restriction->comment, 'Test 2', "Correctly stored 'comment'" ); > > > Koha::Patron::Debarments::ModDebarment({ >- borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'}, >+ borrower_debarment_id => $THE_restriction->borrower_debarment_id, > comment => 'Test 3', > expiration => '9998-06-10', > }); >-$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); >-is( $debarments->[1]->{'comment'}, 'Test 3', "ModDebarment functions correctly" ); > >-my $patron = Koha::Patrons->find( $borrowernumber )->unblessed; >-is( $patron->{'debarred'}, '9999-06-10', "Field borrowers.debarred set correctly" ); >-is( $patron->{'debarredcomment'}, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); >+$restrictions = $patron->restrictions; >+$THE_restriction = $restrictions->last; >+is( $restrictions->count, 2, '$patron->restrictions returns 2 restrictions' ); >+is( $THE_restriction->comment, 'Test 3', "ModDebarment functions correctly" ); >+ >+$patron = $patron->get_from_storage; >+is( $patron->debarred, '9999-06-10', "Field borrowers.debarred set correctly" ); >+is( $patron->debarredcomment, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); > > > Koha::Patron::Debarments::AddUniqueDebarment({ > borrowernumber => $borrowernumber, > type => 'OVERDUES' > }); >-$debarments = Koha::Patron::Debarments::GetDebarments({ >- borrowernumber => $borrowernumber, >- type => 'OVERDUES', >-}); >-is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment" ); >-is( $debarments->[0]->{'type'}, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" ); >+ >+$restrictions = $patron->restrictions->search( >+ { >+ type => 'OVERDUES', >+ } >+); >+$THE_restriction = $restrictions->next; >+is( $restrictions->count, 1, '$patron->restrictions->search({ type => "OVERDUES" }) returns 1 OVERDUES restriction after running AddUniqueDebarment once' ); >+is( $THE_restriction->type->code, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" ); > > Koha::Patron::Debarments::AddUniqueDebarment({ > borrowernumber => $borrowernumber, > expiration => '9999-11-09', > type => 'OVERDUES' > }); >-$debarments = Koha::Patron::Debarments::GetDebarments({ >- borrowernumber => $borrowernumber, >- type => 'OVERDUES', >-}); >-is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment after running AddOverduesDebarment twice" ); >-is( $debarments->[0]->{'expiration'}, '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" ); >+ >+$restrictions = $patron->restrictions->search( >+ { >+ type => 'OVERDUES', >+ } >+); >+$THE_restriction = $restrictions->next; >+is( $restrictions->count, 1, '$patron->restrictions->search({ type => "OVERDUES" }) returns 1 OVERDUES restriction after running AddUniqueDebarent twice' ); >+is( $THE_restriction->expiration, '9999-11-09', "AddUniqueDebarment updated the OVERDUES restriction correctly" ); > > > my $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ > }); > is( $delUniqueDebarment, undef, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' returns undef" ); >-$debarments = Koha::Patron::Debarments::GetDebarments({ >- borrowernumber => $borrowernumber, >- type => 'OVERDUES', >-}); >-is( @$debarments, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" ); >+ >+$restrictions = $patron->restrictions->search( >+ { >+ type => 'OVERDUES', >+ } >+); >+is( $restrictions->count, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" ); > > $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ > borrowernumber => $borrowernumber, > }); > is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'type' returns undef" ); >-$debarments = Koha::Patron::Debarments::GetDebarments({ >- borrowernumber => $borrowernumber, >- type => 'OVERDUES', >-}); >-is( @$debarments, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" ); >+ >+$restrictions = $patron->restrictions->search( >+ { >+ type => 'OVERDUES', >+ } >+); >+is( $restrictions->count, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" ); > > $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ > type => 'OVERDUES' > }); > is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'borrowernumber' returns undef" ); >-$debarments = Koha::Patron::Debarments::GetDebarments({ >- borrowernumber => $borrowernumber, >- type => 'OVERDUES', >-}); >-is( @$debarments, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" ); >+ >+$restrictions = $patron->restrictions->search( >+ { >+ type => 'OVERDUES', >+ } >+); >+is( $restrictions->count, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" ); > > $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ > borrowernumber => $borrowernumber, > type => 'SUSPENSION', > }); > is( $delUniqueDebarment, undef, "DelUniqueDebarment with wrong arguments returns undef" ); >-$debarments = Koha::Patron::Debarments::GetDebarments({ >- borrowernumber => $borrowernumber, >- type => 'OVERDUES', >-}); >-is( @$debarments, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" ); >+ >+$restrictions = $patron->restrictions->search( >+ { >+ type => 'OVERDUES', >+ } >+); >+is( $restrictions->count, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" ); > > $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ > borrowernumber => $borrowernumber, > type => 'OVERDUES', > }); > is( $delUniqueDebarment, 1, "DelUniqueDebarment returns 1" ); >-$debarments = Koha::Patron::Debarments::GetDebarments({ >- borrowernumber => $borrowernumber, >- type => 'OVERDUES', >-}); >-is( @$debarments, 0, "DelUniqueDebarment functions correctly" ); > >+$restrictions = $patron->restrictions->search( >+ { >+ type => 'OVERDUES', >+ } >+); >+is( $restrictions->count, 0, "DelUniqueDebarment functions correctly" ); > >-$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); >-foreach my $d ( @$debarments ) { >- Koha::Patron::Debarments::DelDebarment( $d->{'borrower_debarment_id'} ); >+$restrictions = $patron->restrictions; >+while ( my $restriction = $restrictions->next ) { >+ Koha::Patron::Debarments::DelDebarment( $restriction->borrower_debarment_id ); > } >-$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); >-is( @$debarments, 0, "DelDebarment functions correctly" ); >+ >+$restrictions = $patron->restrictions; >+is( $restrictions->count, 0, "DelDebarment functions correctly" ); > > $dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|); > is( Koha::Patrons->find( $borrowernumber )->is_debarred, undef, 'A patron with a debarred date in the past is not debarred' ); >-- >2.20.1
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 31095
:
139614
|
139719
|
139720
|
139721
|
139722
|
139723
|
139724
|
139725
|
139726
|
139727
|
139728
|
139742
|
139743
|
139744
|
139745
|
139746
|
139747
|
139748
|
139749
|
139750
|
139751
|
139752
|
139753
|
139754
|
139755
|
139756
|
139757
|
139758
|
140714
|
140715
|
140716
|
140717
|
140718
|
140719
|
140720
|
140721
|
140722
|
140723
|
140724
|
140725
|
140726
|
140727
|
140728
|
140729
|
140730
|
140731
|
142059
|
142060
|
142061
|
142062
|
142063
|
142064
|
142065
|
142066
|
142067
|
142068
|
142069
|
142070
|
142071
|
142072
|
142073
|
142074
|
142075
|
142076
|
143745
|
143746
|
143747
|
143748
|
143749
|
143750
|
143751
|
143752
|
143753
|
143754
|
143755
|
143756
|
143757
|
143758
|
143759
|
143760
|
143761
|
143762
|
143763
|
144903
|
144904
|
144905
|
144906
|
144907
|
144908
|
144909
|
144910
|
144911
|
144912
|
144913
|
144914
|
144915
|
144916
|
144917
|
144918
|
144919
|
144920
|
144921
|
145800
|
145801
|
145803
|
145845