Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 3; |
|
|
21 |
use Test::MockModule; |
21 |
use Test::Mojo; |
22 |
use Test::Mojo; |
22 |
use Test::Warn; |
23 |
use Test::Warn; |
23 |
|
24 |
|
Lines 153-155
subtest 'delete() tests' => sub {
Link Here
|
153 |
|
154 |
|
154 |
$schema->storage->txn_rollback; |
155 |
$schema->storage->txn_rollback; |
155 |
}; |
156 |
}; |
156 |
- |
157 |
|
|
|
158 |
subtest 'get_public() tests' => sub { |
159 |
|
160 |
plan tests => 25; |
161 |
|
162 |
$schema->storage->txn_begin; |
163 |
|
164 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
165 |
my $patron = $builder->build_object( |
166 |
{ |
167 |
class => 'Koha::Patrons', |
168 |
value => { |
169 |
flags => undef, # opac user |
170 |
categorycode => $category->categorycode |
171 |
} |
172 |
} |
173 |
); |
174 |
my $password = 'thePassword123'; |
175 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
176 |
$patron->discard_changes; |
177 |
my $userid = $patron->userid; |
178 |
|
179 |
my $biblio = $builder->build_sample_biblio({ |
180 |
title => 'The unbearable lightness of being', |
181 |
author => 'Milan Kundera' |
182 |
}); |
183 |
|
184 |
# Make sure author in shown in the OPAC |
185 |
my $subfields = Koha::MarcSubfieldStructures->search({ tagfield => '100' }); |
186 |
while ( my $subfield = $subfields->next ) { |
187 |
$subfield->set({ hidden => -1 })->store; |
188 |
} |
189 |
Koha::Caches->get_instance()->flush_all; |
190 |
|
191 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
192 |
=> { Accept => 'application/weird+format' } ) |
193 |
->status_is(406) |
194 |
->json_is( [ "application/marcxml+xml", |
195 |
"application/marc-in-json", |
196 |
"application/marc", |
197 |
"text/plain" ] ); |
198 |
|
199 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
200 |
=> { Accept => 'text/plain' } ) |
201 |
->status_is(200) |
202 |
->content_like( qr{100\s+_aMilan Kundera} ) |
203 |
->content_like( qr{245\s+_aThe unbearable lightness of being} ); |
204 |
|
205 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
206 |
=> { Accept => 'application/marcxml+xml' } ) |
207 |
->status_is(200); |
208 |
|
209 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
210 |
=> { Accept => 'application/marc-in-json' } ) |
211 |
->status_is(200); |
212 |
|
213 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
214 |
=> { Accept => 'application/marc' } ) |
215 |
->status_is(200); |
216 |
|
217 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
218 |
=> { Accept => 'text/plain' } ) |
219 |
->status_is(200) |
220 |
->content_is($biblio->metadata->record->as_formatted); |
221 |
|
222 |
subtest 'anonymous access' => sub { |
223 |
plan tests => 9; |
224 |
|
225 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber |
226 |
=> { Accept => 'application/marcxml+xml' } ) |
227 |
->status_is(200); |
228 |
|
229 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber |
230 |
=> { Accept => 'application/marc-in-json' } ) |
231 |
->status_is(200); |
232 |
|
233 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber |
234 |
=> { Accept => 'application/marc' } ) |
235 |
->status_is(200); |
236 |
|
237 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber |
238 |
=> { Accept => 'text/plain' } ) |
239 |
->status_is(200) |
240 |
->content_is($biblio->metadata->record->as_formatted); |
241 |
}; |
242 |
|
243 |
# Hide author in OPAC |
244 |
$subfields = Koha::MarcSubfieldStructures->search({ tagfield => '100' }); |
245 |
while ( my $subfield = $subfields->next ) { |
246 |
$subfield->set({ hidden => 1 })->store; |
247 |
} |
248 |
|
249 |
Koha::Caches->get_instance()->flush_all; |
250 |
|
251 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
252 |
=> { Accept => 'text/plain' } ) |
253 |
->status_is(200) |
254 |
->content_unlike( qr{100\s+_aMilan Kundera} ) |
255 |
->content_like( qr{245\s+_aThe unbearable lightness of being} ); |
256 |
|
257 |
subtest 'hidden_in_opac tests' => sub { |
258 |
|
259 |
plan tests => 6; |
260 |
|
261 |
my $biblio_hidden_in_opac = 1; |
262 |
|
263 |
my $biblio_class = Test::MockModule->new('Koha::Biblio'); |
264 |
# force biblio hidden in OPAC |
265 |
$biblio_class->mock( 'hidden_in_opac', sub { return $biblio_hidden_in_opac; } ); |
266 |
|
267 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber |
268 |
=> { Accept => 'text/plain' } ) |
269 |
->status_is(404, 'hidden_in_opac + anonymous => hidden'); |
270 |
|
271 |
my $category_override_hidden_items = 0; |
272 |
my $category_class = Test::MockModule->new('Koha::Patron::Category'); |
273 |
$category_class->mock( 'override_hidden_items', sub { return $category_override_hidden_items; } ); |
274 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
275 |
=> { Accept => 'text/plain' } ) |
276 |
->status_is(404, "hidden_in_opac + patron whose category doesn't override => hidden"); |
277 |
|
278 |
# Make the category override |
279 |
$category_override_hidden_items = 1; |
280 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
281 |
=> { Accept => 'text/plain' } ) |
282 |
->status_is(200, "hidden_in_opac + patron whose category that overrides => displayed"); |
283 |
|
284 |
t::lib::Mocks::mock_preference('OpacHiddenItems'); |
285 |
}; |
286 |
|
287 |
$biblio->delete; |
288 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber |
289 |
=> { Accept => 'application/marc' } ) |
290 |
->status_is(404) |
291 |
->json_is( '/error', 'Object not found.' ); |
292 |
|
293 |
$schema->storage->txn_rollback; |
294 |
}; |