View | Details | Raw Unified | Return to bug 29691
Collapse All | Expand All

(-)a/t/db_dependent/Template/Plugin/AdditionalContents.t (-1 / +90 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::More tests => 2;
20
21
use C4::Context;
22
use Koha::Caches;
23
use Koha::Database;
24
use Koha::MarcSubfieldStructures;
25
use Koha::Template::Plugin::AdditionalContents;
26
27
use t::lib::TestBuilder;
28
use t::lib::Mocks;
29
30
my $schema = Koha::Database->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
$schema->storage->txn_begin;
34
35
subtest 'get' => sub {
36
    plan tests => 2;
37
38
    my $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default', library => '%' });
39
    my $before_count = $additional_contents ? $additional_contents->{content}->count() : 0;
40
    $builder->build_object({
41
        class => 'Koha::AdditionalContents',
42
        value => {
43
            category   => 'news',
44
            location   => 'opac_only',
45
            lang       => 'default',
46
            branchcode => undef
47
        }
48
    });
49
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default' });
50
    is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added");
51
52
    $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default', blocktitle => 'blockhead' });
53
54
    is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through");
55
56
57
};
58
59
subtest 'get_opac_news_by_id' => sub {
60
61
    plan tests => 4;
62
63
    my $news_item = $builder->build_object({
64
        class => 'Koha::AdditionalContents',
65
        value => {
66
            category => 'news',
67
            location => 'opac_only'
68
        }
69
    });
70
71
   my $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
72
   is( $fetched_news->{content}->next->content, $news_item->content, "Correct news fetched for opac location" );
73
74
   $news_item->location('staff_and_opac')->store();
75
   $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
76
   is( $fetched_news->{content}->next->content, $news_item->content, "Correct news fetched for oac and staff location" );
77
78
   $news_item->location('staff_only')->store();
79
   $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
80
   is( $fetched_news, 0, "News item not fetched when location is staff_only" );
81
82
   $news_item->location('opac_only')->category('HtmlCustomizations')->store();
83
   $fetched_news = Koha::Template::Plugin::AdditionalContents->get_opac_news_by_id({ news_id => $news_item->id });
84
   is( $fetched_news, 0, "News not fetched from a different category" );
85
86
87
88
};
89
90
$schema->storage->txn_rollback;

Return to bug 29691