Bugzilla – Attachment 122644 Details for
Bug 22531
Allow for multiple requests to partners and display partners in audit log
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22531: Add unit tests
Bug-22531-Add-unit-tests.patch (text/plain), 7.68 KB, created by
Martin Renvoize (ashimema)
on 2021-07-07 08:40:26 UTC
(
hide
)
Description:
Bug 22531: Add unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-07-07 08:40:26 UTC
Size:
7.68 KB
patch
obsolete
>From ce5bdca209ee55c2d807e1b713e36de81410d2d9 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Tue, 19 Mar 2019 14:15:15 +0000 >Subject: [PATCH] Bug 22531: Add unit tests > >Add tests for new and modified methods > >Signed-ff-by: Barry Cannon <bc@interleaf.ie> >--- > Koha/Illrequest/Logger.pm | 4 +- > t/db_dependent/Illrequest/Logger.t | 42 ++++++++++++++++-- > t/db_dependent/Illrequests.t | 71 ++++++++++++++++++++++++++++-- > 3 files changed, 108 insertions(+), 9 deletions(-) > >diff --git a/Koha/Illrequest/Logger.pm b/Koha/Illrequest/Logger.pm >index a3dd641c23..5fce4f344a 100644 >--- a/Koha/Illrequest/Logger.pm >+++ b/Koha/Illrequest/Logger.pm >@@ -24,7 +24,7 @@ use Time::Local; > use C4::Koha; > use C4::Context; > use C4::Templates; >-use C4::Log qw( logaction ); >+use C4::Log; > use Koha::ActionLogs; > use Koha::Notice::Template; > use Koha::Patron; >@@ -236,7 +236,7 @@ sub log_something { > defined $to_log->{infos} && > C4::Context->preference("IllLog") > ) { >- logaction( >+ C4::Log::logaction( > $to_log->{modulename}, > $to_log->{actionname}, > $to_log->{objectnumber}, >diff --git a/t/db_dependent/Illrequest/Logger.t b/t/db_dependent/Illrequest/Logger.t >index 07d4097573..b058d3d465 100755 >--- a/t/db_dependent/Illrequest/Logger.t >+++ b/t/db_dependent/Illrequest/Logger.t >@@ -1,4 +1,3 @@ >- > #!/usr/bin/perl > > # This file is part of Koha. >@@ -24,8 +23,10 @@ use Test::More tests => 2; > use Test::MockModule; > use Test::MockObject; > use t::lib::Mocks; >+use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; > > # Mock the modules we use > my $c4_log = Test::MockModule->new('C4::Log'); >@@ -38,7 +39,7 @@ use_ok('Koha::Illrequest::Logger'); > > subtest 'Basics' => sub { > >- plan tests => 7; >+ plan tests => 9; > > $schema->storage->txn_begin; > >@@ -72,7 +73,7 @@ subtest 'Basics' => sub { > 'logaction() being called when data is incomplete'); > > # Fix the data hashref, then test that logging occurs >- $log_obj->{objectnumber} = 'objectnumber'; >+ $log_obj->{objectnumber} = 123; > is($logger->log_something($log_obj), 1, > 'logaction() being called when pref is set and data is complete'); > >@@ -93,6 +94,41 @@ subtest 'Basics' => sub { > 'get_log_template() fetches correct core template' > ); > >+ # logged_requested_partners >+ my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; >+ my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; >+ my $illrq = $builder->build_object({ >+ class => 'Koha::Illrequests' >+ }); >+ my $config = Test::MockObject->new; >+ $config->set_always('partner_code', $categorycode); >+ $illrq->_config($config); >+ Koha::Patron->new( >+ { >+ surname => 'Test 1', >+ email => 'me@nowhere.com', >+ categorycode => $categorycode, >+ branchcode => $branchcode >+ } >+ )->store(); >+ my $returned = Koha::Illrequest::Logger::_logged_requested_partners({ >+ request => $illrq, >+ info => { >+ log_origin => "core", >+ status_before => "GENREQ", >+ status_after => "GENREQ", >+ additional => { >+ partner_email_previous => 'me@nowhere.com', >+ partner_email_now => 'you@nowhere.com' >+ } >+ } >+ }); >+ isa_ok($returned, 'HASH', >+ 'logged_requested_partners returns a hasref' >+ ); >+ is($returned->{'me@nowhere.com'}->{surname}, 'Test 1', >+ 'logged_requested_partners returns full patron objects'); >+ > $schema->storage->txn_rollback; > }; > >diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t >index 0ed98219e1..bd15308f96 100755 >--- a/t/db_dependent/Illrequests.t >+++ b/t/db_dependent/Illrequests.t >@@ -50,7 +50,7 @@ use_ok('Koha::Illrequests'); > > subtest 'Basic object tests' => sub { > >- plan tests => 24; >+ plan tests => 26; > > $schema->storage->txn_begin; > >@@ -122,6 +122,14 @@ subtest 'Basic object tests' => sub { > is(Koha::Illrequests->search->count, 0, > "No illrequest found after delete."); > >+ $illrq_obj->status('REQ'); >+ is($illrq_obj->status, 'REQ', >+ "status correctly handles strings"); >+ >+ $illrq_obj->status({ status => 'NEW', additional => 'add'}); >+ is($illrq_obj->status, 'NEW', >+ "status correctly handles hashrefs"); >+ > $schema->storage->txn_rollback; > }; > >@@ -373,7 +381,7 @@ subtest 'Status Graph tests' => sub { > > subtest 'Backend testing (mocks)' => sub { > >- plan tests => 13; >+ plan tests => 16; > > $schema->storage->txn_begin; > >@@ -381,7 +389,9 @@ subtest 'Backend testing (mocks)' => sub { > # the Dummy plugin installed. load_backend & available_backends don't > # currently have tests as a result. > >- t::lib::Mocks->mock_config('interlibrary_loans', { backend_dir => 'a_dir' } ); >+ my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; >+ my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; >+ > my $backend = Test::MockObject->new; > $backend->set_isa('Koha::Illbackends::Mock'); > $backend->set_always('name', 'Mock'); >@@ -391,7 +401,12 @@ subtest 'Backend testing (mocks)' => sub { > class => 'Koha::Illrequests', > }); > >+ my $config = Test::MockObject->new; >+ $config->set_always('partner_code', $categorycode); >+ $config->set_always('backend_dir', 'a_dir'); >+ > $illrq->_backend($backend); >+ $illrq->_config($config); > > isa_ok($illrq->_backend, 'Koha::Illbackends::Mock', > "OK accessing mocked backend."); >@@ -438,6 +453,44 @@ subtest 'Backend testing (mocks)' => sub { > "Test metadata." > ); > >+ $backend->mock( >+ 'capabilities', >+ sub { >+ my ($self, $name) = @_; >+ if ($name eq 'get_requested_partners') { >+ return sub { >+ return 'me@nowhere.com; you@nowhere.com'; >+ } >+ } >+ } >+ ); >+ is($illrq->requested_partners, 'me@nowhere.com; you@nowhere.com', >+ "requested_partners returns string by default"); >+ >+ Koha::Patron->new( >+ { >+ surname => 'Test 1', >+ email => 'me@nowhere.com', >+ categorycode => $categorycode, >+ branchcode => $branchcode >+ } >+ )->store(); >+ >+ Koha::Patron->new( >+ { >+ surname => 'Test 2', >+ email => 'you@nowhere.com', >+ categorycode => $categorycode, >+ branchcode => $branchcode >+ } >+ )->store(); >+ >+ my $part = $illrq->requested_partners(1); >+ isa_ok($part, 'ARRAY', >+ "requested_partners returns array when requested"); >+ isa_ok(@{$part}[0], 'HASH', >+ "requested_partners return array contains unblessed Koha patrons"); >+ > # capabilities: > > # No backend graph extension >@@ -1222,7 +1275,7 @@ subtest 'Checking Limits' => sub { > > subtest 'Custom statuses' => sub { > >- plan tests => 3; >+ plan tests => 5; > > $schema->storage->txn_begin; > >@@ -1270,6 +1323,16 @@ subtest 'Custom statuses' => sub { > is($ill_req->statusalias, undef, > "Koha::Illrequest->status overloading resetting status_alias"); > >+ $ill_req->status_alias($av->authorised_value); >+ is($ill_req->status_alias, $av->authorised_value, >+ "Koha::Illrequest->status_alias correctly handling string"); >+ >+ $ill_req->status_alias( >+ { status => $av->authorised_value, additional => 'xyz' } >+ ); >+ is($ill_req->status_alias, $av->authorised_value, >+ "Koha::Illrequest->status_alias correctly handling hashref"); >+ > $schema->storage->txn_rollback; > }; > >-- >2.20.1
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 22531
:
86723
|
86744
|
118843
|
118844
|
122643
|
122644
|
124979
|
124980
|
131234
|
131235
|
131236
|
131237
|
133708
|
133709
|
133710
|
133711
|
145726
|
145727
|
145728
|
145729
|
145730