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