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 (-3 / +66 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 => 18;
639
    plan tests => 19;
640
640
641
    $schema->storage->txn_begin;
641
    $schema->storage->txn_begin;
642
642
Lines 794-799 subtest 'Backend core methods' => sub { Link Here
794
              },
794
              },
795
              "Backend confirm: arbitrary stage.");
795
              "Backend confirm: arbitrary stage.");
796
796
797
    # backend_get_update
798
    $backend->mock(
799
        'get_supplier_update',
800
        sub {
801
            my ( $self, $options ) = @_;
802
            return $options;
803
        }
804
    );
805
    $backend->mock('capabilities', sub { return sub { return 1; } });
806
    is_deeply($illrq->backend_get_update({}), 1,
807
              "Backend get_update method.");
808
797
    $config->set_always('partner_code', "ILLTSTLIB");
809
    $config->set_always('partner_code', "ILLTSTLIB");
798
    $backend->set_always('metadata', { Test => "Foobar" });
810
    $backend->set_always('metadata', { Test => "Foobar" });
799
    my $illbrn = $builder->build({
811
    my $illbrn = $builder->build({
Lines 833-839 subtest 'Backend core methods' => sub { Link Here
833
845
834
subtest 'Helpers' => sub {
846
subtest 'Helpers' => sub {
835
847
836
    plan tests => 21;
848
    plan tests => 25;
837
849
838
    $schema->storage->txn_begin;
850
    $schema->storage->txn_begin;
839
851
Lines 877-882 subtest 'Helpers' => sub { Link Here
877
    $illrq_obj->_config($config);
889
    $illrq_obj->_config($config);
878
    $illrq_obj->_backend($backend);
890
    $illrq_obj->_backend($backend);
879
891
892
    #attach_processors
893
    my $type = 'test_type_1';
894
    my $name = 'test_name_1';
895
    my $update = Test::MockObject->new;
896
    $update->set_isa('Koha::Illrequest::SupplierUpdate');
897
    $update->{source_type} = $type;
898
    $update->{source_name} = $name;
899
    $update->{processors} = [];
900
    $update->mock('attach_processor', sub {
901
        my ( $self, $to_attach ) = @_;
902
        push @{$self->{processors}}, $to_attach;
903
    });
904
    my $processor = Test::MockObject->new;
905
    $processor->{target_source_type} = $type;
906
    $processor->{target_source_name} = $name;
907
    $illrq_obj->init_processors();
908
    $illrq_obj->push_processor($processor);
909
    $illrq_obj->attach_processors($update);
910
    is_deeply(
911
        scalar @{$update->{processors}},
912
        1,
913
        'attaching processors as appropriate works'
914
    );
915
880
    # getPrefix
916
    # getPrefix
881
    $config->set_series('getPrefixes',
917
    $config->set_series('getPrefixes',
882
                        { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
918
                        { HDE => "TEST", TSL => "BAR", default => "DEFAULT" },
Lines 928-933 subtest 'Helpers' => sub { Link Here
928
    );
964
    );
929
    is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created");
965
    is($notice, 'ILL_PICKUP_READY' ,"Notice is correctly created");
930
966
967
    # ill update notice, passes additional text parameter
968
    my $attr_update = Koha::MessageAttributes->find({ message_name => 'Ill_update' });
969
    C4::Members::Messaging::SetMessagingPreference({
970
        borrowernumber => $patron->{borrowernumber},
971
        message_attribute_id => $attr_update->message_attribute_id,
972
        message_transport_types => ['email']
973
    });
974
    my $return_patron_update = $illrq_obj->send_patron_notice('ILL_REQUEST_UPDATE', 'Some additional text');
975
    my $notice_update = $schema->resultset('MessageQueue')->search({
976
            letter_code => 'ILL_REQUEST_UPDATE',
977
            message_transport_type => 'email',
978
            borrowernumber => $illrq_obj->borrowernumber
979
        })->next()->letter_code;
980
    is_deeply(
981
        $return_patron_update,
982
        { result => { success => ['email'], fail => [] } },
983
        "Correct return when notice created"
984
    );
985
    is($notice_update, 'ILL_REQUEST_UPDATE' ,"Notice is correctly created");
986
987
931
    my $return_patron_fail = $illrq_obj->send_patron_notice();
988
    my $return_patron_fail = $illrq_obj->send_patron_notice();
932
    is_deeply(
989
    is_deeply(
933
        $return_patron_fail,
990
        $return_patron_fail,
Lines 1008-1013 subtest 'Helpers' => sub { Link Here
1008
        'Correct content returned from get_notice with metadata correctly ordered'
1065
        'Correct content returned from get_notice with metadata correctly ordered'
1009
    );
1066
    );
1010
1067
1068
    $illrq_obj->append_to_note('Some text');
1069
    like(
1070
        $illrq_obj->notesstaff,
1071
        qr/Some text$/,
1072
        'appending to a note works'
1073
    );
1074
1011
    $schema->storage->txn_rollback;
1075
    $schema->storage->txn_rollback;
1012
};
1076
};
1013
1077
1014
- 

Return to bug 30484