View | Details | Raw Unified | Return to bug 12445
Collapse All | Expand All

(-)a/t/db_dependent/Suggestions.t (-30 / +136 lines)
Lines 1-19 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!
4
# Add more tests here!!!
5
2
6
use strict;
3
use strict;
7
use warnings;
4
use warnings;
8
use Modern::Perl;
5
use Modern::Perl;
9
use Data::Dumper;
6
use Data::Dumper;
10
7
11
use C4::Suggestions;
12
use C4::Context;
8
use C4::Context;
13
use C4::Members;
9
use C4::Members;
14
use C4::Letters;
10
use C4::Letters;
15
11
16
use Test::More tests => 32;
12
use Test::More tests => 89;
17
13
18
BEGIN {
14
BEGIN {
19
    use_ok('C4::Suggestions');
15
    use_ok('C4::Suggestions');
Lines 30-51 $dbh->do(q|DELETE FROM letter|); Link Here
30
$dbh->do(q|DELETE FROM message_queue|);
26
$dbh->do(q|DELETE FROM message_queue|);
31
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|);
27
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|);
32
28
33
my $borrowernumber = AddMember(
29
my $member = {
34
    firstname    => 'my firstname',
30
    firstname => 'my firstname',
35
    surname      => 'my surname',
31
    surname => 'my surname',
36
    categorycode => 'S',
32
    categorycode => 'S',
37
    branchcode   => 'CPL',
33
    branchcode => 'CPL',
38
);
34
};
35
my $borrowernumber = AddMember(%$member);
39
36
37
my $biblionumber1 = 1;
40
my $my_suggestion = {
38
my $my_suggestion = {
41
    title         => 'my title',
39
    title         => 'my title',
42
    author        => 'my author',
40
    author        => 'my author',
43
    publishercode => 'my publishercode',
41
    publishercode => 'my publishercode',
44
    suggestedby   => $borrowernumber,
42
    suggestedby   => $borrowernumber,
45
    biblionumber  => 1,
43
    biblionumber  => $biblionumber1,
46
};
44
};
45
46
47
is( CountSuggestion(), 0, 'CountSuggestion without the status returns 0' );
48
is( CountSuggestion('ASKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
49
is( CountSuggestion('CHECKED'), 0, 'CountSuggestion returns the correct number of suggestions' );
50
is( CountSuggestion('ACCEPTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
51
is( CountSuggestion('REJECTED'), 0, 'CountSuggestion returns the correct number of suggestions' );
52
53
47
my $my_suggestionid = NewSuggestion($my_suggestion);
54
my $my_suggestionid = NewSuggestion($my_suggestion);
48
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
55
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
56
57
is( GetSuggestion(), undef, 'GetSuggestion without the suggestion id returns undef' );
49
my $suggestion = GetSuggestion($my_suggestionid);
58
my $suggestion = GetSuggestion($my_suggestionid);
50
is( $suggestion->{title}, $my_suggestion->{title}, 'NewSuggestion stores the title correctly' );
59
is( $suggestion->{title}, $my_suggestion->{title}, 'NewSuggestion stores the title correctly' );
51
is( $suggestion->{author}, $my_suggestion->{author}, 'NewSuggestion stores the author correctly' );
60
is( $suggestion->{author}, $my_suggestion->{author}, 'NewSuggestion stores the author correctly' );
Lines 53-71 is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestio Link Here
53
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' );
62
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'NewSuggestion stores the borrower number correctly' );
54
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' );
63
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'NewSuggestion stores the biblio number correctly' );
55
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
64
is( $suggestion->{STATUS}, 'ASKED', 'NewSuggestion stores a suggestion with the status ASKED by default' );
56
$suggestion = GetSuggestion();
57
is( $suggestion, undef, 'GetSuggestion without the suggestion id returns undef' );
58
65
66
is( CountSuggestion('ASKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
59
67
60
my $status = ModSuggestion();
61
is( $status, undef, 'ModSuggestion without arguments returns undef' );
62
68
69
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
63
my $mod_suggestion1 = {
70
my $mod_suggestion1 = {
64
    title         => 'my modified title',
71
    title         => 'my modified title',
65
    author        => 'my modified author',
72
    author        => 'my modified author',
66
    publishercode => 'my modified publishercode',
73
    publishercode => 'my modified publishercode',
67
};
74
};
68
$status = ModSuggestion($mod_suggestion1);
75
my $status = ModSuggestion($mod_suggestion1);
69
is( $status, '0E0', 'ModSuggestion without the suggestion id returns 0E0' );
76
is( $status, '0E0', 'ModSuggestion without the suggestion id returns 0E0' );
70
77
71
$mod_suggestion1->{suggestionid} = $my_suggestionid;
78
$mod_suggestion1->{suggestionid} = $my_suggestionid;
Lines 93-119 $messages = C4::Letters::GetQueuedMessages({ Link Here
93
});
100
});
94
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
101
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
95
102
103
is( CountSuggestion('CHECKED'), 1, 'CountSuggestion returns the correct number of suggestions' );
104
105
106
is( GetSuggestionInfo(), undef, 'GetSuggestionInfo without the suggestion id returns undef' );
107
$suggestion = GetSuggestionInfo($my_suggestionid);
108
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfo returns the suggestion id correctly' );
109
is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfo returns the title correctly' );
110
is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfo returns the author correctly' );
111
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfo returns the publisher code correctly' );
112
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfo returns the borrower number correctly' );
113
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfo returns the biblio number correctly' );
114
is( $suggestion->{STATUS}, $mod_suggestion2->{STATUS}, 'GetSuggestionInfo returns the status correctly' );
115
is( $suggestion->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionInfo returns the surname correctly' );
116
is( $suggestion->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionInfo returns the firstname correctly' );
117
is( $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfo returns the borrower number correctly' );
118
119
120
is( GetSuggestionFromBiblionumber(), undef, 'GetSuggestionFromBiblionumber without the biblio number returns undef' );
121
is( GetSuggestionFromBiblionumber(2), undef, 'GetSuggestionFromBiblionumber with an invalid biblio number returns undef' );
122
is( GetSuggestionFromBiblionumber($biblionumber1), $my_suggestionid, 'GetSuggestionFromBiblionumber functions correctly' );
123
124
125
is( GetSuggestionInfoFromBiblionumber(), undef, 'GetSuggestionInfoFromBiblionumber without the biblio number returns undef' );
126
is( GetSuggestionInfoFromBiblionumber(2), undef, 'GetSuggestionInfoFromBiblionumber with an invalid biblio number returns undef' );
127
$suggestion = GetSuggestionInfoFromBiblionumber($biblionumber1);
128
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfoFromBiblionumber returns the suggestion id correctly' );
129
is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfoFromBiblionumber returns the title correctly' );
130
is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfoFromBiblionumber returns the author correctly' );
131
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfoFromBiblionumber returns the publisher code correctly' );
132
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumber returns the borrower number correctly' );
133
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfoFromBiblionumber returns the biblio number correctly' );
134
is( $suggestion->{STATUS}, $mod_suggestion2->{STATUS}, 'GetSuggestionInfoFromBiblionumber returns the status correctly' );
135
is( $suggestion->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionInfoFromBiblionumber returns the surname correctly' );
136
is( $suggestion->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionInfoFromBiblionumber returns the firstname correctly' );
137
is( $suggestion->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumeber returns the borrower number correctly' );
138
139
140
my $suggestions = GetSuggestionByStatus();
141
is( @$suggestions, 0, 'GetSuggestionByStatus without the status returns an empty array' );
142
$suggestions = GetSuggestionByStatus('CHECKED');
143
is( @$suggestions, 1, 'GetSuggestionByStatus returns the correct number of suggestions' );
144
is( $suggestions->[0]->{suggestionid}, $my_suggestionid, 'GetSuggestionByStatus returns the suggestion id correctly' );
145
is( $suggestions->[0]->{title}, $mod_suggestion1->{title}, 'GetSuggestionByStatus returns the title correctly' );
146
is( $suggestions->[0]->{author}, $mod_suggestion1->{author}, 'GetSuggestionByStatus returns the author correctly' );
147
is( $suggestions->[0]->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionByStatus returns the publisher code correctly' );
148
is( $suggestions->[0]->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionByStatus returns the borrower number correctly' );
149
is( $suggestions->[0]->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionByStatus returns the biblio number correctly' );
150
is( $suggestions->[0]->{STATUS}, $mod_suggestion2->{STATUS}, 'GetSuggestionByStatus returns the status correctly' );
151
is( $suggestions->[0]->{surnamesuggestedby}, $member->{surname}, 'GetSuggestionByStatus returns the surname correctly' );
152
is( $suggestions->[0]->{firstnamesuggestedby}, $member->{firstname}, 'GetSuggestionByStatus returns the firstname correctly' );
153
is( $suggestions->[0]->{branchcodesuggestedby}, $member->{branchcode}, 'GetSuggestionByStatus returns the branch code correctly' );
154
is( $suggestions->[0]->{borrnumsuggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionByStatus returns the borrower number correctly' );
155
is( $suggestions->[0]->{categorycodesuggestedby}, $member->{categorycode}, 'GetSuggestionByStatus returns the category code correctly' );
156
157
158
is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arguments returns 0E0' );
159
my $biblionumber2 = 2;
160
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio($my_suggestionid, $biblionumber2);
161
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' );
162
$suggestion = GetSuggestion($my_suggestionid);
163
is( $suggestion->{biblionumber}, $biblionumber2, 'ConnectSuggestionAndBiblio updates the biblio number correctly' );
96
164
97
my $biblionumber = 1;
98
my $suggestionid = GetSuggestionFromBiblionumber($biblionumber);
99
is( $suggestionid, $my_suggestionid, 'GetSuggestionFromBiblionumber functions correctly' );
100
165
166
my $search_suggestion = SearchSuggestion();
167
is( @$search_suggestion, 1, 'SearchSuggestion without arguments returns all suggestions' );
101
168
102
$suggestion = GetSuggestionInfoFromBiblionumber($biblionumber);
169
$search_suggestion = SearchSuggestion({
103
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfoFromBiblionumber gets the suggestion id correctly' );
170
    title => $mod_suggestion1->{title},
171
});
172
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
173
$search_suggestion = SearchSuggestion({
174
    title => 'another title',
175
});
176
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
104
177
105
is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfoFromBiblionumber gets the title correctly' );
178
$search_suggestion = SearchSuggestion({
106
is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfoFromBiblionumber gets the author correctly' );
179
    author => $mod_suggestion1->{author},
107
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfoFromBiblionumber gets the publisher code correctly' );
180
});
108
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumber gets the borrower number correctly' );
181
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
109
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfoFromBiblionumber gets the biblio number correctly' );
182
$search_suggestion = SearchSuggestion({
110
is( $suggestion->{STATUS}, $mod_suggestion2->{STATUS}, 'GetSuggestionInfoFromBiblionumber gets the status correctly' );
183
    author => 'another author',
184
});
185
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
111
186
187
$search_suggestion = SearchSuggestion({
188
    publishercode => $mod_suggestion2->{publishercode},
189
});
190
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
191
$search_suggestion = SearchSuggestion({
192
    publishercode => 'another publishercode',
193
});
194
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
112
195
113
my $search_suggestion = SearchSuggestion({
196
$search_suggestion = SearchSuggestion({
114
    STATUS => $mod_suggestion2->{STATUS},
197
    STATUS => $mod_suggestion2->{STATUS},
115
});
198
});
116
is( @$search_suggestion, 1, '' );
199
is( @$search_suggestion, 1, 'SearchSuggestion returns the correct number of suggestions' );
200
$search_suggestion = SearchSuggestion({
201
    STATUS => 'REJECTED',
202
});
203
is( @$search_suggestion, 0, 'SearchSuggestion returns the correct number of suggestions' );
204
205
206
my $del_suggestion = {
207
    title => 'my deleted title',
208
    STATUS => 'CHECKED',
209
    suggestedby => $borrowernumber,
210
};
211
my $del_suggestionid = NewSuggestion($del_suggestion);
212
213
is( CountSuggestion('CHECKED'), 2, 'CountSuggestion returns the correct number of suggestions' );
214
215
is( DelSuggestion(), '0E0', 'DelSuggestion without arguments returns 0E0' );
216
is( DelSuggestion($borrowernumber), '', 'DelSuggestion without the suggestion id returns an empty string' );
217
is( DelSuggestion(undef, $my_suggestionid), '', 'DelSuggestion with an invalid borrower number returns an empty string' );
218
$suggestion = DelSuggestion($borrowernumber, $my_suggestionid);
219
is( $suggestion, 1, 'DelSuggestion deletes one suggestion' );
220
221
$suggestions = GetSuggestionByStatus('CHECKED');
222
is( @$suggestions, 1, 'DelSuggestion deletes one suggestion' );
223
is( $suggestions->[0]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
117
224
118
225
119
## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values
226
## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values
120
- 

Return to bug 12445