|
Lines 16-22
Link Here
|
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
use Test::More tests => 15; |
19 |
use Test::More tests => 14; |
| 20 |
|
20 |
|
| 21 |
use Koha::Database; |
21 |
use Koha::Database; |
| 22 |
use Koha::DateUtils qw(dt_from_string); |
22 |
use Koha::DateUtils qw(dt_from_string); |
|
Lines 24-29
use Koha::Quote;
Link Here
|
| 24 |
use Koha::Quotes; |
24 |
use Koha::Quotes; |
| 25 |
|
25 |
|
| 26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
|
|
27 |
use t::lib::Dates; |
| 27 |
use t::lib::Mocks; |
28 |
use t::lib::Mocks; |
| 28 |
|
29 |
|
| 29 |
BEGIN { |
30 |
BEGIN { |
|
Lines 39-58
$schema->storage->txn_begin;
Link Here
|
| 39 |
my $dbh = C4::Context->dbh; |
40 |
my $dbh = C4::Context->dbh; |
| 40 |
|
41 |
|
| 41 |
# Ids not starting with 1 to reflect possible deletes, this acts as a regression test for bug 11297 |
42 |
# Ids not starting with 1 to reflect possible deletes, this acts as a regression test for bug 11297 |
| 42 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
43 |
my $yesterday = dt_from_string()->subtract(days => 1); |
| 43 |
my $timestamp = $dtf->format_datetime(dt_from_string()); |
44 |
my $quote_1 = Koha::Quote->new({ source => 'George Washington', text => 'To be prepared for war is one of the most effectual means of preserving peace.' })->store; |
| 44 |
my $quote_1 = Koha::Quote->new({ source => 'George Washington', text => 'To be prepared for war is one of the most effectual means of preserving peace.', timestamp => $timestamp })->store; |
45 |
my $quote_2 = Koha::Quote->new({ source => 'Thomas Jefferson', text => 'When angry, count ten, before you speak; if very angry, an hundred.' })->store; |
| 45 |
my $quote_2 = Koha::Quote->new({ source => 'Thomas Jefferson', text => 'When angry, count ten, before you speak; if very angry, an hundred.', timestamp => $timestamp })->store; |
46 |
my $quote_3 = Koha::Quote->new({ source => 'Abraham Lincoln', text => 'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal' })->store; |
| 46 |
my $quote_3 = Koha::Quote->new({ source => 'Abraham Lincoln', text => 'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal', timestamp => $timestamp })->store; |
47 |
my $quote_4 = Koha::Quote->new({ source => 'Abraham Lincoln', text => 'I have always found that mercy bears richer fruits than strict justice.' })->store; |
| 47 |
my $quote_4 = Koha::Quote->new({ source => 'Abraham Lincoln', text => 'I have always found that mercy bears richer fruits than strict justice.', timestamp => $timestamp })->store; |
48 |
my $quote_5 = Koha::Quote->new({ source => 'Andrew Johnson', text => 'I feel incompetent to perform duties...which have been so unexpectedly thrown upon me.' })->store; |
| 48 |
my $quote_5 = Koha::Quote->new({ source => 'Andrew Johnson', text => 'I feel incompetent to perform duties...which have been so unexpectedly thrown upon me.', timestamp => $timestamp })->store; |
|
|
| 49 |
|
| 50 |
my $expected_quote = { |
| 51 |
id => $quote_3->id, |
| 52 |
source => 'Abraham Lincoln', |
| 53 |
text => 'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.', |
| 54 |
timestamp => $timestamp, |
| 55 |
}; |
| 56 |
|
49 |
|
| 57 |
#First test with QuoteOfTheDay disabled |
50 |
#First test with QuoteOfTheDay disabled |
| 58 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 0); |
51 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 0); |
|
Lines 71-91
ok(not($quote), "'QuoteOfTheDay'-syspref doesn't include 'opac'");
Link Here
|
| 71 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 'opac,intranet'); |
64 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 'opac,intranet'); |
| 72 |
|
65 |
|
| 73 |
$quote = Koha::Quotes->get_daily_quote('id'=>$quote_3->id); |
66 |
$quote = Koha::Quotes->get_daily_quote('id'=>$quote_3->id); |
| 74 |
cmp_ok($quote->id, '==', $expected_quote->{'id'}, "Correctly got quote by ID"); |
67 |
is($quote->id, $quote_3->id, "Correctly got quote by ID"); |
| 75 |
is($quote->{'quote'}, $expected_quote->{'quote'}, "Quote is correct"); |
68 |
is($quote->text, $quote_3->text, "Quote is correct"); |
|
|
69 |
is(t::lib::Dates::compare($quote->timestamp, dt_from_string), 0, "get_daily_quote updated the timestamp/last seen"); |
| 76 |
|
70 |
|
| 77 |
$quote = Koha::Quotes->get_daily_quote('random'=>1); |
71 |
$quote = Koha::Quotes->get_daily_quote('random'=>1); |
| 78 |
ok($quote, "Got a random quote."); |
72 |
ok($quote, "Got a random quote."); |
| 79 |
cmp_ok($quote->id, '>', 0, 'Id is greater than 0'); |
73 |
cmp_ok($quote->id, '>', 0, 'Id is greater than 0'); |
| 80 |
|
74 |
|
| 81 |
$timestamp = $dtf->format_datetime(dt_from_string->add( seconds => 1 )); # To make it the last one |
75 |
subtest 'timestamp column is updated' => sub { |
| 82 |
Koha::Quotes->search({ id => $expected_quote->{'id'} })->update({ timestamp => $timestamp }); |
76 |
plan tests => 3; |
| 83 |
$expected_quote->{'timestamp'} = $timestamp; |
77 |
|
|
|
78 |
Koha::Quotes->search->update( { timestamp => $yesterday } ); |
| 79 |
|
| 80 |
my $now = dt_from_string; |
| 84 |
|
81 |
|
| 85 |
$quote = Koha::Quotes->get_daily_quote()->unblessed; # this is the "default" mode of selection |
82 |
my $expected_quote = { |
| 86 |
cmp_ok($quote->{'id'}, '==', $expected_quote->{'id'}, "Id is correct"); |
83 |
id => $quote_3->id, |
| 87 |
is($quote->{'source'}, $expected_quote->{'source'}, "Source is correct"); |
84 |
source => 'Abraham Lincoln', |
| 88 |
is($quote->{'timestamp'}, $expected_quote->{'timestamp'}, "Timestamp $timestamp is correct"); |
85 |
text => 'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.', |
|
|
86 |
timestamp => $yesterday, |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
Koha::Quotes->find( $expected_quote->{'id'} ) |
| 91 |
->update( { timestamp => $now->clone->subtract( seconds => 10 ) } ); ; # To make it the last one |
| 92 |
$quote = Koha::Quotes->get_daily_quote(); # this is the "default" mode of selection |
| 93 |
is($quote->id, $expected_quote->{'id'}, "Id is correct"); |
| 94 |
is($quote->source, $expected_quote->{'source'}, "Source is correct"); |
| 95 |
is(t::lib::Dates::compare($quote->timestamp, $now), 0, "get_daily_quote updated the timestamp/last seen"); |
| 96 |
}; |
| 89 |
|
97 |
|
| 90 |
Koha::Quotes->search()->delete(); |
98 |
Koha::Quotes->search()->delete(); |
| 91 |
$quote = eval {Koha::Quotes->get_daily_quote();}; |
99 |
$quote = eval {Koha::Quotes->get_daily_quote();}; |
| 92 |
- |
|
|