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

(-)a/t/db_dependent/Koha/Holds.t (-2 / +69 lines)
Lines 20-25 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 1;
23
use Test::Warn;
23
24
24
use C4::Reserves;
25
use C4::Reserves;
25
use Koha::Holds;
26
use Koha::Holds;
Lines 34-40 $schema->storage->txn_begin; Link Here
34
my $builder = t::lib::TestBuilder->new;
35
my $builder = t::lib::TestBuilder->new;
35
36
36
subtest 'cancel' => sub {
37
subtest 'cancel' => sub {
37
    plan tests => 10;
38
    plan tests => 12;
38
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
39
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
39
    my $library    = $builder->build_object( { class => 'Koha::Libraries' } );
40
    my $library    = $builder->build_object( { class => 'Koha::Libraries' } );
40
    my $itemtype   = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } );
41
    my $itemtype   = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } );
Lines 147-152 subtest 'cancel' => sub { Link Here
147
        my $hold_old = Koha::Old::Holds->find( $reserve_id );
148
        my $hold_old = Koha::Old::Holds->find( $reserve_id );
148
        is( $hold_old->found, 'W', 'The found column should have been kept and a hold is cancelled' );
149
        is( $hold_old->found, 'W', 'The found column should have been kept and a hold is cancelled' );
149
    };
150
    };
151
152
    subtest 'HoldsLog' => sub {
153
        plan tests => 2;
154
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
155
        my @hold_info = (
156
            $library->branchcode, $patron->borrowernumber,
157
            $item->biblionumber,  '',
158
            1,                    undef,
159
            undef,                '',
160
            "title for fee",      $item->itemnumber,
161
        );
162
163
        t::lib::Mocks::mock_preference('HoldsLog', 0);
164
        my $reserve_id = C4::Reserves::AddReserve(@hold_info);
165
        Koha::Holds->find( $reserve_id )->cancel;
166
        my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count;
167
        is( $number_of_logs, 0, 'Without HoldsLog, Koha::Hold->cancel should not have logged' );
168
169
        t::lib::Mocks::mock_preference('HoldsLog', 1);
170
        $reserve_id = C4::Reserves::AddReserve(@hold_info);
171
        Koha::Holds->find( $reserve_id )->cancel;
172
        $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )->count;
173
        is( $number_of_logs, 1, 'With HoldsLog, Koha::Hold->cancel should have logged' );
174
    };
175
176
    subtest 'rollback' => sub {
177
        plan tests => 3;
178
        my $patron_category = $builder->build_object(
179
            {
180
                class => 'Koha::Patron::Categories',
181
                value => { reservefee => 0 }
182
            }
183
        );
184
        my $patron = $builder->build_object(
185
            {
186
                class => 'Koha::Patrons',
187
                value => { categorycode => $patron_category->categorycode }
188
            }
189
        );
190
        my @hold_info = (
191
            $library->branchcode, $patron->borrowernumber,
192
            $item->biblionumber,  '',
193
            1,                    undef,
194
            undef,                '',
195
            "title for fee",      $item->itemnumber,
196
        );
197
198
        t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge',42 );
199
        my $reserve_id = C4::Reserves::AddReserve(@hold_info);
200
        my $hold       = Koha::Holds->find($reserve_id);
201
202
        # Add a row with the same id to make the cancel fails
203
        Koha::Old::Hold->new( $hold->unblessed )->store;
204
205
        warning_like {
206
            eval { $hold->cancel( { charge_cancel_fee => 1 } ) };
207
        }
208
        qr{.*DBD::mysql::st execute failed: Duplicate entry.*},
209
          'DBD should have raised an error about dup primary key';
210
211
        $hold = Koha::Holds->find($reserve_id);
212
        is( ref($hold), 'Koha::Hold', 'The hold should not have been deleted' );
213
        is( $patron->account->balance, 0,
214
'If the hold has not been cancelled, the patron should not have been charged'
215
        );
216
    };
217
150
};
218
};
151
219
152
$schema->storage->txn_rollback;
220
$schema->storage->txn_rollback;
153
- 

Return to bug 19059