From 04c1267201b7e494f6b4e0d081ac3ba62fcef1a7 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Tue, 17 Apr 2018 17:00:32 +0100 Subject: [PATCH] Bug 20581: Unit tests for status_alias This patch adds unit tests for the specific status_alias functionality added in this bug - Creation of the ILLSTATUS authorised value - Illrequest->statusalias accessor - Illrequest->status overloading to reset status_alias To test: 1) Apply this patch 2) prove t/db_dependent/Illrequests.t --- t/db_dependent/Illrequests.t | 57 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t index 761de9f12b..b40fc9c9cb 100644 --- a/t/db_dependent/Illrequests.t +++ b/t/db_dependent/Illrequests.t @@ -22,13 +22,15 @@ use Koha::Database; use Koha::Illrequestattributes; use Koha::Illrequest::Config; use Koha::Patrons; +use Koha::AuthorisedValueCategories; +use Koha::AuthorisedValues; use t::lib::Mocks; use t::lib::TestBuilder; use Test::MockObject; use Test::MockModule; use Test::Exception; -use Test::More tests => 11; +use Test::More tests => 12; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; @@ -860,3 +862,56 @@ subtest 'TO_JSON() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'Custom statuses' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $cat = Koha::AuthorisedValueCategories->search( + { + category_name => 'ILLSTATUS' + } + ); + + if ($cat->count == 0) { + $cat = $builder->build_object( + { + class => 'Koha::AuthorisedValueCategory', + value => { + category_name => 'ILLSTATUS' + } + } + ); + }; + + my $av = $builder->build_object( + { + class => 'Koha::AuthorisedValues', + value => { + category => 'ILLSTATUS' + } + } + ); + + is($av->category, 'ILLSTATUS', + "Successfully created authorised value for custom status"); + + my $ill_req = $builder->build_object( + { + class => 'Koha::Illrequests', + value => { + status_alias => $av->id + } + } + ); + isa_ok($ill_req->statusalias, 'Koha::AuthorisedValue', + "statusalias correctly returning Koha::AuthorisedValue object"); + + $ill_req->status("COMP"); + is($ill_req->statusalias, undef, + "Koha::Illrequest->status overloading resetting status_alias"); + + $schema->storage->txn_rollback; +}; -- 2.11.0