Lines 50-84
my $expected_quote = {
Link Here
|
50 |
id => $quote_3->id, |
50 |
id => $quote_3->id, |
51 |
source => 'Abraham Lincoln', |
51 |
source => 'Abraham Lincoln', |
52 |
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.', |
52 |
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.', |
53 |
timestamp => dt_from_string, |
53 |
timestamp => $timestamp, |
54 |
}; |
54 |
}; |
55 |
|
55 |
|
56 |
$quote = Koha::Quote->get_daily_quote('id'=>$quote_3->id); |
56 |
$quote = Koha::Quote->get_daily_quote('id'=>$quote_3->id); |
57 |
cmp_ok($quote->{'id'}, '==', $expected_quote->{'id'}, "Correctly got quote by ID"); |
57 |
cmp_ok($quote->id, '==', $expected_quote->{'id'}, "Correctly got quote by ID"); |
58 |
is($quote->{'quote'}, $expected_quote->{'quote'}, "Quote is correct"); |
58 |
is($quote->{'quote'}, $expected_quote->{'quote'}, "Quote is correct"); |
59 |
|
59 |
|
60 |
$quote = Koha::Quote->get_daily_quote('random'=>1); |
60 |
$quote = Koha::Quote->get_daily_quote('random'=>1); |
61 |
ok($quote, "Got a random quote."); |
61 |
ok($quote, "Got a random quote."); |
62 |
cmp_ok($quote->{'id'}, '>', 0, 'Id is greater than 0'); |
62 |
cmp_ok($quote->id, '>', 0, 'Id is greater than 0'); |
63 |
|
63 |
|
64 |
$timestamp = DateTime::Format::MySQL->format_datetime(dt_from_string->add( seconds => 1 )); # To make it the last one |
64 |
$timestamp = DateTime::Format::MySQL->format_datetime(dt_from_string->add( seconds => 1 )); # To make it the last one |
65 |
Koha::Quotes->search({ id => $expected_quote->{'id'} })->update({ timestamp => $timestamp }); |
65 |
Koha::Quotes->search({ id => $expected_quote->{'id'} })->update({ timestamp => $timestamp }); |
66 |
$expected_quote->{'timestamp'} = $timestamp; |
66 |
$expected_quote->{'timestamp'} = $timestamp; |
67 |
|
67 |
|
68 |
$quote = Koha::Quote->get_daily_quote(); # this is the "default" mode of selection |
68 |
$quote = Koha::Quote->get_daily_quote()->unblessed; # this is the "default" mode of selection |
69 |
cmp_ok($quote->{'id'}, '==', $expected_quote->{'id'}, "Id is correct"); |
69 |
cmp_ok($quote->{'id'}, '==', $expected_quote->{'id'}, "Id is correct"); |
70 |
is($quote->{'source'}, $expected_quote->{'source'}, "Source is correct"); |
70 |
is($quote->{'source'}, $expected_quote->{'source'}, "Source is correct"); |
71 |
is($quote->{'timestamp'}, $expected_quote->{'timestamp'}, "Timestamp $timestamp is correct"); |
71 |
is($quote->{'timestamp'}, $expected_quote->{'timestamp'}, "Timestamp $timestamp is correct"); |
72 |
|
72 |
|
73 |
$dbh->do(q|DELETE FROM quotes|); |
73 |
Koha::Quotes->search()->delete(); |
74 |
$quote = eval {Koha::Quote->get_daily_quote();}; |
74 |
$quote = eval {Koha::Quote->get_daily_quote();}; |
75 |
is( $@, '', 'get_daily_quote does not die if no quote exist' ); |
75 |
is( $@, '', 'get_daily_quote does not die if no quote exist' ); |
76 |
is_deeply( $quote, {}, 'get_daily_quote return an empty hashref is no quote exist'); # Is it what we expect? |
76 |
is_deeply( $quote, undef, 'return undef if quotes do not exists'); # Is it what we expect? |
77 |
|
77 |
|
78 |
my $quote_6 = Koha::Quote->new({ source => 'George Washington', text => 'To be prepared for war is one of the most effectual means of preserving peace.', timestamp => dt_from_string() })->store; |
78 |
my $quote_6 = Koha::Quote->new({ source => 'George Washington', text => 'To be prepared for war is one of the most effectual means of preserving peace.', timestamp => dt_from_string() })->store; |
79 |
|
79 |
|
80 |
$quote = Koha::Quote->get_daily_quote(); |
80 |
$quote = Koha::Quote->get_daily_quote(); |
81 |
is( $quote->{id}, $quote_6->id, ' get_daily_quote returns the only existing quote' ); |
81 |
is( $quote->id, $quote_6->id, ' get_daily_quote returns the only existing quote' ); |
82 |
|
82 |
|
83 |
$schema->storage->txn_rollback; |
83 |
$schema->storage->txn_rollback; |
84 |
|
84 |
|
Lines 112-118
subtest "get_daily_quote_for_interface" => sub {
Link Here
|
112 |
|
112 |
|
113 |
##Set 'QuoteOfTheDay'-syspref to include current interface 'opac' |
113 |
##Set 'QuoteOfTheDay'-syspref to include current interface 'opac' |
114 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 'opac,intranet'); |
114 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 'opac,intranet'); |
115 |
$quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id); |
115 |
$quote = Koha::Quote->get_daily_quote_for_interface(id => $quote_1->id)->unblessed; |
116 |
is_deeply($quote, $expected_quote, "Got the expected quote"); |
116 |
is_deeply($quote, $expected_quote, "Got the expected quote"); |
117 |
|
117 |
|
118 |
$schema->storage->txn_rollback; |
118 |
$schema->storage->txn_rollback; |
119 |
- |
|
|