Bugzilla – Attachment 129274 Details for
Bug 29843
Add ->anonymize and ->filter_by_anonymizable to Koha::Old::Checkouts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29843: Unit tests
Bug-29843-Unit-tests.patch (text/plain), 6.60 KB, created by
Tomás Cohen Arazi
on 2022-01-10 15:19:51 UTC
(
hide
)
Description:
Bug 29843: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi
Created:
2022-01-10 15:19:51 UTC
Size:
6.60 KB
patch
obsolete
>From e3b125674832f14cd1bc80a81aebda786f8a396e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 10 Jan 2022 11:22:52 -0300 >Subject: [PATCH] Bug 29843: Unit tests > >This patch adds unit tests for the introduced methods. >--- > t/db_dependent/Koha/Old/Checkouts.t | 185 ++++++++++++++++++++++++++++ > 1 file changed, 185 insertions(+) > create mode 100755 t/db_dependent/Koha/Old/Checkouts.t > >diff --git a/t/db_dependent/Koha/Old/Checkouts.t b/t/db_dependent/Koha/Old/Checkouts.t >new file mode 100755 >index 0000000000..97559495a6 >--- /dev/null >+++ b/t/db_dependent/Koha/Old/Checkouts.t >@@ -0,0 +1,185 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+use Koha::Database; >+use Koha::DateUtils qw(dt_from_string); >+use Koha::Old::Checkouts; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'anonymize() tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ is( $patron->old_checkouts->count, 0, 'Patron has no old checkouts' ); >+ is( $patron->old_checkouts->anonymize + 0, >+ 0, 'Anonymizing an empty resultset returns 0' ); >+ >+ my $checkout_1 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => >+ { borrowernumber => $patron->id, timestamp => dt_from_string() } >+ } >+ ); >+ my $checkout_2 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron->id, >+ timestamp => dt_from_string()->subtract( days => 1 ) >+ } >+ } >+ ); >+ my $checkout_3 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron->id, >+ timestamp => dt_from_string()->subtract( days => 2 ) >+ } >+ } >+ ); >+ my $checkout_4 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron->id, >+ timestamp => dt_from_string()->subtract( days => 3 ) >+ } >+ } >+ ); >+ >+ is( $patron->old_checkouts->count, 4, 'Patron has 4 completed checkouts' ); >+ >+ # filter them so only the older two are part of the resultset >+ my $checkouts = $patron->old_checkouts->filter_by_last_update( >+ { days => 1, days_inclusive => 1 } ); >+ >+ # Anonymize them >+ my $anonymized_count = $checkouts->anonymize(); >+ is( $anonymized_count, 2, 'update() tells 2 rows were updated' ); >+ >+ is( $patron->old_checkouts->count, 2, 'Patron has 2 completed checkouts' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'filter_by_anonymizable() tests' => sub { >+ >+ plan tests => 7; >+ >+ $schema->storage->txn_begin; >+ >+ my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >+ >+ # patron_1 => keep records forever >+ my $patron_1 = $builder->build_object( >+ { class => 'Koha::Patrons', value => { privacy => 0 } } ); >+ >+ # patron_2 => never keep records >+ my $patron_2 = $builder->build_object( >+ { class => 'Koha::Patrons', value => { privacy => 1 } } ); >+ >+ is( $patron_1->old_checkouts->count, 0, 'patron_1 has no old checkouts' ); >+ is( $patron_2->old_checkouts->count, 0, 'patron_2 has no old checkouts' ); >+ >+ my $checkout_1 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron_1->id, >+ } >+ } >+ ); >+ my $checkout_2 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron_2->id, >+ } >+ } >+ ); >+ my $checkout_3 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron_1->id, >+ } >+ } >+ ); >+ my $checkout_4 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $patron_2->id, >+ } >+ } >+ ); >+ # borrowernumber == undef => never listed as anonymizable >+ my $checkout_5 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => undef, >+ } >+ } >+ ); >+ # borrowernumber == anonymous patron => never listed as anonymizable >+ my $checkout_6 = $builder->build_object( >+ { >+ class => 'Koha::Old::Checkouts', >+ value => { >+ borrowernumber => $anonymous_patron->id, >+ } >+ } >+ ); >+ >+ $checkout_2->set( { timestamp => dt_from_string()->subtract( days => 1 ) } )->store; >+ $checkout_3->set( { timestamp => dt_from_string()->subtract( days => 2 ) } )->store; >+ $checkout_4->set( { timestamp => dt_from_string()->subtract( days => 3 ) } )->store; >+ >+ is( $patron_1->old_checkouts->count, 2, 'patron_1 has 2 completed checkouts' ); >+ is( $patron_2->old_checkouts->count, 2, 'patron_2 has 2 completed checkouts' ); >+ >+ # filter them so only the older two are part of the resultset >+ my $checkouts = Koha::Old::Checkouts->search( >+ { 'me.borrowernumber' => [ $patron_1->id, $patron_2->id ] } ); >+ is( $checkouts->count, 4, 'Total of 4 checkouts returned correctly' ); >+ my $rs = $checkouts->filter_by_anonymizable; >+ is( $rs->count, 2, 'Only 2 can be anonymized' ); >+ >+ $rs = $checkouts->filter_by_anonymizable->filter_by_last_update( >+ { days => 1 } ); >+ >+ is( $rs->count, 1, 'Only 1 can be anonymized with date filter applied' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.32.0
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 29843
:
129269
|
129270
|
129271
|
129272
|
129274
|
129275
|
129276
|
129277
|
129278
|
129438
|
129439
|
129440
|
129441
|
129442
|
129445
|
129446
|
129447
|
129448
|
129449
|
129475
|
129476
|
129477
|
129478
|
129479
|
129492
|
129493
|
129494
|
129495
|
129496
|
130264
|
130265
|
130266
|
130267
|
130268
|
130335