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

(-)a/t/db_dependent/Illrequest/SupplierUpdate.t (+64 lines)
Line 0 Link Here
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
);
(-)a/t/db_dependent/Illrequest/SupplierUpdateProcessor.t (+37 lines)
Line 0 Link Here
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 Koha::Illrequest::SupplierUpdateProcessor;
21
22
use Test::More tests => 3;
23
use Test::Warn;
24
25
my $processor = Koha::Illrequest::SupplierUpdateProcessor->new(
26
    'test_type',
27
    'test_name',
28
    'Test processor name'
29
);
30
31
use_ok('Koha::Illrequest::SupplierUpdateProcessor');
32
33
isa_ok( $processor, 'Koha::Illrequest::SupplierUpdateProcessor' );
34
35
warning_like {
36
    $processor->run()
37
} qr/run should only be invoked by a subclass/, 'Invoking base class "run" warns';
(-)a/t/db_dependent/Illrequests.t (-2 / +65 lines)
Lines 799-804 subtest 'Backend core methods' => sub { Link Here
799
              },
799
              },
800
              "Backend confirm: arbitrary stage.");
800
              "Backend confirm: arbitrary stage.");
801
801
802
    # backend_get_update
803
    $backend->mock(
804
        'get_supplier_update',
805
        sub {
806
            my ( $self, $options ) = @_;
807
            return $options;
808
        }
809
    );
810
    $backend->mock('capabilities', sub { return sub { return 1; } });
811
    is_deeply($illrq->backend_get_update({}), 1,
812
              "Backend get_update method.");
813
802
    $config->set_always('partner_code', "ILLTSTLIB");
814
    $config->set_always('partner_code', "ILLTSTLIB");
803
    $backend->set_always('metadata', { Test => "Foobar" });
815
    $backend->set_always('metadata', { Test => "Foobar" });
804
    my $illbrn = $builder->build({
816
    my $illbrn = $builder->build({
Lines 838-844 subtest 'Backend core methods' => sub { Link Here
838
850
839
subtest 'Helpers' => sub {
851
subtest 'Helpers' => sub {
840
852
841
    plan tests => 21;
853
    plan tests => 25;
842
854
843
    $schema->storage->txn_begin;
855
    $schema->storage->txn_begin;
844
856
Lines 882-887 subtest 'Helpers' => sub { Link Here
882
    $illrq_obj->_config($config);
894
    $illrq_obj->_config($config);
883
    $illrq_obj->_backend($backend);
895
    $illrq_obj->_backend($backend);
884
896
897
    #attach_processors
898
    my $type = 'test_type_1';
899
    my $name = 'test_name_1';
900
    my $update = Test::MockObject->new;
901
    $update->set_isa('Koha::Illrequest::SupplierUpdate');
902
    $update->{source_type} = $type;
903
    $update->{source_name} = $name;
904
    $update->{processors} = [];
905
    $update->mock('attach_processor', sub {
906
        my ( $self, $to_attach ) = @_;
907
        push @{$self->{processors}}, $to_attach;
908
    });
909
    my $processor = Test::MockObject->new;
910
    $processor->{target_source_type} = $type;
911
    $processor->{target_source_name} = $name;
912
    $illrq_obj->init_processors();
913
    $illrq_obj->push_processor($processor);
914
    $illrq_obj->attach_processors($update);
915
    is_deeply(
916
        scalar @{$update->{processors}},
917
        1,
918
        'attaching processors as appropriate works'
919
    );
920
885
    # getPrefix
921
    # getPrefix
886
    $config->set_series('getPrefixes',
922
    $config->set_series('getPrefixes',
887
                        { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
923
                        { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
Lines 933-938 subtest 'Helpers' => sub { Link Here
933
    );
969
    );
934
    is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created");
970
    is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created");
935
971
972
    # ill update notice, passes additional text parameter
973
    my $attr_update = Koha::MessageAttributes->find({ message_name => 'Ill_update' });
974
    C4::Members::Messaging::SetMessagingPreference({
975
        borrowernumber => $patron->{borrowernumber},
976
        message_attribute_id => $attr_update->message_attribute_id,
977
        message_transport_types => ['email']
978
    });
979
    my $return_patron_update = $illrq_obj->send_patron_notice('ILL_REQUEST_UPDATE', 'Some additional text');
980
    my $notice_update = $schema->resultset('MessageQueue')->search({
981
            letter_code => 'ILL_REQUEST_UPDATE',
982
            message_transport_type => 'email',
983
            borrowernumber => $illrq_obj->borrowernumber
984
        })->next()->letter_code;
985
    is_deeply(
986
        $return_patron_update,
987
        { result => { success => ['email'], fail => [] } },
988
        "Correct return when notice created"
989
    );
990
    is($notice_update, 'ILL_REQUEST_UPDATE' ,"Notice is correctly created");
991
992
936
    my $return_patron_fail = $illrq_obj->send_patron_notice();
993
    my $return_patron_fail = $illrq_obj->send_patron_notice();
937
    is_deeply(
994
    is_deeply(
938
        $return_patron_fail,
995
        $return_patron_fail,
Lines 1013-1018 subtest 'Helpers' => sub { Link Here
1013
        'Correct content returned from get_notice with metadata correctly ordered'
1070
        'Correct content returned from get_notice with metadata correctly ordered'
1014
    );
1071
    );
1015
1072
1073
    $illrq_obj->append_to_note('Some text');
1074
    like(
1075
        $illrq_obj->notesstaff,
1076
        qr/Some text$/,
1077
        'appending to a note works'
1078
    );
1079
1016
    $schema->storage->txn_rollback;
1080
    $schema->storage->txn_rollback;
1017
};
1081
};
1018
1082
1019
- 

Return to bug 30484