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

(-)a/t/db_dependent/Koha/Hold.t (-2 / +93 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 10;
23
23
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
use Test::Warn;
26
27
27
use t::lib::Mocks;
28
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
Lines 863-865 subtest 'cancellation_requestable_from_opac() tests' => sub { Link Here
863
864
864
    $schema->storage->txn_rollback;
865
    $schema->storage->txn_rollback;
865
};
866
};
866
- 
867
868
subtest 'cancel() tests' => sub {
869
870
    plan tests => 12;
871
872
    $schema->storage->txn_begin;
873
874
    my $get_prepared_letter_called;
875
876
    # Mock GetPreparedLetter so it raises a warning we can look for
877
    # and returns undef, so no call to EnqueueLetter happens
878
    my $mocked_letter = Test::MockModule->new("C4::Letters");
879
    $mocked_letter->mock( 'GetPreparedLetter', sub {
880
        $get_prepared_letter_called = 1;
881
        return;
882
    });
883
884
    my $hold = $builder->build_object(
885
        {
886
            class => 'Koha::Holds',
887
            value => {
888
                cancellationdate    => undef,
889
                priority            => 1,
890
                cancellation_reason => undef,
891
            }
892
        }
893
    );
894
895
    # leave this things out of the test
896
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 0 );
897
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
898
899
    $hold = $builder->build_object(
900
        {
901
            class => 'Koha::Holds',
902
            value => {
903
                cancellationdate    => undef,
904
                priority            => 1,
905
                cancellation_reason => undef,
906
            }
907
        }
908
    );
909
910
    $get_prepared_letter_called = 0;
911
    $hold->cancel({ cancellation_reason => 'Some reason' });
912
    ok( !$get_prepared_letter_called, 'GetPreparedLetter not called' );
913
914
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
915
    is( $hold->priority, 0, 'priority gets set to 0' );
916
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
917
918
    $hold = $builder->build_object(
919
        {
920
            class => 'Koha::Holds',
921
            value => {
922
                cancellationdate    => undef,
923
                priority            => 1,
924
                cancellation_reason => undef,
925
            }
926
        }
927
    );
928
929
    $get_prepared_letter_called = 0;
930
    $hold->cancel({ cancellation_reason => 'Some reason', notify_patron => 1 });
931
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron and cancellation_reason passed' );
932
933
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
934
    is( $hold->priority, 0, 'priority gets set to 0' );
935
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
936
937
    $hold = $builder->build_object(
938
        {
939
            class => 'Koha::Holds',
940
            value => {
941
                cancellationdate    => undef,
942
                priority            => 1,
943
                cancellation_reason => undef,
944
            }
945
        }
946
    );
947
948
    $get_prepared_letter_called = 0;
949
    $hold->cancel({ notify_patron => 1 });
950
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron passed' );
951
952
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
953
    is( $hold->priority, 0, 'priority gets set to 0' );
954
    is( $hold->cancellation_reason, undef, 'cancellation_reason not passed' );
955
956
    $schema->storage->txn_rollback;
957
};

Return to bug 26282