|
Lines 33-39
my $builder = t::lib::TestBuilder->new;
Link Here
|
| 33 |
|
33 |
|
| 34 |
subtest 'Koha::AdditionalContents basic test' => sub { |
34 |
subtest 'Koha::AdditionalContents basic test' => sub { |
| 35 |
|
35 |
|
| 36 |
plan tests => 5; |
36 |
plan tests => 9; |
| 37 |
|
37 |
|
| 38 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
| 39 |
|
39 |
|
|
Lines 45-73
subtest 'Koha::AdditionalContents basic test' => sub {
Link Here
|
| 45 |
code => 'news_1', |
45 |
code => 'news_1', |
| 46 |
location => 'staff_only', |
46 |
location => 'staff_only', |
| 47 |
branchcode => $library->{branchcode}, |
47 |
branchcode => $library->{branchcode}, |
| 48 |
title => 'a news', |
|
|
| 49 |
content => 'content for news 1', |
| 50 |
} |
48 |
} |
| 51 |
)->store; |
49 |
)->store; |
|
|
50 |
my $content_1 = { |
| 51 |
title => 'a news', |
| 52 |
content => 'content for news 1', |
| 53 |
lang => 'default', |
| 54 |
}; |
| 55 |
$new_news_item_1->translated_contents([$content_1]); |
| 52 |
my $new_news_item_2 = Koha::AdditionalContent->new( |
56 |
my $new_news_item_2 = Koha::AdditionalContent->new( |
| 53 |
{ |
57 |
{ |
| 54 |
category => 'news', |
58 |
category => 'news', |
| 55 |
code => 'news_2', |
59 |
code => 'news_2', |
| 56 |
location => 'staff_only', |
60 |
location => 'staff_only', |
| 57 |
branchcode => $library->{branchcode}, |
61 |
branchcode => $library->{branchcode}, |
| 58 |
title => 'another news', |
|
|
| 59 |
content => 'content for news 2', |
| 60 |
} |
62 |
} |
| 61 |
)->store; |
63 |
)->store; |
| 62 |
|
64 |
my $content_2 = { |
| 63 |
like( $new_news_item_1->idnew, qr|^\d+$|, 'Adding a new news_item should have set the idnew'); |
65 |
title => 'another news', |
|
|
66 |
content => 'content for news 2', |
| 67 |
lang => 'default', |
| 68 |
}; |
| 69 |
$new_news_item_2->translated_contents([$content_2]); |
| 70 |
|
| 71 |
like( $new_news_item_1->id, qr|^\d+$|, 'Adding a new news_item should have set the id'); |
| 64 |
is( Koha::AdditionalContents->search->count, $nb_of_news + 2, 'The 2 news should have been added' ); |
72 |
is( Koha::AdditionalContents->search->count, $nb_of_news + 2, 'The 2 news should have been added' ); |
| 65 |
|
73 |
|
| 66 |
my $retrieved_news_item_1 = Koha::AdditionalContents->find( $new_news_item_1->idnew ); |
74 |
my $retrieved_news_item_1 = Koha::AdditionalContents->find( $new_news_item_1->id )->translated_contents->next; |
| 67 |
is( $retrieved_news_item_1->title, $new_news_item_1->title, 'Find a news_item by id should return the correct news_item' ); |
75 |
is( $retrieved_news_item_1->title, $content_1->{title}, 'Find a news_item by id should return the correct news_item' ); |
| 68 |
is( $retrieved_news_item_1->content, $new_news_item_1->content, 'The content method return the content of the news'); |
76 |
is( $retrieved_news_item_1->content, $content_1->{content}, 'The content method return the content of the news'); |
| 69 |
|
77 |
|
| 70 |
$retrieved_news_item_1->delete; |
78 |
my $default_content = $new_news_item_2->default_localization; |
|
|
79 |
is( $default_content->content, $content_2->{content}, 'default_localization return the default content' ); |
| 80 |
my $translated_content = { lang => 'nl-NL', content => 'translated_content' }; |
| 81 |
$new_news_item_2->translated_contents( [ $translated_content, $content_2 ] )->as_list; |
| 82 |
$default_content = $new_news_item_2->default_localization; |
| 83 |
is( $default_content->content, $content_2->{content}, 'default_localization still return the default content' ); |
| 84 |
my $retrieved_translated_content = $new_news_item_2->translated_content('en'); |
| 85 |
is( $retrieved_translated_content->content, $content_2->{content}, 'default content is returned for non-existing translated interface' ); |
| 86 |
$retrieved_translated_content = $new_news_item_2->translated_content('nl-NL'); |
| 87 |
is( $retrieved_translated_content->content, $translated_content->{content}, 'translated content is returned if it existsOB' ); |
| 88 |
|
| 89 |
$new_news_item_1->delete; |
| 71 |
is( Koha::AdditionalContents->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); |
90 |
is( Koha::AdditionalContents->search->count, $nb_of_news + 1, 'Delete should have deleted the news_item' ); |
| 72 |
|
91 |
|
| 73 |
$schema->storage->txn_rollback; |
92 |
$schema->storage->txn_rollback; |
|
Lines 148-154
subtest '->author' => sub {
Link Here
|
| 148 |
|
167 |
|
| 149 |
$author->delete; |
168 |
$author->delete; |
| 150 |
|
169 |
|
| 151 |
$news_item = Koha::AdditionalContents->find($news_item->idnew); |
170 |
$news_item = Koha::AdditionalContents->find($news_item->id); |
| 152 |
is( ref($news_item), 'Koha::AdditionalContent', 'News are not deleted alongwith the author' ); |
171 |
is( ref($news_item), 'Koha::AdditionalContent', 'News are not deleted alongwith the author' ); |
| 153 |
is( $news_item->author, undef, '->author returns undef is the author has been deleted' ); |
172 |
is( $news_item->author, undef, '->author returns undef is the author has been deleted' ); |
| 154 |
|
173 |
|
|
Lines 176-186
subtest '->search_for_display' => sub {
Link Here
|
| 176 |
published_on => $today, |
195 |
published_on => $today, |
| 177 |
category => 'news', |
196 |
category => 'news', |
| 178 |
location => 'staff_and_opac', |
197 |
location => 'staff_and_opac', |
| 179 |
lang => 'default', |
|
|
| 180 |
branchcode => undef, |
198 |
branchcode => undef, |
| 181 |
number => 1, |
199 |
number => 1, |
| 182 |
} |
200 |
} |
| 183 |
}); |
201 |
}); |
|
|
202 |
$new_expired->translated_contents( [ { lang => 'default', content => ''} ] ); |
| 184 |
my $new_not_expired = $builder->build_object({ |
203 |
my $new_not_expired = $builder->build_object({ |
| 185 |
class => 'Koha::AdditionalContents', |
204 |
class => 'Koha::AdditionalContents', |
| 186 |
value => { |
205 |
value => { |
|
Lines 188-198
subtest '->search_for_display' => sub {
Link Here
|
| 188 |
published_on => $today, |
207 |
published_on => $today, |
| 189 |
category => 'news', |
208 |
category => 'news', |
| 190 |
location => 'staff_and_opac', |
209 |
location => 'staff_and_opac', |
| 191 |
lang => 'default', |
|
|
| 192 |
branchcode => undef, |
210 |
branchcode => undef, |
| 193 |
number => 2, |
211 |
number => 2, |
| 194 |
} |
212 |
} |
| 195 |
}); |
213 |
}); |
|
|
214 |
$new_not_expired->translated_contents( [ { lang => 'default', content => '' } ] ); |
| 196 |
my $new_not_active = $builder->build_object({ |
215 |
my $new_not_active = $builder->build_object({ |
| 197 |
class => 'Koha::AdditionalContents', |
216 |
class => 'Koha::AdditionalContents', |
| 198 |
value => { |
217 |
value => { |
|
Lines 200-210
subtest '->search_for_display' => sub {
Link Here
|
| 200 |
published_on => $tomorrow, |
219 |
published_on => $tomorrow, |
| 201 |
category => 'news', |
220 |
category => 'news', |
| 202 |
location => 'staff_and_opac', |
221 |
location => 'staff_and_opac', |
| 203 |
lang => 'default', |
|
|
| 204 |
branchcode => undef, |
222 |
branchcode => undef, |
| 205 |
number => 3, |
223 |
number => 3, |
| 206 |
} |
224 |
} |
| 207 |
}); |
225 |
}); |
|
|
226 |
$new_not_active->translated_contents( [ { lang => 'default', content => '' } ] ); |
| 208 |
my $new_slip= $builder->build_object({ |
227 |
my $new_slip= $builder->build_object({ |
| 209 |
class => 'Koha::AdditionalContents', |
228 |
class => 'Koha::AdditionalContents', |
| 210 |
value => { |
229 |
value => { |
|
Lines 212-222
subtest '->search_for_display' => sub {
Link Here
|
| 212 |
published_on => $today, |
231 |
published_on => $today, |
| 213 |
category => 'news', |
232 |
category => 'news', |
| 214 |
location => 'staff_only', |
233 |
location => 'staff_only', |
| 215 |
lang => 'default', |
|
|
| 216 |
branchcode => $library1->branchcode, |
234 |
branchcode => $library1->branchcode, |
| 217 |
number => 4, |
235 |
number => 4, |
| 218 |
} |
236 |
} |
| 219 |
}); |
237 |
}); |
|
|
238 |
$new_slip->translated_contents( [ { lang => 'default', content => '' } ] ); |
| 220 |
my $new_intra = $builder->build_object({ |
239 |
my $new_intra = $builder->build_object({ |
| 221 |
class => 'Koha::AdditionalContents', |
240 |
class => 'Koha::AdditionalContents', |
| 222 |
value => { |
241 |
value => { |
|
Lines 224-234
subtest '->search_for_display' => sub {
Link Here
|
| 224 |
published_on => $today, |
243 |
published_on => $today, |
| 225 |
category => 'news', |
244 |
category => 'news', |
| 226 |
location => 'staff_only', |
245 |
location => 'staff_only', |
| 227 |
lang => 'default', |
|
|
| 228 |
branchcode => $library2->branchcode, |
246 |
branchcode => $library2->branchcode, |
| 229 |
number => 5, |
247 |
number => 5, |
| 230 |
} |
248 |
} |
| 231 |
}); |
249 |
}); |
|
|
250 |
$new_intra->translated_contents( [ { lang => 'default', content => '' } ] ); |
| 232 |
my $new_intra2 = $builder->build_object({ |
251 |
my $new_intra2 = $builder->build_object({ |
| 233 |
class => 'Koha::AdditionalContents', |
252 |
class => 'Koha::AdditionalContents', |
| 234 |
value => { |
253 |
value => { |
|
Lines 236-246
subtest '->search_for_display' => sub {
Link Here
|
| 236 |
published_on => $today, |
255 |
published_on => $today, |
| 237 |
category => 'news', |
256 |
category => 'news', |
| 238 |
location => 'staff_only', |
257 |
location => 'staff_only', |
| 239 |
lang => 'default', |
|
|
| 240 |
branchcode => undef, |
258 |
branchcode => undef, |
| 241 |
number => 5, |
259 |
number => 5, |
| 242 |
} |
260 |
} |
| 243 |
}); |
261 |
}); |
|
|
262 |
$new_intra2->translated_contents( [ { lang => 'default', content => '' } ] ); |
| 244 |
|
263 |
|
| 245 |
my $news = Koha::AdditionalContents->search_for_display({ location => 'staff_only' }); |
264 |
my $news = Koha::AdditionalContents->search_for_display({ location => 'staff_only' }); |
| 246 |
is($news->count, 1, "There is 1 news for all staff"); |
265 |
is($news->count, 1, "There is 1 news for all staff"); |
|
Lines 267-286
subtest 'find_best_match' => sub {
Link Here
|
| 267 |
my $library01 = $builder->build_object({ class => 'Koha::Libraries' }); |
286 |
my $library01 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 268 |
my $html01 = $builder->build_object({ |
287 |
my $html01 = $builder->build_object({ |
| 269 |
class => 'Koha::AdditionalContents', |
288 |
class => 'Koha::AdditionalContents', |
| 270 |
value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'default' }, |
289 |
value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef }, |
| 271 |
}); |
290 |
}); |
|
|
291 |
my ( $default_content ) = $html01->translated_contents( [ { lang => 'default', content => '' } ] )->as_list; |
| 272 |
my $params = { category => 'html_customizations', location => 'test_best_match', lang => 'nl-NL' }; |
292 |
my $params = { category => 'html_customizations', location => 'test_best_match', lang => 'nl-NL' }; |
| 273 |
is( Koha::AdditionalContents->find_best_match($params)->idnew, $html01->idnew, 'Found all branches, lang default' ); |
293 |
is( Koha::AdditionalContents->find_best_match($params)->id, $default_content->id, 'Found all branches, lang default' ); |
| 274 |
|
294 |
|
| 275 |
my $html02 = $builder->build_object({ |
295 |
my $html02 = $builder->build_object({ |
| 276 |
class => 'Koha::AdditionalContents', |
296 |
class => 'Koha::AdditionalContents', |
| 277 |
value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef, lang => 'nl-NL' }, |
297 |
value => { category => 'html_customizations', location => 'test_best_match', branchcode => undef }, |
| 278 |
}); |
298 |
}); |
| 279 |
is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found all branches, lang nl-NL' ); |
299 |
my ( $translated_content ) = $html02->translated_contents( [ { lang => 'nl-NL', content => '' } ] )->as_list; |
|
|
300 |
is( Koha::AdditionalContents->find_best_match($params)->id, $translated_content->id, 'Found all branches, lang nl-NL' ); |
| 280 |
|
301 |
|
| 281 |
$params->{ library_id } = $library01->id; |
302 |
$params->{ library_id } = $library01->id; |
| 282 |
$html02->branchcode( $library01->id )->store; |
303 |
$html02->branchcode( $library01->id )->store; |
| 283 |
is( Koha::AdditionalContents->find_best_match($params)->idnew, $html02->idnew, 'Found library01, lang nl-NL' ); |
304 |
is( Koha::AdditionalContents->find_best_match($params)->id, $translated_content->id, 'Found library01, lang nl-NL' ); |
| 284 |
|
305 |
|
| 285 |
# Note: find_best_match is tested further via $libary->opac_info; see t/db_dependent/Koha/Library.t |
306 |
# Note: find_best_match is tested further via $libary->opac_info; see t/db_dependent/Koha/Library.t |
| 286 |
|
307 |
|