Bugzilla – Attachment 85007 Details for
Bug 21765
AutoUnsuspendReserves manually sets holds fields instead of calling ->resume
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21765: Regression tests
Bug-21765-Regression-tests.patch (text/plain), 5.85 KB, created by
Kyle M Hall (khall)
on 2019-02-11 20:04:28 UTC
(
hide
)
Description:
Bug 21765: Regression tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2019-02-11 20:04:28 UTC
Size:
5.85 KB
patch
obsolete
>From 5157f92531aa6181b31b115225499d5fd9c6912b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 11 Feb 2019 16:04:59 -0300 >Subject: [PATCH] Bug 21765: Regression tests > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > .../Reserves/AutoUnsuspendReserves.t | 135 +++++++++++++++--- > 1 file changed, 115 insertions(+), 20 deletions(-) > >diff --git a/t/db_dependent/Reserves/AutoUnsuspendReserves.t b/t/db_dependent/Reserves/AutoUnsuspendReserves.t >index 9302da64da..d5703cc4e9 100644 >--- a/t/db_dependent/Reserves/AutoUnsuspendReserves.t >+++ b/t/db_dependent/Reserves/AutoUnsuspendReserves.t >@@ -1,6 +1,22 @@ > #!/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 t::lib::Mocks; >@@ -12,46 +28,125 @@ use Koha::DateUtils; > use Koha::Holds; > > my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; > > subtest 'AutoUnsuspendReserves test' => sub { >- plan tests => 2; > >- my $builder = t::lib::TestBuilder->new(); >+ plan tests => 4; > >- my $today = dt_from_string(); >- my $today_date = output_pref({ dateformat => 'sql' }); >- my $tomorrow_date = output_pref({ dt => $today->add(days=>1), dateformat=>'sql' }); >+ $schema->storage->txn_begin; > >- # Reserve not expired >- my $reserve1 = $builder->build({ >- source => 'Reserve', >+ my $today = dt_from_string(); >+ my $tomorrow = $today->clone->add(days=>1); >+ >+ # Not expired hold >+ my $hold_1 = $builder->build_object({ >+ class => 'Koha::Holds', > value => { > expirationdate => undef, > cancellationdate => undef, > priority => 5, > found => undef, >- suspend_until => $today_date, > }, > }); >- # Reserve expired >- my $reserve2 = $builder->build({ >- source => 'Reserve', >+ >+ $hold_1->suspend_hold( $today ); >+ >+ # Expired hold >+ my $hold_2 = $builder->build_object({ >+ class => 'Koha::Holds', > value => { > expirationdate => undef, > cancellationdate => undef, > priority => 6, > found => undef, >- suspend_until => $tomorrow_date, > }, > }); > >+ $hold_2->suspend_hold( $tomorrow ); >+ > AutoUnsuspendReserves(); >- my $r1 = Koha::Holds->find($reserve1->{reserve_id}); >- my $r2 = Koha::Holds->find($reserve2->{reserve_id}); >- ok(!defined($r1->suspend_until), 'Reserve suspended until today should be unsuspended.'); >- ok(defined($r2->suspend_until), 'Reserve suspended after today should be suspended.'); > >-}; >+ # refresh >+ $hold_1->discard_changes; >+ $hold_2->discard_changes; >+ >+ ok(!$hold_1->is_suspended, 'Hold suspended until today should be unsuspended.'); >+ ok( $hold_2->is_suspended, 'Hold suspended after today should be suspended.'); >+ >+ subtest 'logging enabled' => sub { >+ >+ plan tests => 2; >+ >+ # Enable logging >+ t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); >+ >+ my $hold_3 = $builder->build_object( >+ { class => 'Koha::Holds', >+ value => { >+ expirationdate => undef, >+ cancellationdate => undef, >+ priority => 5, >+ found => undef, >+ suspend_until => undef, >+ } >+ } >+ ); >+ $hold_3->suspend_hold( $today ); >+ >+ my $logs_count = $schema->resultset('ActionLog') >+ ->search( { module => 'HOLDS', action => 'RESUME' } )->count; >+ >+ AutoUnsuspendReserves(); > >-$schema->storage->txn_rollback; >+ $hold_3->discard_changes; >+ ok(!$hold_3->is_suspended, 'Hold suspended until today should be unsuspended.'); >+ >+ my $new_logs_count = $schema->resultset('ActionLog') >+ ->search( { module => 'HOLDS', action => 'RESUME' } )->count; >+ >+ is( $new_logs_count, >+ $logs_count + 1, >+ 'If logging is enabled, calling AutoUnsuspendReserves gets logged' >+ ); >+ }; >+ >+ subtest 'logging disabled' => sub { >+ >+ plan tests => 2; >+ >+ # Enable logging >+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); >+ >+ my $hold_4 = $builder->build_object( >+ { class => 'Koha::Holds', >+ value => { >+ expirationdate => undef, >+ cancellationdate => undef, >+ priority => 5, >+ found => undef >+ } >+ } >+ ); >+ >+ my $logs_count = $schema->resultset('ActionLog') >+ ->search( { module => 'HOLDS', action => 'RESUME' } )->count; >+ >+ $hold_4->suspend_hold( $today ); >+ >+ AutoUnsuspendReserves(); >+ >+ $hold_4->discard_changes; >+ ok(!defined($hold_4->suspend_until), 'Hold suspended until today should be unsuspended.'); >+ >+ my $new_logs_count = $schema->resultset('ActionLog') >+ ->search( { module => 'HOLDS', action => 'RESUME' } )->count; >+ >+ is( $new_logs_count, >+ $logs_count, >+ 'If logging is not enabled, no logging from AutoUnsuspendReserves calls' >+ ); >+ }; >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.17.2 (Apple Git-113)
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 21765
:
84999
|
85000
|
85007
|
85008
|
85386
|
85387