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

(-)a/t/db_dependent/Illrequest/Logger.t (-1 / +44 lines)
Lines 24-31 use Test::More tests => 2; Link Here
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::MockObject;
25
use Test::MockObject;
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
27
28
28
my $schema = Koha::Database->new->schema;
29
my $schema = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
29
31
30
# A mock response from C4::Log::GetLogs()
32
# A mock response from C4::Log::GetLogs()
31
my $logs = [
33
my $logs = [
Lines 43-48 my $logs = [ Link Here
43
        info      => '{"log_origin": "core"}',
45
        info      => '{"log_origin": "core"}',
44
        action    => 'STATUS_CHANGE',
46
        action    => 'STATUS_CHANGE',
45
        timestamp => '2018-10-02 11:12:32'
47
        timestamp => '2018-10-02 11:12:32'
48
    },
49
    {
50
        info      => '{"status_before":"GENREQ","log_origin":"core","additional":{"partner_email_previous":"me@nowhere.com","partner_email_now":"you@nowhere.com"},"status_after":"GENREQ"}',
51
        action    => 'STATUS_CHANGE',
52
        timestamp => '2018-10-02 11:12:42'
46
    }
53
    }
47
];
54
];
48
# Mock the modules we use
55
# Mock the modules we use
Lines 57-63 use_ok('Koha::Illrequest::Logger'); Link Here
57
64
58
subtest 'Basics' => sub {
65
subtest 'Basics' => sub {
59
66
60
    plan tests => 7;
67
    plan tests => 9;
61
68
62
    $schema->storage->txn_begin;
69
    $schema->storage->txn_begin;
63
70
Lines 112-117 subtest 'Basics' => sub { Link Here
112
        'get_log_template() fetches correct core template'
119
        'get_log_template() fetches correct core template'
113
    );
120
    );
114
121
122
    # logged_requested_partners
123
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
124
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
125
    my $illrq = $builder->build_object({
126
        class => 'Koha::Illrequests',
127
        value => { borrowernumber => 123 }
128
    });
129
    my $config = Test::MockObject->new;
130
    $config->set_always('partner_code', $categorycode);
131
    $illrq->_config($config);
132
    Koha::Patron->new(
133
        {
134
            surname      => 'Test 1',
135
            email        => 'me@nowhere.com',
136
            categorycode => $categorycode,
137
            branchcode   => $branchcode
138
        }
139
    )->store();
140
    my $returned = Koha::Illrequest::Logger::_logged_requested_partners({
141
        request => $illrq,
142
        info => {
143
            log_origin => "core",
144
            status_before => "GENREQ",
145
            status_after => "GENREQ",
146
            additional => {
147
                partner_email_previous => 'me@nowhere.com',
148
                partner_email_now => 'you@nowhere.com'
149
            }
150
        }
151
    });
152
    isa_ok($returned, 'HASH',
153
        'logged_requested_partners returns a hasref'
154
    );
155
    is($returned->{'me@nowhere.com'}->{surname}, 'Test 1',
156
        'logged_requested_partners returns full patron objects');
157
115
    $schema->storage->txn_rollback;
158
    $schema->storage->txn_rollback;
116
};
159
};
117
160
(-)a/t/db_dependent/Illrequests.t (-5 / +67 lines)
Lines 39-45 use_ok('Koha::Illrequests'); Link Here
39
39
40
subtest 'Basic object tests' => sub {
40
subtest 'Basic object tests' => sub {
41
41
42
    plan tests => 24;
42
    plan tests => 26;
43
43
44
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
45
45
Lines 111-116 subtest 'Basic object tests' => sub { Link Here
111
    is(Koha::Illrequests->search->count, 0,
111
    is(Koha::Illrequests->search->count, 0,
112
       "No illrequest found after delete.");
112
       "No illrequest found after delete.");
113
113
114
    $illrq_obj->status('REQ');
115
    is($illrq_obj->status, 'REQ',
116
        "status correctly handles strings");
117
118
    $illrq_obj->status({ status => 'NEW', additional => 'add'});
119
    is($illrq_obj->status, 'NEW',
120
        "status correctly handles hashrefs");
121
114
    $schema->storage->txn_rollback;
122
    $schema->storage->txn_rollback;
115
};
123
};
116
124
Lines 231-237 subtest 'Status Graph tests' => sub { Link Here
231
239
232
subtest 'Backend testing (mocks)' => sub {
240
subtest 'Backend testing (mocks)' => sub {
233
241
234
    plan tests => 13;
242
    plan tests => 16;
235
243
236
    $schema->storage->txn_begin;
244
    $schema->storage->txn_begin;
237
245
Lines 239-245 subtest 'Backend testing (mocks)' => sub { Link Here
239
    # the Dummy plugin installed.  load_backend & available_backends don't
247
    # the Dummy plugin installed.  load_backend & available_backends don't
240
    # currently have tests as a result.
248
    # currently have tests as a result.
241
249
242
    t::lib::Mocks->mock_config('interlibrary_loans', { backend_dir => 'a_dir' }  );
250
    my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
251
    my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
252
243
    my $backend = Test::MockObject->new;
253
    my $backend = Test::MockObject->new;
244
    $backend->set_isa('Koha::Illbackends::Mock');
254
    $backend->set_isa('Koha::Illbackends::Mock');
245
    $backend->set_always('name', 'Mock');
255
    $backend->set_always('name', 'Mock');
Lines 250-256 subtest 'Backend testing (mocks)' => sub { Link Here
250
        value => { borrowernumber => $patron->{borrowernumber} }
260
        value => { borrowernumber => $patron->{borrowernumber} }
251
    });
261
    });
252
262
263
    my $config = Test::MockObject->new;
264
    $config->set_always('partner_code', $categorycode);
265
    $config->set_always('backend_dir', 'a_dir');
266
253
    $illrq->_backend($backend);
267
    $illrq->_backend($backend);
268
    $illrq->_config($config);
254
269
255
    isa_ok($illrq->_backend, 'Koha::Illbackends::Mock',
270
    isa_ok($illrq->_backend, 'Koha::Illbackends::Mock',
256
           "OK accessing mocked backend.");
271
           "OK accessing mocked backend.");
Lines 297-302 subtest 'Backend testing (mocks)' => sub { Link Here
297
        "Test metadata."
312
        "Test metadata."
298
    );
313
    );
299
314
315
    $backend->mock(
316
        'capabilities',
317
        sub {
318
            my ($self, $name) = @_;
319
            if ($name eq 'get_requested_partners') {
320
                return sub {
321
                    return 'me@nowhere.com; you@nowhere.com';
322
                }
323
            }
324
        }
325
    );
326
    is($illrq->requested_partners, 'me@nowhere.com; you@nowhere.com',
327
        "requested_partners returns string by default");
328
329
    Koha::Patron->new(
330
        {
331
            surname      => 'Test 1',
332
            email        => 'me@nowhere.com',
333
            categorycode => $categorycode,
334
            branchcode   => $branchcode
335
        }
336
    )->store();
337
338
    Koha::Patron->new(
339
        {
340
            surname      => 'Test 2',
341
            email        => 'you@nowhere.com',
342
            categorycode => $categorycode,
343
            branchcode   => $branchcode
344
        }
345
    )->store();
346
347
	my $part = $illrq->requested_partners(1);
348
    isa_ok($part, 'ARRAY',
349
           "requested_partners returns array when requested");
350
    isa_ok(@{$part}[0], 'HASH',
351
           "requested_partners return array contains unblessed Koha patrons");
352
300
    # capabilities:
353
    # capabilities:
301
354
302
    # No backend graph extension
355
    # No backend graph extension
Lines 842-848 subtest 'Checking Limits' => sub { Link Here
842
895
843
subtest 'Custom statuses' => sub {
896
subtest 'Custom statuses' => sub {
844
897
845
    plan tests => 3;
898
    plan tests => 5;
846
899
847
    $schema->storage->txn_begin;
900
    $schema->storage->txn_begin;
848
901
Lines 890-894 subtest 'Custom statuses' => sub { Link Here
890
    is($ill_req->statusalias, undef,
943
    is($ill_req->statusalias, undef,
891
        "Koha::Illrequest->status overloading resetting status_alias");
944
        "Koha::Illrequest->status overloading resetting status_alias");
892
945
946
    $ill_req->status_alias($av->authorised_value);
947
    is($ill_req->status_alias, $av->authorised_value,
948
        "Koha::Illrequest->status_alias correctly handling string");
949
950
    $ill_req->status_alias(
951
        { status => $av->authorised_value, additional => 'xyz' }
952
    );
953
    is($ill_req->status_alias, $av->authorised_value,
954
        "Koha::Illrequest->status_alias correctly handling hashref");
955
893
    $schema->storage->txn_rollback;
956
    $schema->storage->txn_rollback;
894
};
957
};
895
- 

Return to bug 22531