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

(-)a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteBiblio.t (-1 / +84 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
use Test::MockModule;
22
23
use JSON qw( encode_json );
24
25
use C4::Reserves qw(AddReserve);
26
27
use Koha::Database;
28
use Koha::BackgroundJob::BatchDeleteBiblio;
29
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue;
30
31
use t::lib::TestBuilder;
32
33
my $schema = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
35
36
subtest "process() tests" => sub {
37
38
    plan tests => 1;
39
40
    $schema->storage->txn_begin;
41
42
    my $biblio = $builder->build_sample_biblio;
43
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id });
44
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id });
45
46
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
47
    AddReserve(
48
        {
49
            borrowernumber => $patron->id,
50
            biblionumber   => $biblio->id,
51
            itemnumber     => $item_1->id,
52
            branchcode     => $patron->branchcode
53
        }
54
    );
55
56
    my $counter = 0;
57
58
    my $mock_holds_queue_job = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
59
    $mock_holds_queue_job->mock( 'enqueue', sub {
60
        $counter++;
61
    });
62
63
    my $job = Koha::BackgroundJob::BatchDeleteBiblio->new(
64
        {
65
            status         => 'new',
66
            size           => 1,
67
            borrowernumber => undef,
68
            type           => 'batch_biblio_record_deletion',
69
            data           => encode_json {
70
                record_ids     => [ $biblio->id ],
71
            }
72
        }
73
    );
74
75
    $job->process(
76
        {
77
            record_ids => [ $biblio->id ],
78
        }
79
    );
80
81
    is( $counter, 1, 'Holds queue update is enqueued only once' );
82
83
    $schema->storage->txn_rollback;
84
};

Return to bug 30727