Bugzilla – Attachment 131298 Details for
Bug 30007
Make ->anonymize methods throw an exception if AnonymousPatron is not set
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30007: (follow-up) Adapt tests
Bug-30007-follow-up-Adapt-tests.patch (text/plain), 5.82 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-03-02 20:50:43 UTC
(
hide
)
Description:
Bug 30007: (follow-up) Adapt tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-03-02 20:50:43 UTC
Size:
5.82 KB
patch
obsolete
>From 1e55b6e24d55cf17be86183c483213c08f4ea4e8 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 2 Mar 2022 15:05:02 -0300 >Subject: [PATCH] Bug 30007: (follow-up) Adapt tests > >This patch adapts tests to acknowledge ->cancel and ->fill methods won't >yield 'undef' borrowernumber when anonymization takes place, and even >further, and exception will be thrown and cancellation/fulfillment will >be rejected. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Hold.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Bonus: this problem was hidding bad tests caused by 29857, fixed on this >one as well. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/Hold.t | 49 ++++++++++++++++++++++++-------------- > 1 file changed, 31 insertions(+), 18 deletions(-) > >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 33290ac205..0c1776daa9 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -166,18 +166,20 @@ subtest 'fill() tests' => sub { > > subtest 'anonymization behavior tests' => sub { > >- plan tests => 4; >+ plan tests => 5; > > # reduce the tests noise > t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); > t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' ); >+ # unset AnonymousPatron >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); > > # 0 == keep forever > $patron->privacy(0)->store; > my $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); > $hold->fill(); >@@ -189,7 +191,7 @@ subtest 'fill() tests' => sub { > $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); > $hold->fill(); >@@ -201,12 +203,18 @@ subtest 'fill() tests' => sub { > $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); >- $hold->fill(); >- is( Koha::Old::Holds->find( $hold->id )->borrowernumber, >- undef, 'Patron link is deleted immediately' ); >+ >+ throws_ok >+ { $hold->fill(); } >+ 'Koha::Exception', >+ 'AnonymousPatron not set, exception thrown'; >+ >+ $hold->discard_changes; # refresh from DB >+ >+ ok( !$hold->is_found, 'Hold is not filled' ); > > my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); > t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >@@ -214,10 +222,10 @@ subtest 'fill() tests' => sub { > $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); >- $hold->cancel(); >+ $hold->fill(); > is( > Koha::Old::Holds->find( $hold->id )->borrowernumber, > $anonymous_patron->id, >@@ -337,7 +345,7 @@ subtest 'set_pickup_location() tests' => sub { > 'Koha::Exceptions::MissingParameter', > 'Exception thrown if missing parameter'; > >- is( "$@", 'The library_id parameter is mandatory', 'Exception message is clear' ); >+ like( "$@", qr/The library_id parameter is mandatory/, 'Exception message is clear' ); > > $schema->storage->txn_rollback; > }; >@@ -448,7 +456,7 @@ subtest 'is_pickup_location_valid() tests' => sub { > > subtest 'cancel() tests' => sub { > >- plan tests => 4; >+ plan tests => 5; > > $schema->storage->txn_begin; > >@@ -466,7 +474,7 @@ subtest 'cancel() tests' => sub { > my $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); > $hold->cancel(); >@@ -478,7 +486,7 @@ subtest 'cancel() tests' => sub { > $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); > $hold->cancel(); >@@ -490,12 +498,17 @@ subtest 'cancel() tests' => sub { > $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); >- $hold->cancel(); >- is( Koha::Old::Holds->find( $hold->id )->borrowernumber, >- undef, 'Patron link is deleted immediately' ); >+ throws_ok >+ { $hold->cancel(); } >+ 'Koha::Exception', >+ 'AnonymousPatron not set, exception thrown'; >+ >+ $hold->discard_changes; >+ >+ ok( !$hold->is_found, 'Hold is not cancelled' ); > > my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); > t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >@@ -503,7 +516,7 @@ subtest 'cancel() tests' => sub { > $hold = $builder->build_object( > { > class => 'Koha::Holds', >- value => { borrowernumber => $patron->id, status => undef } >+ value => { borrowernumber => $patron->id, found => undef } > } > ); > $hold->cancel(); >-- >2.35.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 30007
:
130163
|
130164
|
130165
|
130175
|
130176
|
130177
|
130272
|
130273
|
130274
|
131239
| 131298