|
Lines 17-28
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use C4::Suggestions; |
|
|
| 21 |
use C4::Context; |
20 |
use C4::Context; |
| 22 |
use C4::Members; |
21 |
use C4::Members; |
| 23 |
use C4::Letters; |
22 |
use C4::Letters; |
| 24 |
|
23 |
|
| 25 |
use Test::More tests => 34; |
24 |
use Test::More tests => 91; |
| 26 |
use Test::Warn; |
25 |
use Test::Warn; |
| 27 |
|
26 |
|
| 28 |
BEGIN { |
27 |
BEGIN { |
|
Lines 42-63
$dbh->do(q|DELETE FROM letter|);
Link Here
|
| 42 |
$dbh->do(q|DELETE FROM message_queue|); |
41 |
$dbh->do(q|DELETE FROM message_queue|); |
| 43 |
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|); |
42 |
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|); |
| 44 |
|
43 |
|
| 45 |
my $borrowernumber = AddMember( |
44 |
my $member = { |
| 46 |
firstname => 'my firstname', |
45 |
firstname => 'my firstname', |
| 47 |
surname => 'my surname', |
46 |
surname => 'my surname', |
| 48 |
categorycode => 'S', |
47 |
categorycode => 'S', |
| 49 |
branchcode => 'CPL', |
48 |
branchcode => 'CPL', |
| 50 |
); |
49 |
}; |
|
|
50 |
my $borrowernumber = AddMember(%$member); |
| 51 |
|
51 |
|
|
|
52 |
my $biblionumber1 = 1; |
| 52 |
my $my_suggestion = { |
53 |
my $my_suggestion = { |
| 53 |
title => 'my title', |
54 |
title => 'my title', |
| 54 |
author => 'my author', |
55 |
author => 'my author', |
| 55 |
publishercode => 'my publishercode', |
56 |
publishercode => 'my publishercode', |
| 56 |
suggestedby => $borrowernumber, |
57 |
suggestedby => $borrowernumber, |
| 57 |
biblionumber => 1, |
58 |
biblionumber => $biblionumber1, |
| 58 |
}; |
59 |
}; |
|
|
60 |
|
| 61 |
|
| 62 |
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' ); |
| 63 |
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
| 64 |
is( CountSuggestion('CHECKED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
| 65 |
is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
| 66 |
is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' ); |
| 67 |
|
| 68 |
|
| 59 |
my $my_suggestionid = NewSuggestion($my_suggestion); |
69 |
my $my_suggestionid = NewSuggestion($my_suggestion); |
| 60 |
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' ); |
70 |
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' ); |
|
|
71 |
|
| 72 |
is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' ); |
| 61 |
my $suggestion = GetSuggestion($my_suggestionid); |
73 |
my $suggestion = GetSuggestion($my_suggestionid); |
| 62 |
is( $suggestion->{title}, $my_suggestion->{title}, 'NewSuggestion stores the title correctly' ); |
74 |
is( $suggestion->{title}, $my_suggestion->{title}, 'NewSuggestion stores the title correctly' ); |
| 63 |
is( $suggestion->{author}, $my_suggestion->{author}, 'NewSuggestion stores the author correctly' ); |
75 |
is( $suggestion->{author}, $my_suggestion->{author}, 'NewSuggestion stores the author correctly' ); |
|
Lines 65-83
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestio
Link Here
|
| 65 |
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' ); |
77 |
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' ); |
| 66 |
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' ); |
78 |
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' ); |
| 67 |
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' ); |
79 |
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' ); |
| 68 |
$suggestion = GetSuggestion(); |
|
|
| 69 |
is( $suggestion, undef, 'GetSuggestion without the suggestion id returns undef' ); |
| 70 |
|
80 |
|
|
|
81 |
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
| 71 |
|
82 |
|
| 72 |
my $status = ModSuggestion(); |
|
|
| 73 |
is( $status, undef, 'ModSuggestion without arguments returns undef' ); |
| 74 |
|
83 |
|
|
|
84 |
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' ); |
| 75 |
my $mod_suggestion1 = { |
85 |
my $mod_suggestion1 = { |
| 76 |
title => 'my modified title', |
86 |
title => 'my modified title', |
| 77 |
author => 'my modified author', |
87 |
author => 'my modified author', |
| 78 |
publishercode => 'my modified publishercode', |
88 |
publishercode => 'my modified publishercode', |
| 79 |
}; |
89 |
}; |
| 80 |
$status = ModSuggestion($mod_suggestion1); |
90 |
my $status = ModSuggestion($mod_suggestion1); |
| 81 |
is( $status, '0E0', 'ModSuggestion without the suggestion id returns 0E0' ); |
91 |
is( $status, '0E0', 'ModSuggestion without the suggestion id returns 0E0' ); |
| 82 |
|
92 |
|
| 83 |
$mod_suggestion1->{suggestionid} = $my_suggestionid; |
93 |
$mod_suggestion1->{suggestionid} = $my_suggestionid; |
|
Lines 115-140
$messages = C4::Letters::GetQueuedMessages({
Link Here
|
| 115 |
}); |
125 |
}); |
| 116 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
126 |
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' ); |
| 117 |
|
127 |
|
| 118 |
my $biblionumber = 1; |
128 |
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' ); |
| 119 |
my $suggestionid = GetSuggestionFromBiblionumber($biblionumber); |
129 |
|
| 120 |
is( $suggestionid, $my_suggestionid, 'GetSuggestionFromBiblionumber functions correctly' ); |
130 |
|
|
|
131 |
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' ); |
| 132 |
$suggestion = GetSuggestionInfo($my_suggestionid); |
| 133 |
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' ); |
| 134 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfo returns the title correctly' ); |
| 135 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfo returns the author correctly' ); |
| 136 |
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfo returns the publisher code correctly' ); |
| 137 |
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfo returns the borrower number correctly' ); |
| 138 |
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfo returns the biblio number correctly' ); |
| 139 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionInfo returns the status correctly' ); |
| 140 |
is( $suggestion->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionInfo returns the surname correctly' ); |
| 141 |
is( $suggestion->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionInfo returns the firstname correctly' ); |
| 142 |
is( $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfo returns the borrower number correctly' ); |
| 143 |
|
| 144 |
|
| 145 |
is( GetSuggestionFromBiblionumber(), undef, 'GetSuggestionFromBiblionumber without the biblio number returns undef' ); |
| 146 |
is( GetSuggestionFromBiblionumber(2), undef, 'GetSuggestionFromBiblionumber with an invalid biblio number returns undef' ); |
| 147 |
is( GetSuggestionFromBiblionumber($biblionumber1), $my_suggestionid, 'GetSuggestionFromBiblionumber functions correctly' ); |
| 148 |
|
| 149 |
|
| 150 |
is( GetSuggestionInfoFromBiblionumber(), undef, 'GetSuggestionInfoFromBiblionumber without the biblio number returns undef' ); |
| 151 |
is( GetSuggestionInfoFromBiblionumber(2), undef, 'GetSuggestionInfoFromBiblionumber with an invalid biblio number returns undef' ); |
| 152 |
$suggestion = GetSuggestionInfoFromBiblionumber($biblionumber1); |
| 153 |
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfoFromBiblionumber returns the suggestion id correctly' ); |
| 154 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfoFromBiblionumber returns the title correctly' ); |
| 155 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfoFromBiblionumber returns the author correctly' ); |
| 156 |
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfoFromBiblionumber returns the publisher code correctly' ); |
| 157 |
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumber returns the borrower number correctly' ); |
| 158 |
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfoFromBiblionumber returns the biblio number correctly' ); |
| 159 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionInfoFromBiblionumber returns the status correctly' ); |
| 160 |
is( $suggestion->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionInfoFromBiblionumber returns the surname correctly' ); |
| 161 |
is( $suggestion->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionInfoFromBiblionumber returns the firstname correctly' ); |
| 162 |
is( $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumeber returns the borrower number correctly' ); |
| 163 |
|
| 164 |
|
| 165 |
my $suggestions = GetSuggestionByStatus(); |
| 166 |
is( @$suggestions, 0, 'GetSuggestionByStatus without the status returns an empty array' ); |
| 167 |
$suggestions = GetSuggestionByStatus('CHECKED'); |
| 168 |
is( @$suggestions, 1, 'GetSuggestionByStatus returns the correct number of suggestions' ); |
| 169 |
is( $suggestions->[0]->{suggestionid}, $my_suggestionid, 'GetSuggestionByStatus returns the suggestion id correctly' ); |
| 170 |
is( $suggestions->[0]->{title}, $mod_suggestion1->{title}, 'GetSuggestionByStatus returns the title correctly' ); |
| 171 |
is( $suggestions->[0]->{author}, $mod_suggestion1->{author}, 'GetSuggestionByStatus returns the author correctly' ); |
| 172 |
is( $suggestions->[0]->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionByStatus returns the publisher code correctly' ); |
| 173 |
is( $suggestions->[0]->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionByStatus returns the borrower number correctly' ); |
| 174 |
is( $suggestions->[0]->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionByStatus returns the biblio number correctly' ); |
| 175 |
is( $suggestions->[0]->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionByStatus returns the status correctly' ); |
| 176 |
is( $suggestions->[0]->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionByStatus returns the surname correctly' ); |
| 177 |
is( $suggestions->[0]->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionByStatus returns the firstname correctly' ); |
| 178 |
is( $suggestions->[0]->{branchcodesuggestedby}, $member->{branchcode}, 'GetSuggestionByStatus returns the branch code correctly' ); |
| 179 |
is( $suggestions->[0]->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionByStatus returns the borrower number correctly' ); |
| 180 |
is( $suggestions->[0]->{categorycodesuggestedby}, $member->{categorycode}, 'GetSuggestionByStatus returns the category code correctly' ); |
| 181 |
|
| 182 |
|
| 183 |
is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arguments returns 0E0' ); |
| 184 |
my $biblionumber2 = 2; |
| 185 |
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio($my_suggestionid, $biblionumber2); |
| 186 |
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' ); |
| 187 |
$suggestion = GetSuggestion($my_suggestionid); |
| 188 |
is( $suggestion->{biblionumber}, $biblionumber2, 'ConnectSuggestionAndBiblio updates the biblio number correctly' ); |
| 121 |
|
189 |
|
| 122 |
|
190 |
|
| 123 |
$suggestion = GetSuggestionInfoFromBiblionumber($biblionumber); |
191 |
my $search_suggestion = SearchSuggestion(); |
| 124 |
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfoFromBiblionumber gets the suggestion id correctly' ); |
192 |
is( @$search_suggestion, 1, 'SearchSuggestion without arguments returns all suggestions' ); |
|
|
193 |
|
| 194 |
$search_suggestion = SearchSuggestion({ |
| 195 |
title => $mod_suggestion1->{title}, |
| 196 |
}); |
| 197 |
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' ); |
| 198 |
$search_suggestion = SearchSuggestion({ |
| 199 |
title => 'another title', |
| 200 |
}); |
| 201 |
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' ); |
| 125 |
|
202 |
|
| 126 |
is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfoFromBiblionumber gets the title correctly' ); |
203 |
$search_suggestion = SearchSuggestion({ |
| 127 |
is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfoFromBiblionumber gets the author correctly' ); |
204 |
author => $mod_suggestion1->{author}, |
| 128 |
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfoFromBiblionumber gets the publisher code correctly' ); |
205 |
}); |
| 129 |
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumber gets the borrower number correctly' ); |
206 |
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' ); |
| 130 |
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfoFromBiblionumber gets the biblio number correctly' ); |
207 |
$search_suggestion = SearchSuggestion({ |
| 131 |
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionInfoFromBiblionumber gets the status correctly' ); |
208 |
author => 'another author', |
|
|
209 |
}); |
| 210 |
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' ); |
| 132 |
|
211 |
|
|
|
212 |
$search_suggestion = SearchSuggestion({ |
| 213 |
publishercode => $mod_suggestion3->{publishercode}, |
| 214 |
}); |
| 215 |
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' ); |
| 216 |
$search_suggestion = SearchSuggestion({ |
| 217 |
publishercode => 'another publishercode', |
| 218 |
}); |
| 219 |
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' ); |
| 133 |
|
220 |
|
| 134 |
my $search_suggestion = SearchSuggestion({ |
221 |
$search_suggestion = SearchSuggestion({ |
| 135 |
STATUS => $mod_suggestion3->{STATUS}, |
222 |
STATUS => $mod_suggestion3->{STATUS}, |
| 136 |
}); |
223 |
}); |
| 137 |
is( @$search_suggestion, 1, '' ); |
224 |
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' ); |
|
|
225 |
$search_suggestion = SearchSuggestion({ |
| 226 |
STATUS => 'REJECTED', |
| 227 |
}); |
| 228 |
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' ); |
| 229 |
|
| 230 |
|
| 231 |
my $del_suggestion = { |
| 232 |
title => 'my deleted title', |
| 233 |
STATUS => 'CHECKED', |
| 234 |
suggestedby => $borrowernumber, |
| 235 |
}; |
| 236 |
my $del_suggestionid = NewSuggestion($del_suggestion); |
| 237 |
|
| 238 |
is( CountSuggestion('CHECKED'), 2, 'CountSuggestion returns the correct number of suggestions' ); |
| 239 |
|
| 240 |
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' ); |
| 241 |
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' ); |
| 242 |
is( DelSuggestion(undef, $my_suggestionid), '', 'DelSuggestion with an invalid borrower number returns an empty string' ); |
| 243 |
$suggestion = DelSuggestion($borrowernumber, $my_suggestionid); |
| 244 |
is( $suggestion, 1, 'DelSuggestion deletes one suggestion' ); |
| 245 |
|
| 246 |
$suggestions = GetSuggestionByStatus('CHECKED'); |
| 247 |
is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' ); |
| 248 |
is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' ); |
| 138 |
|
249 |
|
| 139 |
## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values |
250 |
## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values |
| 140 |
C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode'); |
251 |
C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode'); |
| 141 |
- |
|
|