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

(-)a/t/db_dependent/Suggestions.t (-17 / +103 lines)
Lines 18-25 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use C4::Suggestions;
20
use C4::Suggestions;
21
use C4::Context;
22
use C4::Members;
23
use C4::Letters;
21
24
22
use Test::More tests => 14;
25
use Test::More tests => 34;
23
use Test::Warn;
26
use Test::Warn;
24
27
25
BEGIN {
28
BEGIN {
Lines 33-63 my $dbh = C4::Context->dbh; Link Here
33
$dbh->{AutoCommit} = 0;
36
$dbh->{AutoCommit} = 0;
34
$dbh->{RaiseError} = 1;
37
$dbh->{RaiseError} = 1;
35
38
36
my ($suggestionid, $suggestion, $status, $biblionumber);
39
$dbh->do(q|DELETE FROM suggestions|);
37
$biblionumber = 1;
40
$dbh->do(q|DELETE FROM borrowers|);
38
ok($suggestionid= NewSuggestion( {title=>'Petit traité de philosohpie',author=>'Hubert de Chardassé',publishercode=>'Albin Michel'} ), "NewSuggestion OK");
41
$dbh->do(q|DELETE FROM letter|);
39
ok($suggestion= GetSuggestion( $suggestionid), "GetSuggestion OK");
42
$dbh->do(q|DELETE FROM message_queue|);
40
ok($status= ModSuggestion( {title=>'test Modif Simple', suggestionid=>$suggestionid} ), "ModSuggestion Simple OK");
43
$dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHECKED', 'my content')|);
41
warning_is { $status = ModSuggestion( {STATUS=>'STALLED', suggestionid=>$suggestionid} )}
44
45
my $borrowernumber = AddMember(
46
    firstname    => 'my firstname',
47
    surname      => 'my surname',
48
    categorycode => 'S',
49
    branchcode   => 'CPL',
50
);
51
52
my $my_suggestion = {
53
    title         => 'my title',
54
    author        => 'my author',
55
    publishercode => 'my publishercode',
56
    suggestedby   => $borrowernumber,
57
    biblionumber  => 1,
58
};
59
my $my_suggestionid = NewSuggestion($my_suggestion);
60
isnt( $my_suggestionid, 0, 'NewSuggestion returns an not null id' );
61
my $suggestion = GetSuggestion($my_suggestionid);
62
is( $suggestion->{title}, $my_suggestion->{title}, 'NewSuggestion stores the title correctly' );
63
is( $suggestion->{author}, $my_suggestion->{author}, 'NewSuggestion stores the author correctly' );
64
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'NewSuggestion stores the publishercode correctly' );
65
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' );
67
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
71
72
my $status = ModSuggestion();
73
is( $status, undef, 'ModSuggestion without arguments returns undef' );
74
75
my $mod_suggestion1 = {
76
    title         => 'my modified title',
77
    author        => 'my modified author',
78
    publishercode => 'my modified publishercode',
79
};
80
$status = ModSuggestion($mod_suggestion1);
81
is( $status, '0E0', 'ModSuggestion without the suggestion id returns 0E0' );
82
83
$mod_suggestion1->{suggestionid} = $my_suggestionid;
84
$status = ModSuggestion($mod_suggestion1);
85
is( $status, 1, 'ModSuggestion modifies one entry' );
86
$suggestion = GetSuggestion($my_suggestionid);
87
is( $suggestion->{title}, $mod_suggestion1->{title}, 'ModSuggestion modifies the title  correctly' );
88
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
89
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'ModSuggestion modifies the publishercode correctly' );
90
my $messages = C4::Letters::GetQueuedMessages({
91
    borrowernumber => $borrowernumber,
92
});
93
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
94
95
my $mod_suggestion2 = {
96
    STATUS       => 'STALLED',
97
    suggestionid => $my_suggestionid,
98
};
99
warning_is { $status = ModSuggestion($mod_suggestion2) }
42
           "No suggestions STALLED letter transported by email",
100
           "No suggestions STALLED letter transported by email",
43
           "ModSuggestion status warning is correct";
101
           "ModSuggestion status warning is correct";
