From a363bba1adfa2a6e315782fcbdc6f71a28a65aed Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 27 Jul 2023 13:50:24 +0000 Subject: [PATCH] Bug 34223: (follow-up) Mock backend in tests Add a new request with a backend specific status --- t/db_dependent/Koha/Illbackend.t | 50 +++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/Koha/Illbackend.t b/t/db_dependent/Koha/Illbackend.t index f78144a17d..b5874881b3 100644 --- a/t/db_dependent/Koha/Illbackend.t +++ b/t/db_dependent/Koha/Illbackend.t @@ -31,11 +31,40 @@ my $schema = Koha::Database->new->schema; subtest 'existing_statuses() tests' => sub { - plan tests => 4; + plan tests => 1; $schema->storage->txn_begin; Koha::Illrequests->search->delete; + # Mock ILLBackend (as object) + my $backend = Test::MockObject->new; + $backend->set_isa('Koha::Illbackends::Mock'); + $backend->set_always( 'name', 'Mock' ); + + # 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 } + ); + + $illreqmodule->mock( + 'capabilities', + sub { + return { + READY => { + prev_actions => [ 'NEW', 'REQREV', 'QUEUED', 'CANCREQ' ], + id => 'REQ', + name => 'Requested', + ui_method_name => 'Confirm request', + method => 'confirm', + next_actions => [ 'REQREV', 'COMP', 'CHK' ], + ui_method_icon => 'fa-check', + } + }; + }, + ); + my $alias = $builder->build_object( { class => 'Koha::AuthorisedValues', @@ -47,36 +76,43 @@ subtest 'existing_statuses() tests' => sub { } ); + my $backend_req_status = $builder->build_object( + { + class => 'Koha::Illrequests', + value => { status => 'READY', status_alias => undef, biblio_id => undef, backend => 'Mock' } + } + ); + my $req = $builder->build_object( { class => 'Koha::Illrequests', - value => { status => 'REQ', status_alias => undef, biblio_id => undef, backend => 'FreeForm' } + value => { status => 'REQ', status_alias => undef, biblio_id => undef, backend => 'Mock' } } ); my $chk = $builder->build_object( { class => 'Koha::Illrequests', - value => { status => 'CHK', status_alias => undef, biblio_id => undef, backend => 'FreeForm' } + value => { status => 'CHK', status_alias => undef, biblio_id => undef, backend => 'Mock' } } ); my $bob = $builder->build_object( { class => 'Koha::Illrequests', - value => { status => 'REQ', status_alias => 'BOB', biblio_id => undef, backend => 'FreeForm' } + value => { status => 'REQ', status_alias => 'BOB', biblio_id => undef, backend => 'Mock' } } ); my $req2 = $builder->build_object( { class => 'Koha::Illrequests', - value => { status => 'REQ', status_alias => undef, biblio_id => undef, backend => 'FreeForm' } + value => { status => 'REQ', status_alias => undef, biblio_id => undef, backend => 'Mock' } } ); my $backend_module = Koha::Illbackend->new; - my $existing_statuses = $backend_module->existing_statuses('FreeForm'); + my $existing_statuses = $backend_module->existing_statuses('Mock'); - is( @{$existing_statuses}, 3, "Return 3 unique existing statuses" ); + is( @{$existing_statuses}, 4, "Return 4 unique existing statuses" ); # FIXME: Add tests to check content and order of return -- 2.30.2