From eb172282f17184fd6b9852692b53d224e97ee90b Mon Sep 17 00:00:00 2001 From: Koha Date: Tue, 9 Jun 2015 09:58:58 +0200 Subject: [PATCH] Bug 9223 [Follow-up] add unit tests for GetSupportList and GetSupportName subroutine --- t/db_dependent/Suggestions.t | 69 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index 7e12df9..4526dc2 100644 --- a/t/db_dependent/Suggestions.t +++ b/t/db_dependent/Suggestions.t @@ -25,7 +25,8 @@ use C4::Budgets; use Koha::DateUtils qw( dt_from_string ); -use Test::More tests => 104; +use Test::More tests => 109; +use Test::MockModule; use Test::Warn; BEGIN { @@ -40,6 +41,48 @@ my $sql; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; +my $koha = new Test::MockModule('C4::Koha'); +$koha->mock( + 'GetAuthorisedValues', + sub { + my $category = shift; + + my $ret = []; + if ($category eq 'ccode') { + $ret = [ + { + 'imageurl' => '', + 'authorised_value' => 'TH', + 'lib_opac' => "Thesis", + 'lib' => "Thesis", + 'category' => 'CCODE', + 'id' => '3810', + 'selected' => 0 + }, + { + 'imageurl' => '', + 'authorised_value' => 'BOOK', + 'lib_opac' => 'Book', + 'lib' => 'Book', + 'category' => 'CCODE', + 'id' => '3807', + 'selected' => 0 + }, + + ]; + } + + return $ret; + } +); + +$koha->mock( + 'GetKohaAuthorisedValueLib', + sub { + return 'Thesis'; + } +); + # Reset item types to only the default ones $dbh->do(q|DELETE FROM itemtypes;|); $sql = " @@ -341,16 +384,26 @@ $suggestions = GetSuggestionByStatus('CHECKED'); is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' ); is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' ); -## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values -C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode'); +C4::Context->set_preference('SuggestionsUseValues', 'itemtypes'); my $itemtypes1 = C4::Koha::GetSupportList(); -is(@$itemtypes1, 8, "Purchase suggestion itemtypes collected, multiple AdvancedSearchTypes"); +is(@$itemtypes1, 8, "Purchase suggestion itemtypes collected, SuggestionsUseValues is itemtypes"); +my $mp_description = C4::Koha::GetSupportName('MP'); +is($mp_description, 'Maps', 'Purchase suggestion itemtypes collected, itemtype MP description should be Maps'); + +is($itemtypes1->[0]{'authorised_value'},'BK', "Purchase suggestion itemtypes collected, SuggestionsUseValues is itemtypes first authorized value is BK"); +is($itemtypes1->[0]{'lib'},'Books', "Purchase suggestion itemtypes collected, SuggestionsUseValues is itemtypes first lib is books"); +is($itemtypes1->[0]{'imageurl'},'bridge/book.gif', "Purchase suggestion itemtypes collected, SuggestionsUseValues is itemtypes, first imageurl is bridge/book.gif"); + +C4::Context->set_preference('SuggestionsUseValues', 'ccode'); +my $ccodes = C4::Koha::GetSupportList(); +is(@$ccodes, 2, "Purchase suggestion itemtypes collected, SuggestionsUseValues is ccode"); +my $th_description = C4::Koha::GetSupportName('TH'); +is($th_description, 'Thesis', 'Purchase suggestion itemtypes collected, ccode TH description should be Thesis'); -C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes'); -my $itemtypes2 = C4::Koha::GetSupportList(); -is(@$itemtypes2, 8, "Purchase suggestion itemtypes collected, default AdvancedSearchTypes"); -is_deeply($itemtypes1, $itemtypes2, 'same set of purchase suggestion formats retrieved'); +C4::Context->set_preference('SuggestionsUseValues', 'none'); +my $empty = C4::Koha::GetSupportList(); +is(@$empty, 0, "Purchase suggestion itemtypes collected, SuggestionsUseValues is None"); # Test budgetid fk $my_suggestion->{budgetid} = ''; # If budgetid == '', NULL should be set in DB -- 1.7.10.4