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
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomás Cohen Arazi 2022-02-04 08:14:30 -03:00 committed by Fridolin Somers
parent c287121471
commit 8d63dd3760
3 changed files with 63 additions and 9 deletions

View file

@ -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' );

View file

@ -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' );

View file

@ -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' );