Bugzilla – Attachment 84824 Details for
Bug 20750
Allow timestamped auditing of ILL request events
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20750: Add unit tests
Bug-20750-Add-unit-tests.patch (text/plain), 5.37 KB, created by
Andrew Isherwood
on 2019-02-06 15:07:47 UTC
(
hide
)
Description:
Bug 20750: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2019-02-06 15:07:47 UTC
Size:
5.37 KB
patch
obsolete
>From 670e386771868106c2226cc1d2fe85d053f45242 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Tue, 2 Oct 2018 14:56:53 +0100 >Subject: [PATCH] Bug 20750: Add unit tests > >--- > t/Log.t | 1 - > t/db_dependent/Illrequest/Logger.t | 155 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 155 insertions(+), 1 deletion(-) > create mode 100644 t/db_dependent/Illrequest/Logger.t > >diff --git a/t/Log.t b/t/Log.t >index d53386bc33..bfcd75a3af 100755 >--- a/t/Log.t >+++ b/t/Log.t >@@ -10,4 +10,3 @@ use Test::More tests => 1; > BEGIN { > use_ok('C4::Log'); > } >- >diff --git a/t/db_dependent/Illrequest/Logger.t b/t/db_dependent/Illrequest/Logger.t >new file mode 100644 >index 0000000000..a88fc7c485 >--- /dev/null >+++ b/t/db_dependent/Illrequest/Logger.t >@@ -0,0 +1,155 @@ >+ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+ >+use Test::More tests => 2; >+use Test::MockModule; >+use Test::MockObject; >+use t::lib::Mocks; >+ >+my $schema = Koha::Database->new->schema; >+ >+# A mock response from C4::Log::GetLogs() >+my $logs = [ >+ { >+ info => '{"log_origin": "core"}', >+ action => 'STATUS_CHANGE', >+ timestamp => 1538478742 >+ }, >+ { >+ info => '{"log_origin": "core"}', >+ action => 'STATUS_CHANGE', >+ timestamp => 1538478732 >+ }, >+ { >+ info => '{"log_origin": "core"}', >+ action => 'STATUS_CHANGE', >+ timestamp => 1538478752 >+ } >+]; >+# Mock the modules we use >+my $c4_log = Test::MockModule->new('C4::Log'); >+$c4_log->mock('logaction', sub { 1 }); >+$c4_log->mock('GetLogs', sub { return $logs; }); >+my $c4_tpl = Test::MockModule->new('C4::Templates'); >+$c4_tpl->mock('_get_template_file', >+ sub { return ('htdocs', 'theme', 'lang', 'base/'); }); >+ >+use_ok('Koha::Illrequest::Logger'); >+ >+subtest 'Basics' => sub { >+ >+ plan tests => 10; >+ >+ $schema->storage->txn_begin; >+ >+ my $logger = Koha::Illrequest::Logger->new; >+ >+ # new() >+ # >+ ok( defined($logger), 'new() returned something' ); >+ ok( $logger->isa('Koha::Illrequest::Logger'), >+ 'new() returns the correct object' ); >+ is_deeply($logger->{data}, {modulename => 'ILL'}, >+ 'new() setting modulename'); >+ >+ # This is an incomplete data hashref, we use it to >+ # test validation of the data before logging >+ my $log_obj = { >+ modulename => 'modulename', >+ actionname => 'actionname', >+ infos => 'infos' >+ }; >+ >+ # set_data() >+ # >+ $logger->set_data($log_obj); >+ is_deeply($logger->{data}->{actionname}, 'actionname', >+ 'set_data() setter works'); >+ >+ # log_something() >+ # >+ # Do we only log when the pref is set (currently unset) >+ is($logger->log_something(), '', >+ 'logaction() not being called without pref being set'); >+ >+ # Set the pref >+ t::lib::Mocks::mock_preference( 'IllLog', 1 ); >+ # We should not log without all the required data, we are still >+ # using the incomplete hashref >+ is($logger->log_something(), '', >+ 'logaction() being called when data is incomplete'); >+ >+ # Fix the data hashref, then test that logging occurs >+ $log_obj->{objectnumber} = 'objectnumber'; >+ $logger->set_data($log_obj); >+ is($logger->log_something(), 1, >+ 'logaction() being called when pref is set and data is complete'); >+ >+ # log_maybe() >+ # >+ is($logger->log_maybe({}, {}), '', >+ 'log_maybe() does not log with incomplete data'); >+ >+ # get_log_template() >+ # >+ is( >+ $logger->get_log_template( >+ {}, >+ { origin => 'core', 'action' => 'STATUS_CHANGE' } >+ ), >+ 'base/status_change.tt', >+ 'get_log_template() fetches correct core template' >+ ); >+ >+ # get_request_logs >+ # >+ my $res_obj = [ >+ { >+ 'template' => 'mock', >+ 'info' => { 'log_origin' => 'core' }, >+ 'timestamp' => 1538478752, >+ 'action' => 'STATUS_CHANGE' >+ }, >+ { >+ 'template' => 'mock', >+ 'action' => 'STATUS_CHANGE', >+ 'timestamp' => 1538478742, >+ 'info' => { 'log_origin' => 'core' } >+ }, >+ { >+ 'template' => 'mock', >+ 'action' => 'STATUS_CHANGE', >+ 'info' => { 'log_origin' => 'core' }, >+ 'timestamp' => 1538478732 >+ } >+ ]; >+ my $me_mock = Test::MockModule->new('Koha::Illrequest::Logger'); >+ $me_mock->mock('get_log_template', sub { return 'mock'; }); >+ my $mock_req = Test::MockObject->new(); >+ $mock_req->mock('id', sub { 1 }); >+ is_deeply($logger->get_request_logs($mock_req), $res_obj, >+ 'get_request_logs() returns logs property structured and sorted'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+1; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20750
:
75304
|
75326
|
75329
|
75330
|
77757
|
77816
|
77817
|
77818
|
77931
|
79822
|
79823
|
79824
|
80860
|
82082
|
82083
|
82085
|
82096
|
82097
|
82098
|
82099
|
82500
|
82501
|
82502
|
84193
|
84194
|
84195
|
84203
|
84266
|
84497
|
84498
|
84821
|
84823
|
84824
|
84825
|
84826
|
84827
|
84973
|
84974
|
84975
|
84976
|
84977
|
84978
|
84979
|
85097
|
85098
|
85099
|
85101
|
85113
|
85238
|
85266
|
85697
|
85698
|
85699
|
85700
|
85701
|
85702
|
85703
|
85704
|
85705
|
85706
|
85707
|
85708
|
85709
|
85710
|
85756
|
85757
|
85765
|
85826
|
85827
|
85829
|
85830
|
85831
|
85832
|
85833
|
85834
|
85835
|
85836
|
85837
|
85838
|
85839
|
85840
|
85841
|
85842
|
85843
|
85844
|
85845
|
85846
|
85847
|
85848
|
86434
|
86435
|
86436
|
86534
|
86535
|
86536