|
Lines 23-28
use Test::More tests => 11;
Link Here
|
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
|
24 |
|
| 25 |
use Koha::Suggestions; |
25 |
use Koha::Suggestions; |
|
|
26 |
use Koha::Config::SysPrefs; |
| 27 |
use Koha::Notice::Messages; |
| 26 |
use Koha::Database; |
28 |
use Koha::Database; |
| 27 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
29 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
| 28 |
|
30 |
|
|
Lines 49-55
my $new_suggestion_2 = Koha::Suggestion->new(
Link Here
|
| 49 |
)->store; |
51 |
)->store; |
| 50 |
|
52 |
|
| 51 |
subtest 'store' => sub { |
53 |
subtest 'store' => sub { |
| 52 |
plan tests => 5; |
54 |
plan tests => 8; |
| 53 |
my $suggestion = Koha::Suggestion->new( |
55 |
my $suggestion = Koha::Suggestion->new( |
| 54 |
{ suggestedby => $patron->{borrowernumber}, |
56 |
{ suggestedby => $patron->{borrowernumber}, |
| 55 |
biblionumber => $biblio_1->biblionumber, |
57 |
biblionumber => $biblio_1->biblionumber, |
|
Lines 66-71
subtest 'store' => sub {
Link Here
|
| 66 |
$suggestion = Koha::Suggestions->find( $suggestion->suggestionid ); |
68 |
$suggestion = Koha::Suggestions->find( $suggestion->suggestionid ); |
| 67 |
is( $suggestion->suggesteddate, $two_days_ago_sql, 'If suggestion id modified, suggesteddate should not be modified' ); |
69 |
is( $suggestion->suggesteddate, $two_days_ago_sql, 'If suggestion id modified, suggesteddate should not be modified' ); |
| 68 |
|
70 |
|
|
|
71 |
my $syspref = Koha::Config::SysPrefs->find('EmailPurchaseSuggestions'); |
| 72 |
$syspref->value(0)->store; |
| 73 |
Koha::Notice::Messages->search->delete; |
| 74 |
$suggestion->STATUS('ASKED')->store; |
| 75 |
my $last_message = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->single; |
| 76 |
if ( !defined $last_message ) { |
| 77 |
$last_message = "No message was sent"; |
| 78 |
} |
| 79 |
is( |
| 80 |
$last_message, 'No message was sent', |
| 81 |
'If EmailPurchaseSuggestions is not enabled, a message should not be sent' |
| 82 |
); |
| 83 |
|
| 84 |
$syspref = Koha::Config::SysPrefs->find('EmailPurchaseSuggestions'); |
| 85 |
$syspref->value('EmailAddressForSuggestions')->store; |
| 86 |
Koha::Notice::Messages->search->delete; |
| 87 |
$suggestion->STATUS('ASKED')->store; |
| 88 |
$last_message = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->single; |
| 89 |
if ( !defined $last_message ) { |
| 90 |
fail('No message was sent'); |
| 91 |
} else { |
| 92 |
is( |
| 93 |
$last_message->letter_code, 'NEW_SUGGESTION', |
| 94 |
'If EmailPurchaseSuggestions is enabled and the status of suggestion is set to ASKED, a message should be sent' |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
Koha::Notice::Messages->search->delete; |
| 99 |
$suggestion->STATUS('ACCEPTED')->store; |
| 100 |
$last_message = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->single; |
| 101 |
if ( !defined $last_message ) { |
| 102 |
$last_message = "No message was sent"; |
| 103 |
} |
| 104 |
is( |
| 105 |
$last_message, 'No message was sent', |
| 106 |
'If the status of suggestion is not set to ASKED, a message should not be sent' |
| 107 |
); |
| 108 |
|
| 69 |
throws_ok { |
109 |
throws_ok { |
| 70 |
$suggestion->STATUS('UNKNOWN')->store; |
110 |
$suggestion->STATUS('UNKNOWN')->store; |
| 71 |
} |
111 |
} |
| 72 |
- |
|
|