Bug 35167: Regression tests
[koha.git] / t / db_dependent / Illrequest / SupplierUpdate.t
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::MockObject;
21
22 use Koha::Illrequest;
23 use Koha::Illrequest::SupplierUpdate;
24
25 use Test::More tests => 4;
26
27 use_ok('Koha::Illrequest::SupplierUpdate');
28
29 my $update = Koha::Illrequest::SupplierUpdate->new(
30     'test_type',
31     'test_name',
32     'Arbitrary update text'
33 );
34
35 isa_ok( $update, 'Koha::Illrequest::SupplierUpdate' );
36
37 my $processor = Test::MockObject->new;
38 $processor->set_isa('Koha::Illrequest::Processor');
39 $processor->{name} = 'Test processor';
40 $processor->mock('run', sub {
41     my ( $self, $update, $options, $result ) = @_;
42     push @{$result->{success}}, 'Hello';
43 });
44
45 # attach_processor
46 $update->attach_processor($processor);
47 is(
48     scalar @{$update->{processors}},
49     1,
50     'attach_processors works'
51 );
52
53 # run_processors
54 is_deeply(
55     $update->run_processors({}),
56     [{
57         name => 'Test processor',
58         result => {
59             success => ['Hello'],
60             error => []
61         }
62     }],
63     'run_processors calls attached processors'
64 );