From 2446eaf6fe3a4fe23088afde8071e3ee7176d6df Mon Sep 17 00:00:00 2001 From: Alex Sassmannshausen Date: Mon, 16 Oct 2017 10:46:39 +0200 Subject: [PATCH] Bug 7317: Remove obsolete files. The tests files will be replaced with t/db_dependent/Illrequests.t. Dummy backend files are now in their own repository. * Koha/Illrequest/Backend/Dummy/Base.pm: Delete. * t/db_dependent/Illrequest.t: Delete. * t/db_dependent/Illrequest/Dummy.t: Delete. --- Koha/Illrequest/Backend/Dummy/Base.pm | 576 ---------------------------------- t/db_dependent/Illrequest.t | 544 -------------------------------- t/db_dependent/Illrequest/Dummy.t | 378 ---------------------- 3 files changed, 1498 deletions(-) delete mode 100644 Koha/Illrequest/Backend/Dummy/Base.pm delete mode 100644 t/db_dependent/Illrequest.t delete mode 100644 t/db_dependent/Illrequest/Dummy.t diff --git a/Koha/Illrequest/Backend/Dummy/Base.pm b/Koha/Illrequest/Backend/Dummy/Base.pm deleted file mode 100644 index b832bf8de1..0000000000 --- a/Koha/Illrequest/Backend/Dummy/Base.pm +++ /dev/null @@ -1,576 +0,0 @@ -package Koha::Illrequest::Backend::Dummy::Base; - -# Copyright PTFS Europe 2014 -# -# 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, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -use Modern::Perl; -use DateTime; -use Koha::Illrequestattribute; - -=head1 NAME - -Koha::Illrequest::Backend::Dummy - Koha ILL Backend: Dummy - -=head1 SYNOPSIS - -Koha ILL implementation for the "Dummy" backend. - -=head1 DESCRIPTION - -=head2 Overview - -We will be providing the Abstract interface which requires we implement the -following methods: -- create -> initial placement of the request for an ILL order -- confirm -> confirm placement of the ILL order -- list -> list all ILL Requests currently placed with the backend -- renew -> request a currently borrowed ILL be renewed in the backend -- update_status -> ILL module update hook: custom actions on status update -- cancel -> request an already 'confirm'ed ILL order be cancelled -- status -> request the current status of a confirmed ILL order - -Each of the above methods will receive the following parameter from -Illrequest.pm: - - { - request => $request, - other => $other, - } - -where: - -- $REQUEST is the Illrequest object in Koha. It's associated - Illrequestattributes can be accessed through the `illrequestattributes` - method. -- $OTHER is any further data, generally provided through templates .INCs - -Each of the above methods should return a hashref of the following format: - - return { - error => 0, - # ^------- 0|1 to indicate an error - status => 'result_code', - # ^------- Summary of the result of the operation - message => 'Human readable message.', - # ^------- Message, possibly to be displayed - # Normally messages are derived from status in INCLUDE. - # But can be used to pass API messages to the INCLUDE. - method => 'list', - # ^------- Name of the current method invoked. - # Used to load the appropriate INCLUDE. - stage => 'commit', - # ^------- The current stage of this method - # Used by INCLUDE to determine HTML to generate. - # 'commit' will result in final processing by Illrequest.pm. - next => 'illview'|'illlist', - # ^------- When stage is 'commit', should we move on to ILLVIEW the - # current request or ILLLIST all requests. - value => {}, - # ^------- A hashref containing an arbitrary return value that this - # backend wants to supply to its INCLUDE. - }; - -=head2 On the Dummy backend - -The Dummy backend is rather simple, but provides correctly formatted response -values, that other backends can model themselves after. - -The code is not DRY -- primarily so that each method can be looked at in -isolation rather than having to familiarise oneself with helper procedures. - -=head1 API - -=head2 Class Methods - -=cut - -=head3 new - - my $backend = Koha::Illrequest::Backend::Dummy->new; - -=cut - -sub new { - # -> instantiate the backend - my ( $class ) = @_; - my $self = {}; - bless( $self, $class ); - return $self; -} - -=head3 _data_store - - my $request = $self->_data_store($id); - my $requests = $self->_data_store; - -A mock of a data store. When passed no parameters it returns all entries. -When passed one it will return the entry matched by its id. - -=cut - -sub _data_store { - my $data = { - 1234 => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - }, - 5678 => { - id => 5678, - title => "Interlibrary loans in Koha", - author => "A.N. Other", - }, - }; - # ID search - my ( $self, $id ) = @_; - return $data->{$id} if $id; - - # Full search - my @entries; - while ( my ( $k, $v ) = each %{$data} ) { - push @entries, $v; - } - return \@entries; -} - -=head3 create - - my $response = $backend->create({ - request => $requestdetails, - other => $other, - }); - -This is the initial creation of the request. Generally this stage will be -some form of search with the backend. - -By and large we will not have useful $requestdetails (borrowernumber, -branchcode, status, etc.). - -$params is simply an additional slot for any further arbitrary values to pass -to the backend. - -This is an example of a multi-stage method. - -=cut - -sub create { - # -> initial placement of the request for an ILL order - my ( $self, $params ) = @_; - my $stage = $params->{other}->{stage}; - if ( !$stage || $stage eq 'init' ) { - # We simply need our template .INC to produce a search form. - return { - error => 0, - status => '', - message => '', - method => 'create', - stage => 'search_form', - value => {}, - }; - } elsif ( $stage eq 'search_form' ) { - # Received search query in 'other'; perform search... - - # No-op on Dummy - - # and return results. - return { - error => 0, - status => '', - message => '', - method => 'create', - stage => 'search_results', - value => { - borrowernumber => $params->{other}->{borrowernumber}, - branchcode => $params->{other}->{branchcode}, - medium => $params->{other}->{medium}, - candidates => $self->_data_store, - } - }; - } elsif ( $stage eq 'search_results' ) { - # We have a selection - my $id = $params->{other}->{id}; - - # -> select from backend... - my $request_details = $self->_data_store($id); - - # ...Populate Illrequest - my $request = $params->{request}; - $request->borrower_id($params->{other}->{borrowernumber}); - $request->branch_id($params->{other}->{branchcode}); - $request->medium($params->{other}->{medium}); - $request->status('NEW'); - $request->placed(DateTime->now); - $request->updated(DateTime->now); - $request->store; - # ...Populate Illrequestattributes - while ( my ( $type, $value ) = each %{$request_details} ) { - Koha::Illrequestattribute->new({ - illrequest_id => $request->illrequest_id, - type => $type, - value => $value, - })->store; - } - - # -> create response. - return { - error => 0, - status => '', - message => '', - method => 'create', - stage => 'commit', - next => 'illview', - value => $request_details, - }; - } else { - # Invalid stage, return error. - return { - error => 1, - status => 'unknown_stage', - message => '', - method => 'create', - stage => $params->{stage}, - value => {}, - }; - } -} - -=head3 confirm - - my $response = $backend->confirm({ - request => $requestdetails, - other => $other, - }); - -Confirm the placement of the previously "selected" request (by using the -'create' method). - -In this case we will generally use $request. -This will be supplied at all times through Illrequest. $other may be supplied -using templates. - -=cut - -sub confirm { - # -> confirm placement of the ILL order - my ( $self, $params ) = @_; - # Turn Illrequestattributes into a plain hashref - my $value = {}; - my $attributes = $params->{request}->illrequestattributes; - foreach my $attr (@{$attributes->as_list}) { - $value->{$attr->type} = $attr->value; - }; - # Submit request to backend... - - # No-op for Dummy - - # ...parse response... - $attributes->find_or_create({ type => "status", value => "On order" }); - my $request = $params->{request}; - $request->cost("30 GBP"); - $request->orderid($value->{id}); - $request->status("REQ"); - $request->accessurl("URL") if $value->{url}; - $request->store; - $value->{status} = "On order"; - $value->{cost} = "30 GBP"; - # ...then return our result: - return { - error => 0, - status => '', - message => '', - method => 'confirm', - stage => 'commit', - next => 'illview', - value => $value, - }; -} - -=head3 list - - my $response = $backend->list({ - request => $requestdetails, - other => $other, - }; - -Attempt to get a list of the currently registered requests with the backend. - -Parameters are optional for this request. A backend may be supplied with -details of a specific request (or a group of requests in $other), but equally -no parameters might be provided at all. - -Normally no parameters will be provided in the 'create' stage. After this, -parameters may be provided using templates. - -=cut - -sub list { - # -> list all ILL Requests currently placed with the backend - # (we ignore all params provided) - my ( $self, $params ) = @_; - my $stage = $params->{other}->{stage}; - if ( !$stage || $stage eq 'init' ) { - return { - error => 0, - status => '', - message => '', - method => 'list', - stage => 'list', - value => { - 1 => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "On order", - cost => "30 GBP", - }, - }, - }; - } elsif ( $stage eq 'list' ) { - return { - error => 0, - status => '', - message => '', - method => 'list', - stage => 'commit', - value => {}, - }; - } else { - # Invalid stage, return error. - return { - error => 1, - status => 'unknown_stage', - message => '', - method => 'create', - stage => $params->{stage}, - value => {}, - }; - } -} - -=head3 renew - - my $response = $backend->renew({ - request => $requestdetails, - other => $other, - }); - -Attempt to renew a request that was supplied through backend and is currently -in use by us. - -We will generally use $request. This will be supplied at all times through -Illrequest. $other may be supplied using templates. - -=cut - -sub renew { - # -> request a currently borrowed ILL be renewed in the backend - my ( $self, $params ) = @_; - # Turn Illrequestattributes into a plain hashref - my $value = {}; - my $attributes = $params->{request}->illrequestattributes; - foreach my $attr (@{$attributes->as_list}) { - $value->{$attr->type} = $attr->value; - }; - # Submit request to backend, parse response... - my ( $error, $status, $message ) = ( 0, '', '' ); - if ( !$value->{status} || $value->{status} eq 'On order' ) { - $error = 1; - $status = 'not_renewed'; - $message = 'Order not yet delivered.'; - } else { - $value->{status} = "Renewed"; - } - # ...then return our result: - return { - error => $error, - status => $status, - message => $message, - method => 'renew', - stage => 'commit', - value => $value, - }; -} - -=head3 update_status - - my $response = $backend->update_status({ - request => $requestdetails, - other => $other, - }); - -Our Illmodule is handling a request to update the status of an Illrequest. As -part of this we give the backend an opportunity to perform arbitrary actions -on update to a new status. - -We will provide $request. This will be supplied at all times through -Illrequest. $other will contain entries for the old status and the new -status, as well as other information provided from templates. - -$old_status, $new_status. - -=cut - -sub update_status { - # -> ILL module update hook: custom actions on status update - my ( $self, $params ) = @_; - # Turn Illrequestattributes into a plain hashref - my $value = {}; - my $attributes = $params->{request}->illrequestattributes; - foreach my $attr (@{$attributes->as_list}) { - $value->{$attr->type} = $attr->value; - }; - # Submit request to backend, parse response... - my ( $error, $status, $message ) = (0, '', ''); - my $old = $params->{other}->{old_status}; - my $new = $params->{other}->{new_status}; - if ( !$new || $new eq 'ERR' ) { - ( $error, $status, $message ) = ( - 1, 'failed_update_hook', - 'Fake reason for failing to perform update operation.' - ); - } - return { - error => $error, - status => $status, - message => $message, - method => 'update_status', - stage => 'commit', - value => $value, - }; -} - -=head3 cancel - - my $response = $backend->cancel({ - request => $requestdetails, - other => $other, - }); - -We will attempt to cancel a request that was confirmed. - -We will generally use $request. This will be supplied at all times through -Illrequest. $other may be supplied using templates. - -=cut - -sub cancel { - # -> request an already 'confirm'ed ILL order be cancelled - my ( $self, $params ) = @_; - # Turn Illrequestattributes into a plain hashref - my $value = {}; - my $attributes = $params->{request}->illrequestattributes; - foreach my $attr (@{$attributes->as_list}) { - $value->{$attr->type} = $attr->value; - }; - # Submit request to backend, parse response... - my ( $error, $status, $message ) = (0, '', ''); - if ( !$value->{status} ) { - ( $error, $status, $message ) = ( - 1, 'unknown_request', 'Cannot cancel an unknown request.' - ); - } else { - $attributes->find({ type => "status" })->delete; - $params->{request}->status("REQREV"); - $params->{request}->cost(undef); - $params->{request}->orderid(undef); - $params->{request}->store; - } - return { - error => $error, - status => $status, - message => $message, - method => 'cancel', - stage => 'commit', - value => $value, - }; -} - -=head3 status - - my $response = $backend->create({ - request => $requestdetails, - other => $other, - }); - -We will try to retrieve the status of a specific request. - -We will generally use $request. This will be supplied at all times through -Illrequest. $other may be supplied using templates. - -=cut - -sub status { - # -> request the current status of a confirmed ILL order - my ( $self, $params ) = @_; - my $value = {}; - my $stage = $params->{other}->{stage}; - my ( $error, $status, $message ) = (0, '', ''); - if ( !$stage || $stage eq 'init' ) { - # Generate status result - # Turn Illrequestattributes into a plain hashref - my $attributes = $params->{request}->illrequestattributes; - foreach my $attr (@{$attributes->as_list}) { - $value->{$attr->type} = $attr->value; - } - ; - # Submit request to backend, parse response... - if ( !$value->{status} ) { - ( $error, $status, $message ) = ( - 1, 'unknown_request', 'Cannot query status of an unknown request.' - ); - } - return { - error => $error, - status => $status, - message => $message, - method => 'status', - stage => 'status', - value => $value, - }; - - } elsif ( $stage eq 'status') { - # No more to do for method. Return to illlist. - return { - error => $error, - status => $status, - message => $message, - method => 'status', - stage => 'commit', - next => 'illlist', - value => {}, - }; - - } else { - # Invalid stage, return error. - return { - error => 1, - status => 'unknown_stage', - message => '', - method => 'create', - stage => $params->{stage}, - value => {}, - }; - } -} - -=head1 AUTHOR - -Alex Sassmannshausen - -=cut - -1; diff --git a/t/db_dependent/Illrequest.t b/t/db_dependent/Illrequest.t deleted file mode 100644 index 5fd5f0b81f..0000000000 --- a/t/db_dependent/Illrequest.t +++ /dev/null @@ -1,544 +0,0 @@ -#!/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 2 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, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# - -use Modern::Perl; - -use File::Basename qw/basename/; -use Koha::Database; -use Koha::Illrequestattributes; -use Koha::Patrons; -use t::lib::TestBuilder; - -use Test::More tests => 44; - -# We want to test the Koha IllRequest object. At its core it's a simple -# Koha::Object, mapping to the ill_request table. -# -# This object will supersede the Status object in ILLModule. -# -# We must ensure perfect backward compatibility between the current model and -# the Status less model. - -use_ok('Koha::Illrequest'); -use_ok('Koha::Illrequests'); - -my $schema = Koha::Database->new->schema; -$schema->storage->txn_begin; - -my $builder = t::lib::TestBuilder->new; - -my $patron = $builder->build({ source => 'Borrower' }); -my $branch = $builder->build({ source => 'Branch' }); - -my $illRequest = $builder->build({ - source => 'Illrequest', - value => { - borrowernumber => $patron->{borrowernumber}, - branch => $branch->{branchcode}, - biblionumber => 0, - status => 'NEW', - completion_date => 0, - reqtype => 'book', - } -}); - -my $illObject = Koha::Illrequests->find($illRequest->{illrequest_id}); - -isa_ok($illObject, "Koha::Illrequest"); - -# Test delete works correctly. -my $illRequestDelete = $builder->build({ - source => 'Illrequest', - value => { - borrowernumber => $patron->{borrowernumber}, - branch => $branch->{branchcode}, - biblionumber => 0, - status => 'NEW', - completion_date => 0, - reqtype => 'book', - } -}); -sub ill_req_search { - return Koha::Illrequestattributes->search({ - illrequest_id => $illRequestDelete->{illrequest_id} - })->count; -} - -is(ill_req_search, 0, "Correctly not found matching Illrequestattributes."); -# XXX: For some reason test builder can't build Illrequestattributes. -my $illReqAttr = Koha::Illrequestattribute->new({ - illrequest_id => $illRequestDelete->{illrequest_id}, - type => "test", - value => "Hello World" -})->store; -is(ill_req_search, 1, "We have found a matching Illrequestattribute."); - -Koha::Illrequests->find($illRequestDelete->{illrequest_id})->delete; -is( - Koha::Illrequests->find($illRequestDelete->{illrequest_id}), - undef, - "Correctly deleted Illrequest." -); -is(ill_req_search, 0, "Correctly deleted Illrequestattributes."); - -# Test Accessing of related records. - -# # TODO the conclusion from being able to use one_to_many? we no longer need -# # the Record object: simply pass the `ill_request_attributes` resultset -# # whenever one would pass a Record. - -my $illRequest2 = $builder->build({ - source => 'Illrequest', - value => { - borrower_id => $patron->{borrowernumber}, - branch_id => $branch->{branchcode}, - biblio_id => 0, - status => 'NEW', - completed => 0, - medium => 'book', - } -}); -my $illReqAttr2 = Koha::Illrequestattribute->new({ - illrequest_id => $illRequest2->{illrequest_id}, - type => "test2", - value => "Hello World" -})->store; -my $illReqAttr3 = Koha::Illrequestattribute->new({ - illrequest_id => $illRequest2->{illrequest_id}, - type => "test3", - value => "Hello Space" -})->store; - -my $illRequestAttributes = Koha::Illrequests - ->find($illRequest2->{illrequest_id})->illrequestattributes; - -isa_ok($illRequestAttributes, "Koha::Illrequestattributes"); - -is($illRequestAttributes->count, 2, "Able to search related."); - -# Test loading of 'Config'. - -my $rqConfigTest = Koha::Illrequest->new({ - borrower_id => $patron->{borrowernumber}, - branch_id => $branch->{branchcode}, -}); - -isa_ok($rqConfigTest->_config, "Koha::Illrequest::Config"); - -# Test loading of 'Dummy' backend. - -my $rqBackendTest = Koha::Illrequest->new({ - borrower_id => $patron->{borrowernumber}, - branch_id => $branch->{branchcode}, -})->store; - -$rqBackendTest->_config->backend("Dummy"); -$rqBackendTest->_config->limits({ default => { count => -1 } }); -isa_ok($rqBackendTest->_backend, "Koha::Illbackends::Dummy::Base"); - -# Test use of 'Dummy' Backend. - -## Test backend_update_status - -# FIXME: This breaks transparancy of ->status method! -eval { $rqBackendTest->status("ERR") }; -ok($@, "status: Test for status error on hook fail."); - -# FIXME: Will need to test this on new illRequest to not pollute rest of -# tests. - -# is($rqBackendTest->status("NEW")->status, "NEW", "status: Setter works -# OK."); -# is($rqBackendTest->status(null), null, "status: Unsetter works OK."); - -## Test backend_create - -is( - $rqBackendTest->status, - undef, - "backend_create: Test our status initiates correctly." -); - -# Request a search form -my $created_rq = $rqBackendTest->backend_create({ - stage => "search_form", - method => "create", -}); - -is( $created_rq->{stage}, 'search_results', - "backend_create: search_results stage." ); - -# Request search results -# FIXME: fails because of missing patron / branch info. -# $created_rq = $rqBackendTest->backend_create({ -# stage => "search_results", -# method => "create", -# other => { search => "interlibrary loans" }, -# }); - -# is_deeply( -# $created_rq, -# { -# error => 0, -# status => '', -# message => '', -# method => 'create', -# stage => 'search_results', -# template => 'ill/Dummy/create.inc', -# value => [ -# { -# id => 1234, -# title => "Ordering ILLs using Koha", -# author => "A.N. Other", -# }, -# { -# id => 5678, -# title => "Interlibrary loans in Koha", -# author => "A.N. Other", -# }, -# ], -# } -# , -# "backend_create: search_results stage." -# ); - -# # Create the request -# $created_rq = $rqBackendTest->backend_create({ -# stage => "commit", -# method => "create", -# other => { -# id => 1234, -# title => "Ordering ILLs using Koha", -# author => "A.N. Other", -# }, -# }); - -# while ( my ( $field, $value ) = each %{$created_rq} ) { -# isnt($value, undef, "backend_create: key '$field' exists"); -# }; - -# is( -# $rqBackendTest->status, -# "NEW", -# "backend_create: Test our status was updated." -# ); - -# cmp_ok( -# $rqBackendTest->illrequestattributes->count, -# "==", -# 3, -# "backend_create: Ensure we have correctly stored our new attributes." -# ); - -# ## Test backend_list - -# is_deeply( -# $rqBackendTest->backend_list->{value}, -# { -# 1 => { -# id => 1234, -# title => "Ordering ILLs using Koha", -# author => "A.N. Other", -# status => "On order", -# cost => "30 GBP", -# } -# }, -# "backend_list: Retrieve our list of requested requests." -# ); - -# ## Test backend_renew - -# ok( -# $rqBackendTest->backend_renew->{error}, -# "backend_renew: Error for invalid request." -# ); -# is_deeply( -# $rqBackendTest->backend_renew->{value}, -# { -# id => 1234, -# title => "Ordering ILLs using Koha", -# author => "A.N. Other", -# }, -# "backend_renew: Renew request." -# ); - -# ## Test backend_confirm - -# my $rqBackendTestConfirmed = $rqBackendTest->backend_confirm; -# is( -# $rqBackendTest->status, -# "REQ", -# "backend_commit: Confirm status update correct." -# ); -# is( -# $rqBackendTest->orderid, -# 1234, -# "backend_commit: Confirm orderid populated correctly." -# ); - -# ## Test backend_status - -# is( -# $rqBackendTest->backend_status->{error}, -# 0, -# "backend_status: error for invalid request." -# ); -# is_deeply( -# $rqBackendTest->backend_status->{value}, -# { -# id => 1234, -# status => "On order", -# title => "Ordering ILLs using Koha", -# author => "A.N. Other", -# }, -# "backend_status: Retrieve the status of request." -# ); - -# # Now test trying to get status on non-confirmed request. -my $rqBackendTestUnconfirmed = Koha::Illrequest->new({ - borrower_id => $patron->{borrowernumber}, - branch_id => $branch->{branchcode}, -})->store; -$rqBackendTestUnconfirmed->_config->backend("Dummy"); -$rqBackendTestUnconfirmed->_config->limits({ default => { count => -1 } }); - -$rqBackendTestUnconfirmed->backend_create({ - stage => "commit", - method => "create", - other => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - }, -}); -is( - $rqBackendTestUnconfirmed->backend_status->{error}, - 1, - "backend_status: error for invalid request." -); - -## Test backend_cancel - -# is( -# $rqBackendTest->backend_cancel->{error}, -# 0, -# "backend_cancel: Successfully cancelling request." -# ); -# is_deeply( -# $rqBackendTest->backend_cancel->{value}, -# { -# id => 1234, -# title => "Ordering ILLs using Koha", -# author => "A.N. Other", -# }, -# "backend_cancel: Cancel request." -# ); - -# Now test trying to cancel non-confirmed request. -is( - $rqBackendTestUnconfirmed->backend_cancel->{error}, - 1, - "backend_cancel: error for invalid request." -); -is_deeply( - $rqBackendTestUnconfirmed->backend_cancel->{value}, - {}, - "backend_cancel: Cancel request." -); - -# Test Helpers - -## Test getCensorNotesStaff - -is($rqBackendTest->getCensorNotesStaff, 1, "getCensorNotesStaff: Public."); -$rqBackendTest->_config->censorship({ - censor_notes_staff => 0, - censor_reply_date => 0, -}); -is($rqBackendTest->getCensorNotesStaff, 0, "getCensorNotesStaff: Censored."); - -## Test getCensorNotesStaff - -is($rqBackendTest->getDisplayReplyDate, 1, "getDisplayReplyDate: Yes."); -$rqBackendTest->_config->censorship({ - censor_notes_staff => 0, - censor_reply_date => 1, -}); -is($rqBackendTest->getDisplayReplyDate, 0, "getDisplayReplyDate: No."); - -# FIXME: These should be handled by the templates. -# # Test Output Helpers - -# ## Test getStatusSummary - -# $rqBackendTest->medium("Book")->store; -# is_deeply( -# $rqBackendTest->getStatusSummary({brw => 0}), -# { -# biblionumber => ["Biblio Number", undef], -# borrowernumber => ["Borrower Number", $patron->{borrowernumber}], -# id => ["Request Number", $rqBackendTest->illrequest_id], -# prefix_id => ["Request Number", $rqBackendTest->illrequest_id], -# reqtype => ["Request Type", "Book"], -# status => ["Status", "REQREV"], -# }, -# "getStatusSummary: Without Borrower." -# ); - -# is_deeply( -# $rqBackendTest->getStatusSummary({brw => 1}), -# { -# biblionumber => ["Biblio Number", undef], -# borrower => ["Borrower", Koha::Patrons->find($patron->{borrowernumber})], -# id => ["Request Number", $rqBackendTest->illrequest_id], -# prefix_id => ["Request Number", $rqBackendTest->illrequest_id], -# reqtype => ["Request Type", "Book"], -# status => ["Status", "REQREV"], -# }, -# "getStatusSummary: With Borrower." -# ); - -# ## Test getFullStatus - -# is_deeply( -# $rqBackendTest->getFullStatus({brw => 0}), -# { -# biblionumber => ["Biblio Number", undef], -# borrowernumber => ["Borrower Number", $patron->{borrowernumber}], -# id => ["Request Number", $rqBackendTest->illrequest_id], -# prefix_id => ["Request Number", $rqBackendTest->illrequest_id], -# reqtype => ["Request Type", "Book"], -# status => ["Status", "REQREV"], -# placement_date => ["Placement Date", $rqBackendTest->placed], -# completion_date => ["Completion Date", $rqBackendTest->completed], -# ts => ["Timestamp", $rqBackendTest->updated], -# branch => ["Branch", $rqBackendTest->branch_id], -# }, -# "getFullStatus: Without Borrower." -# ); - -# is_deeply( -# $rqBackendTest->getFullStatus({brw => 1}), -# { -# biblionumber => ["Biblio Number", undef], -# borrower => ["Borrower", Koha::Patrons->find($patron->{borrowernumber})], -# id => ["Request Number", $rqBackendTest->illrequest_id], -# prefix_id => ["Request Number", $rqBackendTest->illrequest_id], -# reqtype => ["Request Type", "Book"], -# status => ["Status", "REQREV"], -# placement_date => ["Placement Date", $rqBackendTest->placed], -# completion_date => ["Completion Date", $rqBackendTest->completed], -# ts => ["Timestamp", $rqBackendTest->updated], -# branch => ["Branch", $rqBackendTest->branch_id], -# }, -# "getFullStatus: With Borrower." -# ); - -## Test available_backends -subtest 'available_backends' => sub { - plan tests => 1; - - my $rq = Koha::Illrequest->new({ - borrower_id => $patron->{borrowernumber}, - branch_id => $branch->{branchcode}, - })->store; - - my @backends = (); - my $backenddir = $rq->_config->backend_dir; - @backends = <$backenddir/*> if ( $backenddir ); - @backends = map { basename($_) } @backends; - is_deeply(\@backends, $rq->available_backends, - "Correctly identify available backends."); - -}; - -## Test capabilities - -my $rqCapTest = Koha::Illrequest->new({ - borrower_id => $patron->{borrowernumber}, - branch_id => $branch->{branchcode}, -})->store; - -is( keys %{$rqCapTest->_core_status_graph}, - @{[ 'NEW', 'REQ', 'REVREQ', 'QUEUED', 'CANCREQ', 'COMP', 'KILL' ]}, - "Complete list of core statuses." ); - -my $union = $rqCapTest->_status_graph_union( - $rqCapTest->_core_status_graph, - { - TEST => { - prev_actions => [ 'COMP' ], - id => 'TEST', - name => "Test", - ui_method_name => "Perform test", - method => 'test', - next_actions => [ 'NEW' ] - }, - BLAH => { - prev_actions => [ 'COMP' ], - id => 'BLAH', - name => "BLAH", - ui_method_name => "Perform test", - method => 'test', - next_actions => [ 'NEW' ] - }, - } -); -ok( ( grep 'BLAH', @{$union->{COMP}->{next_actions}} and - grep 'TEST', @{$union->{COMP}->{next_actions}} ), - "next_actions: updated." ); -ok( ( grep 'BLAH', @{$union->{NEW}->{prev_actions}} and - grep 'TEST', @{$union->{NEW}->{prev_actions}} ), - "next_actions: updated." ); - -## Test available_backends -subtest 'available_actions' => sub { - plan tests => 1; - - my $rq = Koha::Illrequest->new({ - borrower_id => $patron->{borrowernumber}, - branch_id => $branch->{branchcode}, - status => 'NEW', - })->store; - - is_deeply( - $rq->available_actions, - [ - { - prev_actions => [ 'NEW', 'REQREV', 'QUEUED' ], - id => 'REQ', - name => 'Requested', - ui_method_name => 'Create request', - method => 'confirm', - next_actions => [ 'REQREV' ], - }, - { - prev_actions => [ 'CANCREQ', 'QUEUED', 'REQREV', 'NEW' ], - id => 'KILL', - name => 0, - ui_method_name => 'Delete request', - method => 'delete', - next_actions => [ ], - } - ] - ); -}; - -$schema->storage->txn_rollback; - -1; diff --git a/t/db_dependent/Illrequest/Dummy.t b/t/db_dependent/Illrequest/Dummy.t deleted file mode 100644 index 38b5fac648..0000000000 --- a/t/db_dependent/Illrequest/Dummy.t +++ /dev/null @@ -1,378 +0,0 @@ -#!/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 2 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, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# - -use Modern::Perl; - -use Koha::Database; -use Koha::Illrequests; -use t::lib::TestBuilder; - -use Test::More tests => 15; - -# This is a set of basic tests for the Dummy backend, largely to provide -# sanity checks for testing at the higher level Illrequest.pm level. -# -# The Dummy backend is rather simple, but provides correctly formatted -# response values, that other backends can model themselves after. - -use_ok('Koha::Illrequest::Backend::Dummy'); - -my $backend = Koha::Illrequest::Backend::Dummy->new; - -isa_ok($backend, 'Koha::Illrequest::Backend::Dummy'); - - -my $schema = Koha::Database->new->schema; -$schema->storage->txn_begin; - -my $builder = t::lib::TestBuilder->new; - -my $patron = $builder->build({ source => 'Borrower' }); -my $branch = $builder->build({ source => 'Branch' }); - -my $illRequest = $builder->build({ - source => 'Illrequest', - value => { - borrowernumber => $patron->{borrowernumber}, - branch => $branch->{branchcode}, - } -}); -my $mock_request = Koha::Illrequests->find($illRequest->{illrequest_id}); -$mock_request->_config->backend("Dummy"); -$mock_request->_config->limits({ default => { count => -1 } }); - -# Test Create -my $rq = $backend->create({ - request => $mock_request, - method => 'create', - stage => 'search_form', - other => undef, -}); - -is_deeply( - $rq, - { - error => 0, - status => '', - message => '', - method => 'create', - stage => 'search_form', - value => {}, - }, - "Search_Form stage of create method." -); - -$rq = $backend->create({ - request => $mock_request, - method => 'create', - stage => 'search_results', - other => { search => "interlibrary loans" }, -}); - -is_deeply( - $rq, - { - error => 0, - status => '', - message => '', - method => 'create', - stage => 'search_results', - value => [ - { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - }, - { - id => 5678, - title => "Interlibrary loans in Koha", - author => "A.N. Other", - }, - ], - }, - "Search_Results stage of create method." -); - -$rq = $backend->create({ - request => $mock_request, - method => 'create', - stage => 'commit', - other => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - }, -}); - -is_deeply( - $rq, - { - error => 0, - status => '', - message => '', - method => 'create', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other" - }, - }, - "Commit stage of create method." -); - -$rq = $backend->create({ - request => $mock_request, - method => 'create', - stage => 'unknown_stage', - other => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - }, -}); - -is_deeply( - $rq, - { - error => 1, - status => 'unknown_stage', - message => '', - method => 'create', - stage => 'unknown_stage', - value => {}, - }, - "Commit stage of create method." -); - -# Test Confirm - -$rq = $backend->confirm({ - request => $mock_request, - other => undef, -}); - -is_deeply( - $rq, - { - error => 0, - status => '', - message => '', - method => 'confirm', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "On order", - cost => "30 GBP", - }, - }, - "Basic confirm method." -); - -# Test List - -is_deeply( - $backend->list, - { - error => 0, - status => '', - message => '', - method => 'list', - stage => 'commit', - value => { - 1 => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "On order", - cost => "30 GBP", - }, - }, - }, - "Basic list method." -); - -# Test Renew - -is_deeply( - $backend->renew({ - request => $mock_request, - other => undef, - }), - { - error => 1, - status => 'not_renewed', - message => 'Order not yet delivered.', - method => 'renew', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "On order", - }, - }, - "Basic renew method." -); - -Koha::Illrequestattributes->find({ - illrequest_id => $mock_request->illrequest_id, - type => "status" -})->set({ value => "Delivered" })->store; - -is_deeply( - $backend->renew({ - request => $mock_request, - other => undef, - }), - { - error => 0, - status => '', - message => '', - method => 'renew', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "Renewed", - }, - }, - "Modified renew method." -); - -# Test Update_Status - -is_deeply( - $backend->update_status({ - request => $mock_request, - other => undef, - }), - { - error => 1, - status => 'failed_update_hook', - message => 'Fake reason for failing to perform update operation.', - method => 'update_status', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "Delivered", - }, - }, - "Basic update_status method." -); - -# FIXME: Perhaps we should add a test checking for specific status code -# transitions. - -# Test Cancel - -is_deeply( - $backend->cancel({ - request => $mock_request, - other => undef, - }), - { - error => 0, - status => '', - message => '', - method => 'cancel', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "Delivered", - }, - }, - "Basic cancel method." -); - -is_deeply( - $backend->cancel({ - request => $mock_request, - other => undef, - }), - { - error => 1, - status => 'unknown_request', - message => 'Cannot cancel an unknown request.', - method => 'cancel', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - }, - }, - "Attempt to cancel an unconfirmed request." -); - -# Test Status - -is_deeply( - $backend->status({ - request => $mock_request, - other => undef, - }), - { - error => 1, - status => 'unknown_request', - message => 'Cannot query status of an unknown request.', - method => 'status', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - }, - }, - "Attempt to get status of an unconfirmed request." -); - -$rq = $backend->confirm({ - request => $mock_request, - other => undef, -}); - -is_deeply( - $backend->status({ - request => $mock_request, - other => undef, - }), - { - error => 0, - status => '', - message => '', - method => 'status', - stage => 'commit', - value => { - id => 1234, - title => "Ordering ILLs using Koha", - author => "A.N. Other", - status => "On order", - }, - }, - "Basic status method." -); - -1; -- 2.14.2