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

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

Return to bug 24909