Bugzilla – Attachment 129360 Details for
Bug 29868
Add Koha::Old::Hold->anonymize
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29868: Add Koha::Old::Hold->anonymize
Bug-29868-Add-KohaOldHold-anonymize.patch (text/plain), 4.03 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-01-12 19:27:47 UTC
(
hide
)
Description:
Bug 29868: Add Koha::Old::Hold->anonymize
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-01-12 19:27:47 UTC
Size:
4.03 KB
patch
obsolete
>From 9ef5da61a13ea702d8ef81bace597d3fde6a8fe7 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 12 Jan 2022 16:24:35 -0300 >Subject: [PATCH] Bug 29868: Add Koha::Old::Hold->anonymize > >This patch introduces a new method in Koha::Old::Hold. The method is >fully covered by tests. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Old/Hold.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Old/Hold.pm | 21 ++++++++- > t/db_dependent/Koha/Old/Hold.t | 80 ++++++++++++++++++++++++++++++++++ > 2 files changed, 99 insertions(+), 2 deletions(-) > create mode 100755 t/db_dependent/Koha/Old/Hold.t > >diff --git a/Koha/Old/Hold.pm b/Koha/Old/Hold.pm >index 0701e64fd4..33642b33f6 100644 >--- a/Koha/Old/Hold.pm >+++ b/Koha/Old/Hold.pm >@@ -21,6 +21,8 @@ use Modern::Perl; > > use base qw(Koha::Hold); > >+use C4::Context; >+ > =head1 NAME > > Koha::Old::Hold - Koha Old Hold object class >@@ -29,12 +31,27 @@ This object represents a hold that has been filled or canceled > > =head1 API > >-=head2 Class Methods >+=head2 Class methods >+ >+=head3 anonymize >+ >+ $old_hold->anonymize(); >+ >+Anonymize the given I<Koha::Old::Hold> object. > > =cut > >+sub anonymize { >+ my ($self) = @_; >+ >+ my $anonymous_id = C4::Context->preference('AnonymousPatron') || undef; >+ >+ return $self->update( { borrowernumber => $anonymous_id } ); >+} >+ >+=head2 Internal methods > >-=head3 type >+=head3 _type > > =cut > >diff --git a/t/db_dependent/Koha/Old/Hold.t b/t/db_dependent/Koha/Old/Hold.t >new file mode 100755 >index 0000000000..b660ec4914 >--- /dev/null >+++ b/t/db_dependent/Koha/Old/Hold.t >@@ -0,0 +1,80 @@ >+#!/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 => 1; >+ >+use Koha::Database; >+ >+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 => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ is( $patron->old_holds->count, 0, 'Patron has no old holds' ); >+ >+ my $hold_1 = $builder->build_object( >+ { >+ class => 'Koha::Old::Holds', >+ value => { borrowernumber => $patron->id } >+ } >+ ); >+ my $hold_2 = $builder->build_object( >+ { >+ class => 'Koha::Old::Holds', >+ value => { borrowernumber => $patron->id } >+ } >+ ); >+ >+ is( $patron->old_holds->count, 2, 'Patron has 2 completed holds' ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); >+ >+ $hold_1->anonymize; >+ >+ is( $patron->old_holds->count, 1, 'Patron has 1 linked completed holds' ); >+ >+ # Reload >+ $hold_1->discard_changes; >+ $hold_2->discard_changes; >+ is( $hold_1->borrowernumber, undef, >+ 'Anonymized hold not linked to patron' ); >+ is( $hold_2->borrowernumber, $patron->id, >+ 'Not anonymized hold still linked to patron' ); >+ >+ my $anonymous_patron = >+ $builder->build_object( { class => 'Koha::Patrons' } ); >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); >+ >+ # anonymize second hold >+ $hold_2->anonymize; >+ $hold_2->discard_changes; >+ is( $hold_2->borrowernumber, $anonymous_patron->id, >+ 'Anonymized hold linked to anonymouspatron' ); >+ >+ $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 29868
:
129359
|
129360
|
129410
|
129423
|
129541