Bug 10519: (followup) unit tests leave problematic cruft
[koha.git] / t / db_dependent / Suggestions.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use C4::Suggestions;
21
22 use Test::More tests => 14;
23 use Test::Warn;
24
25 BEGIN {
26     use_ok('C4::Suggestions');
27     use_ok('C4::Koha');
28 }
29
30 my $dbh = C4::Context->dbh;
31
32 # Start transaction
33 $dbh->{AutoCommit} = 0;
34 $dbh->{RaiseError} = 1;
35
36 my ($suggestionid, $suggestion, $status, $biblionumber);
37 $biblionumber = 1;
38 ok($suggestionid= NewSuggestion( {title=>'Petit traité de philosohpie',author=>'Hubert de Chardassé',publishercode=>'Albin Michel'} ), "NewSuggestion OK");
39 ok($suggestion= GetSuggestion( $suggestionid), "GetSuggestion OK");
40 ok($status= ModSuggestion( {title=>'test Modif Simple', suggestionid=>$suggestionid} ), "ModSuggestion Simple OK");
41 warning_is { $status = ModSuggestion( {STATUS=>'STALLED', suggestionid=>$suggestionid} )}
42            "No suggestions STALLED letter transported by email",
43            "ModSuggestion status warning is correct";
44 ok( $status, "ModSuggestion Status OK");
45 ok($status= ModSuggestion( {suggestionid => $suggestionid, biblionumber => $biblionumber } ), "ModSuggestion, set biblionumber OK" );
46 ok($suggestion= GetSuggestionFromBiblionumber( $biblionumber ), "GetSuggestionFromBiblionumber OK");
47 ok($suggestion= GetSuggestionInfoFromBiblionumber( $biblionumber ), "GetSuggestionInfoFromBiblionumber OK");
48 ok(@{SearchSuggestion( {STATUS=>'STALLED'} )}>0, "SearchSuggestion Status OK");
49
50 ## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values
51 C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode');
52 my $itemtypes1 = C4::Koha::GetSupportList();
53 ok(scalar @$itemtypes1, "Purchase suggestion itemtypes collected, multiple AdvancedSearchTypes");
54
55 C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes');
56 my $itemtypes2 = C4::Koha::GetSupportList();
57 ok(scalar @$itemtypes2, "Purchase suggestion itemtypes collected, default AdvancedSearchTypes");
58
59 is_deeply($itemtypes1, $itemtypes2, 'same set of purchase suggestion formats retrieved');
60
61 $dbh->rollback;
62
63 1;