@@ -, +, @@
---
.../Koha/GetDailyQuoteForInterface.t | 58 +++++++++++--------
1 file changed, 34 insertions(+), 24 deletions(-)
--- a/t/db_dependent/Koha/GetDailyQuoteForInterface.t
+++ a/t/db_dependent/Koha/GetDailyQuoteForInterface.t
@@ -2,51 +2,61 @@
use Modern::Perl;
use Test::More;
-use Test::More tests => 1;
+use Test::More tests => 3;
use Try::Tiny;
use C4::Koha;
+use Koha::Database;
-my $dbh = C4::Context->dbh;
+use t::lib::TestBuilder;
+use t::lib::Mocks;
-# Start transaction
-$dbh->{RaiseError} = 1;
-# Setup stage
-$dbh->do("DELETE FROM quotes");
-##populate test context
-$dbh->do("INSERT INTO `quotes` VALUES
- (10,'Dusk And Her Embrace','Unfurl thy limbs breathless succubus
How the full embosomed fog
Imparts the night to us....','0000-00-00 00:00:00');
-");
+BEGIN {
+ use_ok('C4::Koha');
+}
+
+can_ok('C4::Koha', qw( GetDailyQuoteForInterface ));
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+
+my $builder = t::lib::TestBuilder->new;
+my $test_quote = $builder->build({
+ source => 'Quote',
+ value => {
+ source => 'Dusk And Her Embrace',
+ text => 'Unfurl thy limbs breathless succubus
How the full embosomed fog
Imparts the night to us....',
+ }
+});
my $expected_quote = {
- id => 10,
source => 'Dusk And Her Embrace',
text => 'Unfurl thy limbs breathless succubus
How the full embosomed fog
Imparts the night to us....',
- timestamp => '0000-00-00 00:00:00',
};
+t::lib::Mocks::mock_preference('QuoteOfTheDay', '');
+
+subtest "GetDailyQuoteForInterface" => sub {
+
+ plan tests => 3;
-subtest "GetDailyQuoteForInterface", \&GetDailyQuoteForInterfaceTest;
-sub GetDailyQuoteForInterfaceTest {
my ($quote);
##Set interface and get nothing because syspref is not set.
C4::Context->interface('opac');
- $quote = C4::Koha::GetDailyQuoteForInterface(id => 10);
+ $quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id});
ok(not($quote), "'QuoteOfTheDay'-syspref not set so nothing returned");
##Set 'QuoteOfTheDay'-syspref to not include current interface 'opac'
- C4::Context->set_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama');
- $quote = C4::Koha::GetDailyQuoteForInterface(id => 10);
+ t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama');
+ $quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id});
ok(not($quote), "'QuoteOfTheDay'-syspref doesn't include 'opac'");
##Set 'QuoteOfTheDay'-syspref to include current interface 'opac'
- C4::Context->set_preference('QuoteOfTheDay', 'intraopaccommandline');
- $quote = C4::Koha::GetDailyQuoteForInterface(id => 10);
- is_deeply($quote, $expected_quote, "Got the expected quote");
+ t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intraopaccommandline');
+ $quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id});
+ is($quote->{text}, $expected_quote->{text}, "Got the expected quote");
-}
+};
-# teardown
-C4::Context->set_preference('QuoteOfTheDay', undef);
-$dbh->do("DELETE FROM quotes");
+$schema->storage->txn_rollback;
--