Lines 2-52
Link Here
|
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More; |
4 |
use Test::More; |
5 |
use Test::More tests => 1; |
5 |
use Test::More tests => 3; |
6 |
use Try::Tiny; |
6 |
use Try::Tiny; |
7 |
|
7 |
|
8 |
use C4::Koha; |
8 |
use C4::Koha; |
|
|
9 |
use Koha::Database; |
9 |
|
10 |
|
10 |
my $dbh = C4::Context->dbh; |
11 |
use t::lib::TestBuilder; |
|
|
12 |
use t::lib::Mocks; |
11 |
|
13 |
|
12 |
# Start transaction |
14 |
BEGIN { |
13 |
$dbh->{RaiseError} = 1; |
15 |
use_ok('C4::Koha'); |
14 |
# Setup stage |
16 |
} |
15 |
$dbh->do("DELETE FROM quotes"); |
17 |
|
16 |
##populate test context |
18 |
can_ok('C4::Koha', qw( GetDailyQuoteForInterface )); |
17 |
$dbh->do("INSERT INTO `quotes` VALUES |
19 |
|
18 |
(10,'Dusk And Her Embrace','Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....','0000-00-00 00:00:00'); |
20 |
my $schema = Koha::Database->new->schema; |
19 |
"); |
21 |
$schema->storage->txn_begin; |
|
|
22 |
|
23 |
my $builder = t::lib::TestBuilder->new; |
24 |
my $test_quote = $builder->build({ |
25 |
source => 'Quote', |
26 |
value => { |
27 |
source => 'Dusk And Her Embrace', |
28 |
text => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....', |
29 |
} |
30 |
}); |
20 |
|
31 |
|
21 |
my $expected_quote = { |
32 |
my $expected_quote = { |
22 |
id => 10, |
|
|
23 |
source => 'Dusk And Her Embrace', |
33 |
source => 'Dusk And Her Embrace', |
24 |
text => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....', |
34 |
text => 'Unfurl thy limbs breathless succubus<br/>How the full embosomed fog<br/>Imparts the night to us....', |
25 |
timestamp => '0000-00-00 00:00:00', |
|
|
26 |
}; |
35 |
}; |
27 |
|
36 |
|
|
|
37 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', ''); |
38 |
|
39 |
subtest "GetDailyQuoteForInterface" => sub { |
40 |
|
41 |
plan tests => 3; |
28 |
|
42 |
|
29 |
subtest "GetDailyQuoteForInterface", \&GetDailyQuoteForInterfaceTest; |
|
|
30 |
sub GetDailyQuoteForInterfaceTest { |
31 |
my ($quote); |
43 |
my ($quote); |
32 |
|
44 |
|
33 |
##Set interface and get nothing because syspref is not set. |
45 |
##Set interface and get nothing because syspref is not set. |
34 |
C4::Context->interface('opac'); |
46 |
C4::Context->interface('opac'); |
35 |
$quote = C4::Koha::GetDailyQuoteForInterface(id => 10); |
47 |
$quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id}); |
36 |
ok(not($quote), "'QuoteOfTheDay'-syspref not set so nothing returned"); |
48 |
ok(not($quote), "'QuoteOfTheDay'-syspref not set so nothing returned"); |
37 |
|
49 |
|
38 |
##Set 'QuoteOfTheDay'-syspref to not include current interface 'opac' |
50 |
##Set 'QuoteOfTheDay'-syspref to not include current interface 'opac' |
39 |
C4::Context->set_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama'); |
51 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intra commandline sip2 api yo-mama'); |
40 |
$quote = C4::Koha::GetDailyQuoteForInterface(id => 10); |
52 |
$quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id}); |
41 |
ok(not($quote), "'QuoteOfTheDay'-syspref doesn't include 'opac'"); |
53 |
ok(not($quote), "'QuoteOfTheDay'-syspref doesn't include 'opac'"); |
42 |
|
54 |
|
43 |
##Set 'QuoteOfTheDay'-syspref to include current interface 'opac' |
55 |
##Set 'QuoteOfTheDay'-syspref to include current interface 'opac' |
44 |
C4::Context->set_preference('QuoteOfTheDay', 'intraopaccommandline'); |
56 |
t::lib::Mocks::mock_preference('QuoteOfTheDay', 'intraopaccommandline'); |
45 |
$quote = C4::Koha::GetDailyQuoteForInterface(id => 10); |
57 |
$quote = C4::Koha::GetDailyQuoteForInterface(id => $test_quote->{id}); |
46 |
is_deeply($quote, $expected_quote, "Got the expected quote"); |
58 |
is($quote->{text}, $expected_quote->{text}, "Got the expected quote"); |
47 |
|
59 |
|
48 |
} |
60 |
}; |
49 |
|
61 |
|
50 |
# teardown |
62 |
$schema->storage->txn_rollback; |
51 |
C4::Context->set_preference('QuoteOfTheDay', undef); |
|
|
52 |
$dbh->do("DELETE FROM quotes"); |
53 |
- |
|
|