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, $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 (-4 / +69 lines)
Lines 636-642 subtest 'Backend testing (mocks)' => sub { Link Here
636
636
637
subtest 'Backend core methods' => sub {
637
subtest 'Backend core methods' => sub {
638
638
639
    plan tests => 19;
639
    plan tests => 20;
640
640
641
    $schema->storage->txn_begin;
641
    $schema->storage->txn_begin;
642
642
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, $delay ) = @_;
807
            return {
808
                delay => $delay
809
            }
810
        }
811
    );
812
    $backend->mock('capabilities', sub { return sub { return 1; } });
813
    is_deeply($illrq->backend_get_update(), 1,
814
              "Backend get_update method.");
815
802
    $config->set_always('partner_code', "ILLTSTLIB");
816
    $config->set_always('partner_code', "ILLTSTLIB");
803
    $backend->set_always('metadata', { Test => "Foobar" });
817
    $backend->set_always('metadata', { Test => "Foobar" });
804
    my $illbrn = $builder->build({
818
    my $illbrn = $builder->build({
Lines 838-844 subtest 'Backend core methods' => sub { Link Here
838
852
839
subtest 'Helpers' => sub {
853
subtest 'Helpers' => sub {
840
854
841
    plan tests => 21;
855
    plan tests => 25;
842
856
843
    $schema->storage->txn_begin;
857
    $schema->storage->txn_begin;
844
858
Lines 882-887 subtest 'Helpers' => sub { Link Here
882
    $illrq_obj->_config($config);
896
    $illrq_obj->_config($config);
883
    $illrq_obj->_backend($backend);
897
    $illrq_obj->_backend($backend);
884
898
899
    #attach_processors
900
    my $type = 'test_type_1';
901
    my $name = 'test_name_1';
902
    my $update = Test::MockObject->new;
903
    $update->set_isa('Koha::Illrequest::SupplierUpdate');
904
    $update->{source_type} = $type;
905
    $update->{source_name} = $name;
906
    $update->{processors} = [];
907
    $update->mock('attach_processor', sub {
908
        my ( $self, $to_attach ) = @_;
909
        push @{$self->{processors}}, $to_attach;
910
    });
911
    my $processor = Test::MockObject->new;
912
    $processor->{target_source_type} = $type;
913
    $processor->{target_source_name} = $name;
914
    $illrq_obj->init_processors();
915
    $illrq_obj->push_processor($processor);
916
    $illrq_obj->attach_processors($update);
917
    is_deeply(
918
        scalar @{$update->{processors}},
919
        1,
920
        'attaching processors as appropriate works'
921
    );
922
885
    # getPrefix
923
    # getPrefix
886
    $config->set_series('getPrefixes',
924
    $config->set_series('getPrefixes',
887
                        { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
925
                        { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
Lines 933-938 subtest 'Helpers' => sub { Link Here
933
    );
971
    );
934
    is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created");
972
    is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created");
935
973
974
    # ill update notice, passes additional text parameter
975
    my $attr_update = Koha::MessageAttributes->find({ message_name => 'Ill_update' });
976
    C4::Members::Messaging::SetMessagingPreference({
977
        borrowernumber => $patron->{borrowernumber},
978
        message_attribute_id => $attr_update->message_attribute_id,
979
        message_transport_types => ['email']
980
    });
981
    my $return_patron_update = $illrq_obj->send_patron_notice('ILL_REQUEST_UPDATE', 'Some additional text');
982
    my $notice_update = $schema->resultset('MessageQueue')->search({
983
            letter_code => 'ILL_REQUEST_UPDATE',
984
            message_transport_type => 'email',
985
            borrowernumber => $illrq_obj->borrowernumber
986
        })->next()->letter_code;
987
    is_deeply(
988
        $return_patron_update,
989
        { result => { success => ['email'], fail => [] } },
990
        "Correct return when notice created"
991
    );
992
    is($notice_update, 'ILL_REQUEST_UPDATE' ,"Notice is correctly created");
993
994
936
    my $return_patron_fail = $illrq_obj->send_patron_notice();
995
    my $return_patron_fail = $illrq_obj->send_patron_notice();
937
    is_deeply(
996
    is_deeply(
938
        $return_patron_fail,
997
        $return_patron_fail,
Lines 1013-1018 subtest 'Helpers' => sub { Link Here
1013
        'Correct content returned from get_notice with metadata correctly ordered'
1072
        'Correct content returned from get_notice with metadata correctly ordered'
1014
    );
1073
    );
1015
1074
1075
    $illrq_obj->append_to_note('Some text');
1076
    like(
1077
        $illrq_obj->notesstaff,
1078
        qr/Some text$/,
1079
        'appending to a note works'
1080
    );
1081
1016
    $schema->storage->txn_rollback;
1082
    $schema->storage->txn_rollback;
1017
};
1083
};
1018
1084
Lines 1460-1463 subtest 'Checking in hook' => sub { Link Here
1460
    is( $illrq->status, 'RET' );
1526
    is( $illrq->status, 'RET' );
1461
1527
1462
    $schema->storage->txn_rollback;
1528
    $schema->storage->txn_rollback;
1463
};
1529
};
1464
- 

Return to bug 30484