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

(-)a/t/db_dependent/Koha/Hold.t (-2 / +95 lines)
Lines 19-26 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
use Test::MockModule;
24
use Test::Warn;
23
25
26
use t::lib::Mocks;
24
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
25
28
26
my $schema  = Koha::Database->new->schema;
29
my $schema  = Koha::Database->new->schema;
Lines 48-50 subtest 'patron() tests' => sub { Link Here
48
51
49
    $schema->storage->txn_rollback;
52
    $schema->storage->txn_rollback;
50
};
53
};
51
- 
54
55
subtest 'cancel() tests' => sub {
56
57
    plan tests => 12;
58
59
    $schema->storage->txn_begin;
60
61
    my $get_prepared_letter_called;
62
63
    # Mock GetPreparedLetter so it raises a warning we can look for
64
    # and returns undef, so no call to EnqueueLetter happens
65
    my $mocked_letter = Test::MockModule->new("C4::Letters");
66
    $mocked_letter->mock( 'GetPreparedLetter', sub {
67
        $get_prepared_letter_called = 1;
68
        return;
69
    });
70
71
    my $hold = $builder->build_object(
72
        {
73
            class => 'Koha::Holds',
74
            value => {
75
                cancellationdate    => undef,
76
                priority            => 1,
77
                cancellation_reason => undef,
78
            }
79
        }
80
    );
81
82
    # leave this things out of the test
83
    t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', 0 );
84
    t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
85
86
    $hold = $builder->build_object(
87
        {
88
            class => 'Koha::Holds',
89
            value => {
90
                cancellationdate    => undef,
91
                priority            => 1,
92
                cancellation_reason => undef,
93
            }
94
        }
95
    );
96
97
    $get_prepared_letter_called = 0;
98
    $hold->cancel({ cancellation_reason => 'Some reason' });
99
    ok( !$get_prepared_letter_called, 'GetPreparedLetter not called' );
100
101
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
102
    is( $hold->priority, 0, 'priority gets set to 0' );
103
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
104
105
    $hold = $builder->build_object(
106
        {
107
            class => 'Koha::Holds',
108
            value => {
109
                cancellationdate    => undef,
110
                priority            => 1,
111
                cancellation_reason => undef,
112
            }
113
        }
114
    );
115
116
    $get_prepared_letter_called = 0;
117
    $hold->cancel({ cancellation_reason => 'Some reason', notify_patron => 1 });
118
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron and cancellation_reason passed' );
119
120
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
121
    is( $hold->priority, 0, 'priority gets set to 0' );
122
    is( $hold->cancellation_reason, 'Some reason', 'cancellation_reason is set to the passed value' );
123
124
    $hold = $builder->build_object(
125
        {
126
            class => 'Koha::Holds',
127
            value => {
128
                cancellationdate    => undef,
129
                priority            => 1,
130
                cancellation_reason => undef,
131
            }
132
        }
133
    );
134
135
    $get_prepared_letter_called = 0;
136
    $hold->cancel({ notify_patron => 1 });
137
    ok( $get_prepared_letter_called, 'GetPreparedLetter called if notify_patron passed' );
138
139
    isnt( $hold->cancellationdate, undef, 'cancellationdate gets set to the passed value' );
140
    is( $hold->priority, 0, 'priority gets set to 0' );
141
    is( $hold->cancellation_reason, undef, 'cancellation_reason not passed' );
142
143
    $schema->storage->txn_rollback;
144
};

Return to bug 26282