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

(-)a/t/db_dependent/Koha/Item.t (-14 / +67 lines)
Lines 845-852 subtest 'deletion' => sub { Link Here
845
845
846
    AddReturn( $item->barcode, $library->branchcode );
846
    AddReturn( $item->barcode, $library->branchcode );
847
847
848
    # book_reserved is tested in t/db_dependent/Reserves.t
849
850
    # not_same_branch
848
    # not_same_branch
851
    t::lib::Mocks::mock_preference('IndependentBranches', 1);
849
    t::lib::Mocks::mock_preference('IndependentBranches', 1);
852
    my $item_2 = $builder->build_sample_item({ library => $library_2->branchcode });
850
    my $item_2 = $builder->build_sample_item({ library => $library_2->branchcode });
Lines 885-901 subtest 'deletion' => sub { Link Here
885
883
886
    }
884
    }
887
885
888
    { # last_item_for_hold
889
        C4::Reserves::AddReserve({ branchcode => $patron->branchcode, borrowernumber => $patron->borrowernumber, biblionumber => $item->biblionumber });
890
        is(
891
            @{$item->safe_to_delete->messages}[0]->message,
892
            'last_item_for_hold',
893
            'Item cannot be deleted if a biblio-level is placed on the biblio and there is only 1 item attached to the biblio'
894
        );
895
        # With another item attached to the biblio, the item can be deleted
896
        $builder->build_sample_item({ biblionumber => $item->biblionumber });
897
    }
898
899
    ok(
886
    ok(
900
        $item->safe_to_delete,
887
        $item->safe_to_delete,
901
        'Koha::Item->safe_to_delete shows item safe to delete'
888
        'Koha::Item->safe_to_delete shows item safe to delete'
Lines 909-914 subtest 'deletion' => sub { Link Here
909
        "Koha::Item->safe_delete should delete item if safe_to_delete returns true"
896
        "Koha::Item->safe_delete should delete item if safe_to_delete returns true"
910
    );
897
    );
911
898
899
    subtest 'holds tests' => sub {
900
901
        plan tests => 9;
902
903
        # to avoid noise
904
        t::lib::Mocks::mock_preference( 'IndependentBranches', 0 );
905
906
        $schema->storage->txn_begin;
907
908
        my $item = $builder->build_sample_item;
909
910
        my $processing     = $builder->build_object( { class => 'Koha::Holds', value => { itemnumber => $item->id, itemnumber => $item->id, found => 'P' } } );
911
        my $safe_to_delete = $item->safe_to_delete;
912
913
        ok( !$safe_to_delete, 'Cannot delete' );
914
        is(
915
            @{ $safe_to_delete->messages }[0]->message,
916
            'book_reserved',
917
            'Koha::Item->safe_to_delete reports a in processing hold blocks deletion'
918
        );
919
920
        $processing->delete;
921
922
        my $in_transit = $builder->build_object( { class => 'Koha::Holds', value => { itemnumber => $item->id, itemnumber => $item->id, found => 'T' } } );
923
        $safe_to_delete = $item->safe_to_delete;
924
925
        ok( !$safe_to_delete, 'Cannot delete' );
926
        is(
927
            @{ $safe_to_delete->messages }[0]->message,
928
            'book_reserved',
929
            'Koha::Item->safe_to_delete reports a in transit hold blocks deletion'
930
        );
931
932
        $in_transit->delete;
933
934
        my $waiting = $builder->build_object( { class => 'Koha::Holds', value => { itemnumber => $item->id, itemnumber => $item->id, found => 'W' } } );
935
        $safe_to_delete = $item->safe_to_delete;
936
937
        ok( !$safe_to_delete, 'Cannot delete' );
938
        is(
939
            @{ $safe_to_delete->messages }[0]->message,
940
            'book_reserved',
941
            'Koha::Item->safe_to_delete reports a waiting hold blocks deletion'
942
        );
943
944
        $waiting->delete;
945
946
        # Add am unfilled biblio-level hold to catch the 'last_item_for_hold' use case
947
        $builder->build_object( { class => 'Koha::Holds', value => { biblionumber => $item->biblionumber, itemnumber => undef, found => undef } } );
948
949
        $safe_to_delete = $item->safe_to_delete;
950
951
        ok( !$safe_to_delete );
952
953
        is(
954
            @{ $safe_to_delete->messages}[0]->message,
955
            'last_item_for_hold',
956
            'Item cannot be deleted if a biblio-level is placed on the biblio and there is only 1 item attached to the biblio'
957
        );
958
959
        my $extra_item = $builder->build_sample_item({ biblionumber => $item->biblionumber });
960
961
        ok( $item->safe_to_delete );
962
963
        $schema->storage->txn_rollback;
964
    };
965
912
    $schema->storage->txn_rollback;
966
    $schema->storage->txn_rollback;
913
};
967
};
914
968
915
- 

Return to bug 32529