44
ok( $status, "ModSuggestion Status OK");
102
is( $status, 1, "ModSuggestion Status OK");
45
ok($status= ModSuggestion( {suggestionid => $suggestionid, biblionumber => $biblionumber } ), "ModSuggestion, set biblionumber OK" );
103
46
ok($suggestion= GetSuggestionFromBiblionumber( $biblionumber ), "GetSuggestionFromBiblionumber OK");
104
my $mod_suggestion3 = {
47
ok($suggestion= GetSuggestionInfoFromBiblionumber( $biblionumber ), "GetSuggestionInfoFromBiblionumber OK");
105
    STATUS       => 'CHECKED',
48
ok(@{SearchSuggestion( {STATUS=>'STALLED'} )}>0, "SearchSuggestion Status OK");
106
    suggestionid => $my_suggestionid,
107
};
108
$status = ModSuggestion($mod_suggestion3);
109
110
is( $status, 1, 'ModSuggestion modifies one entry' );
111
$suggestion = GetSuggestion($my_suggestionid);
112
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
113
$messages = C4::Letters::GetQueuedMessages({
114
    borrowernumber => $borrowernumber,
115
});
116
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
117
118
my $biblionumber = 1;
119
my $suggestionid = GetSuggestionFromBiblionumber($biblionumber);
120
is( $suggestionid, $my_suggestionid, 'GetSuggestionFromBiblionumber functions correctly' );
121
122
123
$suggestion = GetSuggestionInfoFromBiblionumber($biblionumber);
124
is( $suggestion->{suggestionid}, $my_suggestionid, 'GetSuggestionInfoFromBiblionumber gets the suggestion id correctly' );
125
126
is( $suggestion->{title}, $mod_suggestion1->{title}, 'GetSuggestionInfoFromBiblionumber gets the title correctly' );
127
is( $suggestion->{author}, $mod_suggestion1->{author}, 'GetSuggestionInfoFromBiblionumber gets the author correctly' );
128
is( $suggestion->{publishercode}, $mod_suggestion1->{publishercode}, 'GetSuggestionInfoFromBiblionumber gets the publisher code correctly' );
129
is( $suggestion->{suggestedby}, $my_suggestion->{suggestedby}, 'GetSuggestionInfoFromBiblionumber gets the borrower number correctly' );
130
is( $suggestion->{biblionumber}, $my_suggestion->{biblionumber}, 'GetSuggestionInfoFromBiblionumber gets the biblio number correctly' );
131
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'GetSuggestionInfoFromBiblionumber gets the status correctly' );
132
133
134
my $search_suggestion = SearchSuggestion({
135
    STATUS => $mod_suggestion3->{STATUS},
136
});
137
is( @$search_suggestion, 1, '' );
49
138
50
## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values
139
## Bug 11466, making sure GetSupportList() returns itemtypes, even if AdvancedSearchTypes has multiple values
51
C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode');
140
C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes|loc|ccode');
52
my $itemtypes1 = C4::Koha::GetSupportList();
141
my $itemtypes1 = C4::Koha::GetSupportList();
53
ok(scalar @$itemtypes1, "Purchase suggestion itemtypes collected, multiple AdvancedSearchTypes");
142
is(@$itemtypes1, 8, "Purchase suggestion itemtypes collected, multiple AdvancedSearchTypes");
54
143
55
C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes');
144
C4::Context->set_preference("AdvancedSearchTypes", 'itemtypes');
56
my $itemtypes2 = C4::Koha::GetSupportList();
145
my $itemtypes2 = C4::Koha::GetSupportList();
57
ok(scalar @$itemtypes2, "Purchase suggestion itemtypes collected, default AdvancedSearchTypes");
146
is(@$itemtypes2, 8, "Purchase suggestion itemtypes collected, default AdvancedSearchTypes");
58
147
59
is_deeply($itemtypes1, $itemtypes2, 'same set of purchase suggestion formats retrieved');
148
is_deeply($itemtypes1, $itemtypes2, 'same set of purchase suggestion formats retrieved');
60
149
61
$dbh->rollback;
150
$dbh->rollback;
62
63
1;
64
- 

Return to bug 12445