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

(-)a/t/db_dependent/Koha/Hold.t (-2 / +92 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 14;
22
use Test::More tests => 15;
23
23
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 1089-1091 subtest 'change_type() tests' => sub { Link Here
1089
1089
1090
    $schema->storage->txn_rollback;
1090
    $schema->storage->txn_rollback;
1091
};
1091
};
1092
- 
1092
1093
subtest 'cancel() tests' => sub {
1094
1095
    plan tests => 12;
1096
1097
    $schema->storage->txn_begin;
1098
1099
    my $get_prepared_letter_called;
1100
1101
    # Mock GetPreparedLetter so it raises a warning we can look for
1102
    # and returns undef, so no call to EnqueueLetter happens
1103
    my $mocked_letter = Test::MockModule->new("C4::Letters");
1104
    $mocked_letter->mock( 'GetPreparedLetter', sub {
1105
        $get_prepared_letter_called = 1;
1106
        return;
1107
    });
1108
1109
    my $hold = $builder->build_object(
1110
        {
1111
            class => 'Koha::Holds',
1112
            value => {
1113
                cancellationdate    => undef,
1114
                priority            => 1,
1115
                cancellation_reason => undef,
1116
            }
1117
        }
1118
    );
1119
1120
    # leave this things out of the test
1121
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 0 );
1122
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
1123
1124
    $hold = $builder->build_object(
1125
        {
1126
            class => 'Koha::Holds',
1127
            value => {
1128
                cancellationdate    => undef,
1129
                priority            => 1,
1130
                cancellation_reason => undef,
1131
            }
1132
        }
1133
    );
1134
1135
    $get_prepared_letter_called = 0;
1136
    $hold->cancel({ cancellation_reason => 'Some reason' });
1137
    ok( !$get_prepared_letter_called, 'GetPreparedLetter not called' );
1138
1139
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
1140
    is( $hold->priority, 0, 'priority gets set to 0' );
1141
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
1142
1143
    $hold = $builder->build_object(
1144
        {
1145
            class => 'Koha::Holds',
1146
            value => {
1147
                cancellationdate    => undef,
1148
                priority            => 1,
1149
                cancellation_reason => undef,
1150
            }
1151
        }
1152
    );
1153
1154
    $get_prepared_letter_called = 0;
1155
    $hold->cancel({ cancellation_reason => 'Some reason', notify_patron => 1 });
1156
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron and cancellation_reason passed' );
1157
1158
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
1159
    is( $hold->priority, 0, 'priority gets set to 0' );
1160
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
1161
1162
    $hold = $builder->build_object(
1163
        {
1164
            class => 'Koha::Holds',
1165
            value => {
1166
                cancellationdate    => undef,
1167
                priority            => 1,
1168
                cancellation_reason => undef,
1169
            }
1170
        }
1171
    );
1172
1173
    $get_prepared_letter_called = 0;
1174
    $hold->cancel({ notify_patron => 1 });
1175
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron passed' );
1176
1177
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
1178
    is( $hold->priority, 0, 'priority gets set to 0' );
1179
    is( $hold->cancellation_reason, undef, 'cancellation_reason not passed' );
1180
1181
    $schema->storage->txn_rollback;
1182
};

Return to bug 26282