From f32dcebf8de236ba91552b5cc3ac591d38038643 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Tue, 9 Aug 2022 16:03:03 +1200 Subject: [PATCH] Bug 21173: Unit tests Test plan: 1. sudo koha-shell kohadev 2. prove t/db_dependent/Items/AutomaticItemModificationByAge.t Sponsored-by: Toi Ohomai Institute of Technology, New Zealand --- .../Items/AutomaticItemModificationByAge.t | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Items/AutomaticItemModificationByAge.t b/t/db_dependent/Items/AutomaticItemModificationByAge.t index 61e6100362e..089b975d394 100755 --- a/t/db_dependent/Items/AutomaticItemModificationByAge.t +++ b/t/db_dependent/Items/AutomaticItemModificationByAge.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 19; +use Test::More tests => 22; use MARC::Record; use MARC::Field; use DateTime; @@ -331,6 +331,53 @@ C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = Koha::Items->find( $itemnumber ); is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 2, agefield = 'items.datelastseen' : The new_status value is updated|); +# Play with the unit field +$dt_today = dt_from_string; +my $hours2ago = dt_from_string->subtract( hours => 2 ); +my $hours10ago = dt_from_string->subtract( hours => 10 ); +$modified_item->itemlost_on($hours2ago)->store; +$modified_item->dateaccessioned($hours10ago)->store; + +# When agefield='items.dateaccessioned' and unit='Hours' +@rules = ( + { + conditions => [ + { + field => 'biblioitems.itemtype', + value => 'ITEMTYPE_T', + }, + ], + substitutions => [ + { + field => 'items.new_status', + value => 'ageunit_new_value', + }, + ], + age => '5', + ageunit => 'Hours', + agefield => 'items.dateaccessioned' + }, +); + +# Confirm a rule with unit = 'Hours' does not work with fields other than items.damaged_on, +# items.itemlost_on, or items.withdrawn_on +C4::Items::ToggleNewStatus( { rules => \@rules } ); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 5, ageunit = 'Hours', agefield = 'items.dateaccessioned' : The new_status value is not updated|); + +# Confirm a rule on a datetime field (items.itemlost_on) with unit = 'Hours' does +# change an item correctly based on the age in hours +$rules[0]->{agefield} = 'items.itemlost_on'; +C4::Items::ToggleNewStatus( { rules => \@rules } ); +$modified_item = Koha::Items->find( $itemnumber ); +$modified_item->itemlost_on; +is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 5, ageunit = 'Hours', agefield = 'items.itemlost_on' : The new_status value is not updated|); + +$rules[0]->{age} = 1; +C4::Items::ToggleNewStatus( { rules => \@rules } ); +$modified_item = Koha::Items->find( $itemnumber ); +is( $modified_item->new_status, 'ageunit_new_value', q|ToggleNewStatus: Age = 1, ageunit = 'Hours', agefield = 'items.itemlost_on' : The new_status value is updated|); + # Run twice t::lib::Mocks::mock_preference('CataloguingLog', 1); my $actions_nb = $schema->resultset('ActionLog')->count(); -- 2.20.1