View | Details | Raw Unified | Return to bug 23010
Collapse All | Expand All

(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-2 / +105 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::NoWarnings;
4
use Test::NoWarnings;
5
use Test::More tests => 21;
5
use Test::More tests => 23;
6
use MARC::Record;
6
use MARC::Record;
7
use MARC::Field;
7
use MARC::Field;
8
use DateTime;
8
use DateTime;
Lines 391-396 C4::Items::ToggleNewStatus( { rules => \@rules } ); Link Here
391
$modified_item = Koha::Items->find($itemnumber);
391
$modified_item = Koha::Items->find($itemnumber);
392
is( $modified_item->new_status, 'new_updated_value_biblio', q|ToggleNewStatus: conditions on biblio| );
392
is( $modified_item->new_status, 'new_updated_value_biblio', q|ToggleNewStatus: conditions on biblio| );
393
393
394
# Test for error handling in ToggleNewStatus with an on-loan item
395
subtest "ToggleNewStatus onloan error handling" => sub {
396
    plan tests => 3;
397
398
    # Create a new test item
399
    my $test_item2 = $builder->build_object( { class => 'Koha::Items' } );
400
    my $patron2    = $builder->build_object( { class => 'Koha::Patrons' } );
401
402
    # Check out the item to create the condition for an error
403
    $test_item2->checkout( $patron2->borrowernumber );
404
    ok( $test_item2->onloan, "Item is checked out" );
405
406
    # Create rules to try to modify the withdrawn status
407
    my @withdrawal_rules = (
408
        {
409
            conditions => [
410
                {
411
                    field => "items.itemnumber",
412
                    value => $test_item2->itemnumber
413
                }
414
            ],
415
            substitutions => [
416
                {
417
                    field => "items.withdrawn",
418
                    value => 1
419
                }
420
            ]
421
        }
422
    );
423
424
    # Run ToggleNewStatus with the rules and catch errors in the report
425
    my $error_report = C4::Items::ToggleNewStatus(
426
        {
427
            rules       => \@withdrawal_rules,
428
            report_only => 0
429
        }
430
    );
431
432
    # Verify report structure
433
    ok( exists $error_report->{ $test_item2->itemnumber }, "Error item appears in report" );
434
435
    is( $test_item2->withdrawn, 0, 'Item should not be withdrawn' );
436
437
};
438
439
subtest "ToggleNewStatus in-transit error handling" => sub {
440
    plan tests => 3;
441
442
    # Create a new test item
443
    my $test_item3 = $builder->build_object( { class => 'Koha::Items' } );
444
445
    # Create a transfer to put item in-transit
446
    my $from_library = $builder->build_object( { class => 'Koha::Libraries' } );
447
    my $to_library   = $builder->build_object( { class => 'Koha::Libraries' } );
448
449
    my $transfer = Koha::Item::Transfer->new(
450
        {
451
            itemnumber => $test_item3->itemnumber,
452
            frombranch => $from_library->branchcode,
453
            tobranch   => $to_library->branchcode,
454
            datesent   => dt_from_string(),
455
        }
456
    )->store;
457
458
    # Mark transfer as in transit
459
    $transfer->datearrived(undef);
460
    $transfer->store;
461
462
    # Verify item is in transit
463
    my $item_transfer = $test_item3->get_transfer;
464
    ok( $item_transfer && !$item_transfer->datearrived, "Item is in transit" );
465
466
    # Create rules to try to modify the withdrawn status
467
    my @withdrawal_rules = (
468
        {
469
            conditions => [
470
                {
471
                    field => "items.itemnumber",
472
                    value => $test_item3->itemnumber
473
                }
474
            ],
475
            substitutions => [
476
                {
477
                    field => "items.withdrawn",
478
                    value => 1
479
                }
480
            ]
481
        }
482
    );
483
484
    # Run ToggleNewStatus with the rules and catch errors in the report
485
    my $error_report = C4::Items::ToggleNewStatus(
486
        {
487
            rules       => \@withdrawal_rules,
488
            report_only => 0
489
        }
490
    );
491
492
    # Verify report structure
493
    ok( exists $error_report->{ $test_item3->itemnumber }, "Error item appears in report" );
494
495
    is( $test_item3->withdrawn, 0, 'Item should not be withdrawn' );
496
};
497
394
# Run twice
498
# Run twice
395
t::lib::Mocks::mock_preference( 'CataloguingLog', 1 );
499
t::lib::Mocks::mock_preference( 'CataloguingLog', 1 );
396
my $actions_nb = $schema->resultset('ActionLog')->count();
500
my $actions_nb = $schema->resultset('ActionLog')->count();
397
- 

Return to bug 23010