From cc422fe92285ce7b0fad3957c4234489872ff312 Mon Sep 17 00:00:00 2001 From: Martin Persson Date: Thu, 3 Dec 2015 16:20:59 +0100 Subject: [PATCH] Bug 15292 - Libris ILS-DI item status (tests) This patch adds the GetLibrisAvailability tests. Sponsored-By: Halland County Library --- t/db_dependent/ILSDI_Services.t | 97 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 9aee73e..2bbda77 100644 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -5,8 +5,11 @@ use Modern::Perl; use C4::Members qw/AddMember GetMember GetBorrowercategory/; use C4::Branch; use CGI qw ( -utf8 ); +use t::lib::TestBuilder; +use t::lib::Mocks; +use XML::LibXML; -use Test::More tests => 15; +use Test::More tests => 18; BEGIN { use_ok('C4::ILSDI::Services'); @@ -90,3 +93,95 @@ my $borrower = GetMember( borrowernumber => $borrowernumber ); } +# End transaction +$dbh->rollback; +$dbh->{AutoCommit} = 1; +$dbh->{RaiseError} = 0; + +my $schema = Koha::Database->schema; +$schema->storage->txn_begin; + +$schema->resultset( 'Borrower' )->delete_all; +$schema->resultset( 'BorrowerAttribute' )->delete_all; +$schema->resultset( 'BorrowerAttributeType' )->delete_all; +$schema->resultset( 'Category' )->delete_all; +$schema->resultset( 'Biblio' )->delete_all; +$schema->resultset( 'Biblioitem' )->delete_all; +$schema->resultset( 'Item' )->delete_all; # 'Branch' dep. +$schema->resultset( 'Branch' )->delete_all; + +{ # GetLibrisAvailability: LIBRIS (Swedish national catalogue) status + + # Configure Koha to enable ILS-DI server and extended attributes: + t::lib::Mocks::mock_preference( 'ILS-DI', 1 ); + + my $builder = t::lib::TestBuilder->new; + + # LIBRIS stores it's own unique ID in Control Field 001 in their + # catalogue's MARC records. Luckily Koha indexes this field. + # Swedish libraries imports the LIBRIS records, the central + # catalogue then queries item status remotely by this ID. + my $libris_id = '001337'; + + # Set up a library/branch for our user to belong to: + my $lib = $builder->build( { + source => 'Branch', + value => { + branchcode => 'T_ILSDI', + } + } ); + + # Create entries for the book we want to test: + my $bib = $builder->build( { + source => 'Biblio', + values => { + } + }); + + my $bibitem = $builder->build( { + source => 'Biblioitem', + value => { + bbiblionumber => $bib->{'biblionumber'}, + } + }); + + my $item = $builder->build( { + source => 'Item', + value => { + biblioitemnumber => $bibitem->{'biblioitemnumber'}, + homebranch => $lib->{'branchcode'}, + holdingbranch => $lib->{'branchcode'}, + } + }); + + # Set up test request: + my $query = new CGI; my $reply; + $query->param( 'service', 'GetLibrisAvailability' ); + + my $parser = XML::LibXML->new; + + # Error handling tests, missing parameters, biblios and/or items. + $query->param( 'id', undef ); + $reply = C4::ILSDI::Services::GetLibrisAvailability( $query ); + $reply = $parser->parse_string( + C4::ILSDI::Services::GetLibrisAvailability( $query )) + ->findnodes('/Error')->[0]->textContent(); + like( $reply, qr/missing parameter/i, 'Test missing id paramter' ); + + $query->param( 'id', 'non-existant-id-string' ); + $reply = $parser->parse_string( + C4::ILSDI::Services::GetLibrisAvailability( $query )) + ->findnodes('/Error')->[0]->textContent(); + like( $reply, qr/no search result/i, 'Test missing search result' ); + + # Expects to find $libris_id in Zebra but missing the + # item info from the Koha SQL database. + $query->param( 'id', $libris_id ); + $reply = $parser->parse_string( + C4::ILSDI::Services::GetLibrisAvailability( $query )) + ->findnodes('/Error')->[0]->textContent(); + like( $reply, qr/no item information/i, 'Test missing item info' ); +} + +# Cleanup +$schema->storage->txn_rollback; -- 2.1.4