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

(-)a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t (-1 / +73 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 Koha::Database;
26
use Koha::BackgroundJob::BatchDeleteItem;
27
28
use t::lib::TestBuilder;
29
30
my $schema = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
subtest "process() tests" => sub {
34
35
    plan tests => 1;
36
37
    $schema->storage->txn_begin;
38
39
    my $biblio = $builder->build_sample_biblio;
40
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id });
41
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id });
42
43
    my $counter = 0;
44
45
    my $mock_holds_queue_job = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
46
    $mock_holds_queue_job->mock( 'enqueue', sub {
47
        $counter++;
48
    });
49
50
    my $job = Koha::BackgroundJob::BatchDeleteItem->new(
51
        {
52
            status         => 'new',
53
            size           => 2,
54
            borrowernumber => undef,
55
            type           => 'batch_biblio_record_modification',
56
            data           => encode_json {
57
                record_ids     => [ $item_1->id, $item_2->id ],
58
                delete_biblios => 1,
59
            }
60
        }
61
    );
62
63
    $job->process(
64
        {
65
            record_ids     => [ $item_1->id, $item_2->id ],
66
            delete_biblios => 1,
67
        }
68
    );
69
70
    is( $counter, 1, 'Holds queue update is enqueued only once' );
71
72
    $schema->storage->txn_rollback;
73
};

Return to bug 30710