Bugzilla – Attachment 168094 Details for
Bug 37182
'datetime' field lost on pseudonymization
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37182: Regression tests
Bug-37182-Regression-tests.patch (text/plain), 5.75 KB, created by
Tomás Cohen Arazi (tcohen)
on 2024-06-25 18:05:21 UTC
(
hide
)
Description:
Bug 37182: Regression tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2024-06-25 18:05:21 UTC
Size:
5.75 KB
patch
obsolete
>From 48e1f5686cb3b86f0965fab9ee1c94b1f83ad9df Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 25 Jun 2024 10:16:56 -0300 >Subject: [PATCH] Bug 37182: Regression tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > .../BackgroundJob/PseudonymizeStatistic.t | 34 +++++++---- > t/db_dependent/Koha/Statistic.t | 58 +++++++++++++++++++ > 2 files changed, 81 insertions(+), 11 deletions(-) > create mode 100755 t/db_dependent/Koha/Statistic.t > >diff --git a/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t b/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t >index 6fbb95cebd9..d7adccec0c4 100755 >--- a/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t >+++ b/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t >@@ -21,6 +21,7 @@ use Test::More tests => 2; > use Test::Exception; > > use Koha::Database; >+use Koha::DateUtils qw(dt_from_string); > use Koha::BackgroundJobs; > use Koha::BackgroundJob::PseudonymizeStatistic; > >@@ -29,6 +30,7 @@ use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >+my $dtf = $schema->storage->datetime_parser; > > subtest 'enqueue() tests' => sub { > >@@ -65,29 +67,39 @@ subtest 'enqueue() tests' => sub { > > subtest 'process() tests' => sub { > >- plan tests => 2; >+ plan tests => 3; > > $schema->storage->txn_begin; > > t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); >- t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); >- t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); >+ t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); >+ t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); >+ t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime' ); > > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > my $item = $builder->build_sample_item(); > my $statistic = $builder->build_object( > { > class => 'Koha::Statistics', >- value => { type => 'issue', borrowernumber => $patron->id, itemnumber => $item->id } >+ value => { >+ borrowernumber => $patron->id, >+ datetime => $dtf->format_datetime( dt_from_string()->subtract( days => 7 ) ), >+ itemnumber => $item->id, >+ type => 'issue', >+ } > } >- ); >+ )->unblessed; > >- my $job_id = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic->unblessed } ); >- my $pseudonymized_transactions_before = Koha::PseudonymizedTransactions->search()->count(); >- my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >- $job->process( { statistic => $statistic->unblessed } ); >- my $pseudonymized_transactions_after = Koha::PseudonymizedTransactions->search()->count(); >- is( $pseudonymized_transactions_after, $pseudonymized_transactions_before + 1, "Pseudonymized transaction added" ); >+ my $job_id = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic } ); >+ my $pt_count_before = Koha::PseudonymizedTransactions->search()->count(); >+ >+ my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >+ $job->process( { statistic => $statistic } ); >+ >+ my $pt_after = Koha::PseudonymizedTransactions->search(); >+ is( $pt_after->count, $pt_count_before + 1, "Pseudonymized transaction added" ); >+ >+ is( $statistic->{datetime}, $pt_after->last->datetime, "'datetime' column preserved" ); > > $job->discard_changes; > is( $job->data, '{"data":""}', "Job data cleared after pseudonymization" ); >diff --git a/t/db_dependent/Koha/Statistic.t b/t/db_dependent/Koha/Statistic.t >new file mode 100755 >index 00000000000..1146c3330d9 >--- /dev/null >+++ b/t/db_dependent/Koha/Statistic.t >@@ -0,0 +1,58 @@ >+#!/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::DateUtils qw(dt_from_string); >+use Koha::Statistics; >+use Koha::Database; >+ >+use t::lib::TestBuilder; >+ >+my $builder = t::lib::TestBuilder->new; >+my $schema = Koha::Database->new->schema; >+my $dtf = $schema->storage->datetime_parser; >+ >+subtest 'new() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $statistic = $builder->build_object( >+ { >+ class => 'Koha::Statistics', >+ value => { >+ datetime => $dtf->format_datetime( dt_from_string()->subtract( days => 7 ) ), >+ type => 'issue', >+ }, >+ } >+ )->unblessed; >+ >+ my $new_statistic = Koha::Statistic->new($statistic); >+ is( $new_statistic->datetime, $statistic->{datetime}, "Passed 'datetime' is preserved" ); >+ >+ delete $statistic->{datetime}; >+ is( $statistic->{datetime}, undef, "'datetime' not present (check)" ); >+ >+ $new_statistic = Koha::Statistic->new($statistic); >+ ok( defined $new_statistic->datetime, "'datetime' calculated if not passed" ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.45.2
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 37182
:
168094
|
168095
|
168114
|
168115