|
Lines 1-7
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
use Test::More tests => 19; |
4 |
use Test::More tests => 22; |
| 5 |
use MARC::Record; |
5 |
use MARC::Record; |
| 6 |
use MARC::Field; |
6 |
use MARC::Field; |
| 7 |
use DateTime; |
7 |
use DateTime; |
|
Lines 331-336
C4::Items::ToggleNewStatus( { rules => \@rules } );
Link Here
|
| 331 |
$modified_item = Koha::Items->find( $itemnumber ); |
331 |
$modified_item = Koha::Items->find( $itemnumber ); |
| 332 |
is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 2, agefield = 'items.datelastseen' : The new_status value is updated|); |
332 |
is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 2, agefield = 'items.datelastseen' : The new_status value is updated|); |
| 333 |
|
333 |
|
|
|
334 |
# Play with the unit field |
| 335 |
$dt_today = dt_from_string; |
| 336 |
my $hours2ago = dt_from_string->subtract( hours => 2 ); |
| 337 |
my $hours10ago = dt_from_string->subtract( hours => 10 ); |
| 338 |
$modified_item->itemlost_on($hours2ago)->store; |
| 339 |
$modified_item->dateaccessioned($hours10ago)->store; |
| 340 |
|
| 341 |
# When agefield='items.dateaccessioned' and unit='Hours' |
| 342 |
@rules = ( |
| 343 |
{ |
| 344 |
conditions => [ |
| 345 |
{ |
| 346 |
field => 'biblioitems.itemtype', |
| 347 |
value => 'ITEMTYPE_T', |
| 348 |
}, |
| 349 |
], |
| 350 |
substitutions => [ |
| 351 |
{ |
| 352 |
field => 'items.new_status', |
| 353 |
value => 'ageunit_new_value', |
| 354 |
}, |
| 355 |
], |
| 356 |
age => '5', |
| 357 |
ageunit => 'Hours', |
| 358 |
agefield => 'items.dateaccessioned' |
| 359 |
}, |
| 360 |
); |
| 361 |
|
| 362 |
# Confirm a rule with unit = 'Hours' does not work with fields other than items.damaged_on, |
| 363 |
# items.itemlost_on, or items.withdrawn_on |
| 364 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
| 365 |
$modified_item = Koha::Items->find( $itemnumber ); |
| 366 |
is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 5, ageunit = 'Hours', agefield = 'items.dateaccessioned' : The new_status value is not updated|); |
| 367 |
|
| 368 |
# Confirm a rule on a datetime field (items.itemlost_on) with unit = 'Hours' does |
| 369 |
# change an item correctly based on the age in hours |
| 370 |
$rules[0]->{agefield} = 'items.itemlost_on'; |
| 371 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
| 372 |
$modified_item = Koha::Items->find( $itemnumber ); |
| 373 |
$modified_item->itemlost_on; |
| 374 |
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|); |
| 375 |
|
| 376 |
$rules[0]->{age} = 1; |
| 377 |
C4::Items::ToggleNewStatus( { rules => \@rules } ); |
| 378 |
$modified_item = Koha::Items->find( $itemnumber ); |
| 379 |
is( $modified_item->new_status, 'ageunit_new_value', q|ToggleNewStatus: Age = 1, ageunit = 'Hours', agefield = 'items.itemlost_on' : The new_status value is updated|); |
| 380 |
|
| 334 |
# Run twice |
381 |
# Run twice |
| 335 |
t::lib::Mocks::mock_preference('CataloguingLog', 1); |
382 |
t::lib::Mocks::mock_preference('CataloguingLog', 1); |
| 336 |
my $actions_nb = $schema->resultset('ActionLog')->count(); |
383 |
my $actions_nb = $schema->resultset('ActionLog')->count(); |
| 337 |
- |
|
|