Bugzilla – Attachment 151392 Details for
Bug 33716
ILL - Allow for a disclaimer stage per request type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33716: Tests
Bug-33716-Tests.patch (text/plain), 7.26 KB, created by
Katrin Fischer
on 2023-05-18 11:24:55 UTC
(
hide
)
Description:
Bug 33716: Tests
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2023-05-18 11:24:55 UTC
Size:
7.26 KB
patch
obsolete
>From 1e3530ff568f1332bec68381b1e6c0f6b0bf619d Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Wed, 10 May 2023 17:50:12 +0000 >Subject: [PATCH] Bug 33716: Tests > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > t/db_dependent/Illrequest/Availability.t | 77 ++++++++++++-- > t/db_dependent/Illrequest/TypeDisclaimer.t | 117 +++++++++++++++++++++ > 2 files changed, 187 insertions(+), 7 deletions(-) > create mode 100755 t/db_dependent/Illrequest/TypeDisclaimer.t > >diff --git a/t/db_dependent/Illrequest/Availability.t b/t/db_dependent/Illrequest/Availability.t >index 8876268ee9..a8d98c9f72 100755 >--- a/t/db_dependent/Illrequest/Availability.t >+++ b/t/db_dependent/Illrequest/Availability.t >@@ -17,11 +17,23 @@ > > use Modern::Perl; > >-use Koha::Illrequest::Availability; >+use Test::More tests => 5; > >-use Test::More tests => 3; >+use Test::MockModule; >+use Test::MockObject; > >-use_ok('Koha::Illrequest::Availability'); >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::Illrequest::Workflow::Availability; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+use_ok('Koha::Illrequest::Workflow::Availability'); > > my $metadata = { > title => 'This is a title', >@@ -31,16 +43,67 @@ my $metadata = { > # Because hashes can reorder themselves, we need to make sure ours is in a > # predictable order > my $sorted = {}; >-foreach my $key( keys %{$metadata} ) { >+foreach my $key ( keys %{$metadata} ) { > $sorted->{$key} = $metadata->{$key}; > } > >-my $availability = Koha::Illrequest::Availability->new($sorted); >+my $availability = >+ Koha::Illrequest::Workflow::Availability->new( $sorted, 'staff' ); > >-isa_ok( $availability, 'Koha::Illrequest::Availability' ); >+isa_ok( $availability, 'Koha::Illrequest::Workflow::Availability' ); > > is( > $availability->prep_metadata($sorted), >- 'eyJhdXRob3IiOiJUaGlzIGlzIGFuIGF1dGhvciIsInRpdGxlIjoiVGhpcyBpcyBhIHRpdGxlIn0%3D%0A', >+'eyJhdXRob3IiOiJUaGlzIGlzIGFuIGF1dGhvciIsInRpdGxlIjoiVGhpcyBpcyBhIHRpdGxlIn0%3D%0A', > 'prep_metadata works' > ); >+ >+# Mock ILLBackend (as object) >+my $backend = Test::MockObject->new; >+$backend->set_isa('Koha::Illbackends::Mock'); >+$backend->set_always( 'name', 'Mock' ); >+$backend->set_always( 'capabilities', sub { return can_create_request => 1 } ); >+$backend->mock( >+ 'metadata', >+ sub { >+ my ( $self, $rq ) = @_; >+ return { >+ ID => $rq->illrequest_id, >+ Title => $rq->patron->borrowernumber >+ }; >+ } >+); >+$backend->mock( 'status_graph', sub { }, ); >+ >+# Mock Koha::Illrequest::load_backend (to load Mocked Backend) >+my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); >+$illreqmodule->mock( 'load_backend', >+ sub { my $self = shift; $self->{_my_backend} = $backend; return $self } ); >+ >+# Mock ILLModuleDisclaimerByType with valid YAML >+t::lib::Mocks::mock_preference( 'ILLCheckAvailability', 1 ); >+ >+# Mock not empty availability services >+my $availability_module = >+ Test::MockModule->new('Koha::Illrequest::Workflow::Availability'); >+$availability_module->mock( 'get_services', [ { name => 'service' } ] ); >+ >+my $req_1 = $builder->build_object( >+ { >+ class => 'Koha::Illrequests', >+ value => {} >+ } >+); >+ >+my $request = $req_1->load_backend('Mock'); >+ >+is( $availability->show_availability($request), >+ 1, 'able to show availability search' ); >+ >+# Mock empty availability services >+$availability_module->mock( 'get_services', [] ); >+ >+is( $availability->show_availability($request), >+ 0, 'unable to show type disclaimer form' ); >+ >+$schema->storage->txn_rollback; >\ No newline at end of file >diff --git a/t/db_dependent/Illrequest/TypeDisclaimer.t b/t/db_dependent/Illrequest/TypeDisclaimer.t >new file mode 100755 >index 0000000000..402bb5002e >--- /dev/null >+++ b/t/db_dependent/Illrequest/TypeDisclaimer.t >@@ -0,0 +1,117 @@ >+#!/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 Test::More tests => 5; >+ >+use Test::MockModule; >+use Test::MockObject; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::Illrequest::Workflow::TypeDisclaimer; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+use_ok('Koha::Illrequest::Workflow::TypeDisclaimer'); >+ >+my $metadata = { >+ title => 'This is a title', >+ author => 'This is an author' >+}; >+ >+# Because hashes can reorder themselves, we need to make sure ours is in a >+# predictable order >+my $sorted = {}; >+foreach my $key ( keys %{$metadata} ) { >+ $sorted->{$key} = $metadata->{$key}; >+} >+ >+my $type_disclaimer = >+ Koha::Illrequest::Workflow::TypeDisclaimer->new( $sorted, 'staff' ); >+ >+isa_ok( $type_disclaimer, 'Koha::Illrequest::Workflow::TypeDisclaimer' ); >+ >+is( >+ $type_disclaimer->prep_metadata($sorted), >+'eyJhdXRob3IiOiJUaGlzIGlzIGFuIGF1dGhvciIsInRpdGxlIjoiVGhpcyBpcyBhIHRpdGxlIn0%3D%0A', >+ 'prep_metadata works' >+); >+ >+# Mock ILLBackend (as object) >+my $backend = Test::MockObject->new; >+$backend->set_isa('Koha::Illbackends::Mock'); >+$backend->set_always( 'name', 'Mock' ); >+$backend->set_always( 'capabilities', sub { return can_create_request => 1 } ); >+$backend->mock( >+ 'metadata', >+ sub { >+ my ( $self, $rq ) = @_; >+ return { >+ ID => $rq->illrequest_id, >+ Title => $rq->patron->borrowernumber >+ }; >+ } >+); >+$backend->mock( 'status_graph', sub { }, ); >+ >+# Mock Koha::Illrequest::load_backend (to load Mocked Backend) >+my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); >+$illreqmodule->mock( 'load_backend', >+ sub { my $self = shift; $self->{_my_backend} = $backend; return $self } ); >+ >+# Mock ILLModuleDisclaimerByType with valid YAML >+t::lib::Mocks::mock_preference( >+ 'ILLModuleDisclaimerByType', "all: >+ text: | >+ <h2>HTML title</h2> >+ <p>This is an HTML paragraph</p> >+ <p>This is another HTML paragraph</p> >+ av_category_code: YES_NO >+article: >+ text: copyright text for all article type requests >+ av_category_code: YES_NO >+ bypass: 1" >+); >+ >+my $req_1 = $builder->build_object( >+ { >+ class => 'Koha::Illrequests', >+ value => {} >+ } >+); >+ >+my $request = $req_1->load_backend('Mock'); >+ >+is( $type_disclaimer->show_type_disclaimer($request), >+ 1, 'able to show type disclaimer form' ); >+ >+# Mock ILLModuleDisclaimerByType with invalid YAML >+my $type_disclaimer_module = >+ Test::MockModule->new('Koha::Illrequest::Workflow::TypeDisclaimer'); >+$type_disclaimer_module->mock( '_get_type_disclaimer_sys_pref', {} ); >+ >+is( $type_disclaimer->show_type_disclaimer($request), >+ 0, 'not able to show type disclaimer form' ); >+ >+$schema->storage->txn_rollback; >-- >2.30.2
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 33716
:
151027
|
151031
|
151032
|
151033
|
151034
|
151035
|
151146
|
151147
|
151148
|
151149
|
151150
|
151388
|
151389
|
151390
|
151391
|
151392
|
151393
|
151394
|
151401
|
151402
|
151403
|
151404
|
151405
|
151406
|
151407
|
151408
|
151409
|
151410
|
151411
|
152809
|
152810
|
152811
|
152813
|
152814
|
152815
|
152816
|
152817
|
152818
|
152819
|
152820
|
152821
|
152822
|
152823
|
152826
|
154305
|
154454
|
154714