Bugzilla – Attachment 101057 Details for
Bug 24909
Add unprivileged route to get a bibliographic record
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24909: Unit tests
Bug-24909-Unit-tests.patch (text/plain), 6.13 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-03-19 20:20:01 UTC
(
hide
)
Description:
Bug 24909: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-03-19 20:20:01 UTC
Size:
6.13 KB
patch
obsolete
>From fe043c4e7a10ddd77057ed40c7ecb5752bc85f85 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 19 Mar 2020 17:03:23 -0300 >Subject: [PATCH] Bug 24909: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/api/v1/biblios.t | 141 +++++++++++++++++++++++++++++++- > 1 file changed, 140 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t >index 342b13b75f..66d423d25f 100644 >--- a/t/db_dependent/api/v1/biblios.t >+++ b/t/db_dependent/api/v1/biblios.t >@@ -17,7 +17,8 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; >+use Test::MockModule; > use Test::Mojo; > use Test::Warn; > >@@ -153,3 +154,141 @@ subtest 'delete() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'get_public() tests' => sub { >+ >+ plan tests => 25; >+ >+ $schema->storage->txn_begin; >+ >+ my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { >+ flags => undef, # opac user >+ categorycode => $category->categorycode >+ } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ $patron->discard_changes; >+ my $userid = $patron->userid; >+ >+ my $biblio = $builder->build_sample_biblio({ >+ title => 'The unbearable lightness of being', >+ author => 'Milan Kundera' >+ }); >+ >+ # Make sure author in shown in the OPAC >+ my $subfields = Koha::MarcSubfieldStructures->search({ tagfield => '100' }); >+ while ( my $subfield = $subfields->next ) { >+ $subfield->set({ hidden => -1 })->store; >+ } >+ Koha::Caches->get_instance()->flush_all; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/weird+format' } ) >+ ->status_is(406) >+ ->json_is( [ "application/marcxml+xml", >+ "application/marc-in-json", >+ "application/marc", >+ "text/plain" ] ); >+ >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'text/plain' } ) >+ ->status_is(200) >+ ->content_like( qr{100\s+_aMilan Kundera} ) >+ ->content_like( qr{245\s+_aThe unbearable lightness of being} ); >+ >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/marcxml+xml' } ) >+ ->status_is(200); >+ >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/marc-in-json' } ) >+ ->status_is(200); >+ >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/marc' } ) >+ ->status_is(200); >+ >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'text/plain' } ) >+ ->status_is(200) >+ ->content_is($biblio->metadata->record->as_formatted); >+ >+ subtest 'anonymous access' => sub { >+ plan tests => 9; >+ >+ $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/marcxml+xml' } ) >+ ->status_is(200); >+ >+ $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/marc-in-json' } ) >+ ->status_is(200); >+ >+ $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/marc' } ) >+ ->status_is(200); >+ >+ $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'text/plain' } ) >+ ->status_is(200) >+ ->content_is($biblio->metadata->record->as_formatted); >+ }; >+ >+ # Hide author in OPAC >+ $subfields = Koha::MarcSubfieldStructures->search({ tagfield => '100' }); >+ while ( my $subfield = $subfields->next ) { >+ $subfield->set({ hidden => 1 })->store; >+ } >+ >+ Koha::Caches->get_instance()->flush_all; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'text/plain' } ) >+ ->status_is(200) >+ ->content_unlike( qr{100\s+_aMilan Kundera} ) >+ ->content_like( qr{245\s+_aThe unbearable lightness of being} ); >+ >+ subtest 'hidden_in_opac tests' => sub { >+ >+ plan tests => 6; >+ >+ my $biblio_hidden_in_opac = 1; >+ >+ my $biblio_class = Test::MockModule->new('Koha::Biblio'); >+ # force biblio hidden in OPAC >+ $biblio_class->mock( 'hidden_in_opac', sub { return $biblio_hidden_in_opac; } ); >+ >+ $t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'text/plain' } ) >+ ->status_is(404, 'hidden_in_opac + anonymous => hidden'); >+ >+ my $category_override_hidden_items = 0; >+ my $category_class = Test::MockModule->new('Koha::Patron::Category'); >+ $category_class->mock( 'override_hidden_items', sub { return $category_override_hidden_items; } ); >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'text/plain' } ) >+ ->status_is(404, "hidden_in_opac + patron whose category doesn't override => hidden"); >+ >+ # Make the category override >+ $category_override_hidden_items = 1; >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'text/plain' } ) >+ ->status_is(200, "hidden_in_opac + patron whose category that overrides => displayed"); >+ >+ t::lib::Mocks::mock_preference('OpacHiddenItems'); >+ }; >+ >+ $biblio->delete; >+ $t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber >+ => { Accept => 'application/marc' } ) >+ ->status_is(404) >+ ->json_is( '/error', 'Object not found.' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.25.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24909
:
101057
|
101058
|
101059
|
102163
|
102164
|
102165
|
103672
|
103673
|
103674