Bugzilla – Attachment 130272 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: Regression tests
Bug-30007-Regression-tests.patch (text/plain), 6.21 KB, created by
Martin Renvoize (ashimema)
on 2022-02-08 09:48:16 UTC
(
hide
)
Description:
Bug 30007: Regression tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-02-08 09:48:16 UTC
Size:
6.21 KB
patch
obsolete
>From 7b03bbc0f3d2fb441664535d78a4fdf7f9cb5add Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 4 Feb 2022 08:14:30 -0300 >Subject: [PATCH] Bug 30007: Regression tests > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >https://bugs.koha-community.org/show_bug.cgi?id=3007 >--- > t/db_dependent/Koha/Old/Checkouts.t | 27 ++++++++++++++++++++++++++- > t/db_dependent/Koha/Old/Hold.t | 16 +++++++++------- > t/db_dependent/Koha/Old/Holds.t | 29 ++++++++++++++++++++++++++++- > 3 files changed, 63 insertions(+), 9 deletions(-) > >diff --git a/t/db_dependent/Koha/Old/Checkouts.t b/t/db_dependent/Koha/Old/Checkouts.t >index 97559495a6..2c7c52ad62 100755 >--- a/t/db_dependent/Koha/Old/Checkouts.t >+++ b/t/db_dependent/Koha/Old/Checkouts.t >@@ -18,6 +18,7 @@ > use Modern::Perl; > > use Test::More tests => 2; >+use Test::Exception; > > use Koha::Database; > use Koha::DateUtils qw(dt_from_string); >@@ -31,13 +32,26 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'anonymize() tests' => sub { > >- plan tests => 5; >+ plan tests => 10; > > $schema->storage->txn_begin; > > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); > > is( $patron->old_checkouts->count, 0, 'Patron has no old checkouts' ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); >+ >+ throws_ok >+ { $patron->old_checkouts->anonymize; } >+ 'Koha::Exceptions::SysPref::NotSet', >+ 'Exception thrown because AnonymousPatron not set'; >+ >+ is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >+ > is( $patron->old_checkouts->anonymize + 0, > 0, 'Anonymizing an empty resultset returns 0' ); > >@@ -82,6 +96,17 @@ subtest 'anonymize() tests' => sub { > my $checkouts = $patron->old_checkouts->filter_by_last_update( > { days => 1, days_inclusive => 1 } ); > >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); >+ throws_ok >+ { $checkouts->anonymize; } >+ 'Koha::Exceptions::SysPref::NotSet', >+ 'Exception thrown because AnonymousPatron not set'; >+ >+ is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' ); >+ is( $patron->old_checkouts->count, 4, 'Patron has 4 completed checkouts' ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >+ > # Anonymize them > my $anonymized_count = $checkouts->anonymize(); > is( $anonymized_count, 2, 'update() tells 2 rows were updated' ); >diff --git a/t/db_dependent/Koha/Old/Hold.t b/t/db_dependent/Koha/Old/Hold.t >index b660ec4914..91ed7a71c2 100755 >--- a/t/db_dependent/Koha/Old/Hold.t >+++ b/t/db_dependent/Koha/Old/Hold.t >@@ -18,6 +18,7 @@ > use Modern::Perl; > > use Test::More tests => 1; >+use Test::Exception; > > use Koha::Database; > >@@ -29,7 +30,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'anonymize() tests' => sub { > >- plan tests => 6; >+ plan tests => 8; > > $schema->storage->txn_begin; > >@@ -54,14 +55,15 @@ subtest 'anonymize() tests' => sub { > > t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); > >- $hold_1->anonymize; >+ throws_ok >+ { $hold_1->anonymize; } >+ 'Koha::Exceptions::SysPref::NotSet', >+ 'Exception thrown because AnonymousPatron not set'; > >- is( $patron->old_holds->count, 1, 'Patron has 1 linked completed holds' ); >+ is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' ); >+ is( $patron->old_holds->count, 2, 'No changes, patron has 2 linked completed holds' ); > >- # Reload >- $hold_1->discard_changes; >- $hold_2->discard_changes; >- is( $hold_1->borrowernumber, undef, >+ is( $hold_1->borrowernumber, $patron->id, > 'Anonymized hold not linked to patron' ); > is( $hold_2->borrowernumber, $patron->id, > 'Not anonymized hold still linked to patron' ); >diff --git a/t/db_dependent/Koha/Old/Holds.t b/t/db_dependent/Koha/Old/Holds.t >index befaefe7d1..cd791ad350 100755 >--- a/t/db_dependent/Koha/Old/Holds.t >+++ b/t/db_dependent/Koha/Old/Holds.t >@@ -18,11 +18,13 @@ > use Modern::Perl; > > use Test::More tests => 2; >+use Test::Exception; > > use Koha::Database; > use Koha::DateUtils qw(dt_from_string); > use Koha::Old::Holds; > >+use t::lib::Mocks; > use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; >@@ -30,13 +32,26 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'anonymize() tests' => sub { > >- plan tests => 5; >+ plan tests => 10; > > $schema->storage->txn_begin; > > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); > > is( $patron->old_holds->count, 0, 'Patron has no old holds' ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); >+ >+ throws_ok >+ { $patron->old_holds->anonymize; } >+ 'Koha::Exceptions::SysPref::NotSet', >+ 'Exception thrown because AnonymousPatron not set'; >+ >+ is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >+ > is( $patron->old_holds->anonymize + 0, 0, 'Anonymizing an empty resultset returns 0' ); > > my $hold_1 = $builder->build_object( >@@ -78,6 +93,18 @@ subtest 'anonymize() tests' => sub { > # filter them so only the older two are part of the resultset > my $holds = $patron->old_holds->search({ timestamp => { '<=' => dt_from_string()->subtract( days => 2 ) } }); > # Anonymize them >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); >+ throws_ok >+ { $holds->anonymize; } >+ 'Koha::Exceptions::SysPref::NotSet', >+ 'Exception thrown because AnonymousPatron not set'; >+ >+ is( $@->syspref, 'AnonymousPatron', 'syspref parameter is correctly passed' ); >+ is( $patron->old_holds->count, 4, 'Patron has 4 completed holds' ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >+ > my $anonymized_count = $holds->anonymize(); > is( $anonymized_count, 2, 'update() tells 2 rows were updated' ); > >-- >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 30007
:
130163
|
130164
|
130165
|
130175
|
130176
|
130177
| 130272 |
130273
|
130274
|
131239
|
131298