3 # Copyright 2023 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Test::More tests => 1;
26 use t::lib::TestBuilder;
29 my $builder = t::lib::TestBuilder->new;
30 my $schema = Koha::Database->new->schema;
32 subtest 'existing_statuses() tests' => sub {
36 $schema->storage->txn_begin;
37 Koha::Illrequests->search->delete;
39 # Mock ILLBackend (as object)
40 my $backend = Test::MockObject->new;
41 $backend->set_isa('Koha::Illbackends::Mock');
42 $backend->set_always( 'name', 'Mock' );
49 prev_actions => [ 'NEW', 'REQREV', 'QUEUED', 'CANCREQ' ],
52 ui_method_name => 'Make request ready',
54 next_actions => [ 'REQREV', 'COMP', 'CHK' ],
55 ui_method_icon => 'fa-check',
61 # Mock Koha::Illrequest::load_backend (to load Mocked Backend)
62 my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
65 sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
68 my $alias = $builder->build_object(
70 class => 'Koha::AuthorisedValues',
72 category => 'ILL_STATUS_ALIAS',
73 authorised_value => 'BOB',
74 lib => "Bob is the best status"
79 my $backend_req_status = $builder->build_object(
81 class => 'Koha::Illrequests',
84 status_alias => undef,
91 my $req = $builder->build_object(
93 class => 'Koha::Illrequests',
96 status_alias => undef,
102 my $chk = $builder->build_object(
104 class => 'Koha::Illrequests',
107 status_alias => undef,
113 my $bob = $builder->build_object(
115 class => 'Koha::Illrequests',
118 status_alias => 'BOB',
124 my $req2 = $builder->build_object(
126 class => 'Koha::Illrequests',
129 status_alias => undef,
136 my $backend_module = Koha::Illbackend->new;
138 my $existing_statuses = $backend_module->existing_statuses('Mock');
140 is( @{$existing_statuses}, 4, "Return 4 unique existing statuses" );
142 # FIXME: Add tests to check content and order of return
143 my $expected_statuses = [
144 { code => 'CHK', str => 'Checked out' },
145 { code => 'READY', str => 'Ready' },
146 { code => 'REQ', str => 'Requested' },
147 { code => 'BOB', str => 'Bob is the best status' }
150 is_deeply( $existing_statuses, $expected_statuses, 'Deep match on return' );
152 $schema->storage->txn_rollback;