|
Lines 16-22
Link Here
|
| 16 |
|
16 |
|
| 17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
| 18 |
|
18 |
|
| 19 |
use Test::More tests => 2; |
19 |
use Test::More tests => 1; |
| 20 |
|
20 |
|
| 21 |
use C4::Context; |
21 |
use C4::Context; |
| 22 |
use Koha::Caches; |
22 |
use Koha::Caches; |
|
Lines 37-51
subtest 'get' => sub {
Link Here
|
| 37 |
|
37 |
|
| 38 |
my $additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default', library => '%' }); |
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; |
39 |
my $before_count = $additional_contents ? $additional_contents->{content}->count() : 0; |
| 40 |
$builder->build_object({ |
40 |
my $additional_content = $builder->build_object({ |
| 41 |
class => 'Koha::AdditionalContents', |
41 |
class => 'Koha::AdditionalContents', |
| 42 |
value => { |
42 |
value => { |
| 43 |
category => 'news', |
43 |
category => 'news', |
| 44 |
location => 'opac_only', |
44 |
location => 'opac_only', |
| 45 |
lang => 'default', |
|
|
| 46 |
branchcode => undef |
45 |
branchcode => undef |
| 47 |
} |
46 |
} |
| 48 |
}); |
47 |
}); |
|
|
48 |
$builder->build_object( |
| 49 |
{ |
| 50 |
class => 'Koha::AdditionalContentsLocalizations', |
| 51 |
value => { |
| 52 |
additional_content_id => $additional_content->id, |
| 53 |
lang => 'default', |
| 54 |
} |
| 55 |
} |
| 56 |
); |
| 49 |
$additional_contents = Koha::Template::Plugin::AdditionalContents->get({ category => 'news', location => ['opac_only', 'staff_and_opac'], lang => 'default' }); |
57 |
$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"); |
58 |
is( $additional_contents->{content}->count, $before_count + 1, "We get the additional one we added"); |
| 51 |
|
59 |
|
|
Lines 54-90
subtest 'get' => sub {
Link Here
|
| 54 |
is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through"); |
62 |
is( $additional_contents->{blocktitle}, 'blockhead', "Block title is passed through"); |
| 55 |
|
63 |
|
| 56 |
|
64 |
|
| 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 |
}; |
65 |
}; |
| 89 |
|
66 |
|
| 90 |
$schema->storage->txn_rollback; |
67 |
$schema->storage->txn_rollback; |
| 91 |
- |
|
|