From ca9c35900a8361c4375f2d8a8867e4b06478607d Mon Sep 17 00:00:00 2001 From: Srdjan Date: Fri, 23 Sep 2016 18:08:30 +1200 Subject: [PATCH] Bug 17602 : Add OneClickDigital Integration to Koha Koha::ExternalContent::OneClickDigital - a wrapper around WebService::ILS::OneClickDigital::PartnerPatron Nothing functional to test with this patch yet. But you can run the tests that come with it t/db_dependent/Koha_ExternalContent_OneClickDigital.t --- C4/Installer/PerlDependencies.pm | 2 +- Koha/ExternalContent/OneClickDigital.pm | 90 ++++++++++++++++++++++ .../Koha_ExternalContent_OneClickDigital.t | 57 ++++++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 Koha/ExternalContent/OneClickDigital.pm create mode 100755 t/db_dependent/Koha_ExternalContent_OneClickDigital.t diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index c411e91..bb533ef 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -860,7 +860,7 @@ our $PERL_DEPS = { 'WebService::ILS' => { 'usage' => 'Interface third party systems', 'required' => '0', - 'min_ver' => '0.07', + 'min_ver' => '0.08', }, }; diff --git a/Koha/ExternalContent/OneClickDigital.pm b/Koha/ExternalContent/OneClickDigital.pm new file mode 100644 index 0000000..541d131 --- /dev/null +++ b/Koha/ExternalContent/OneClickDigital.pm @@ -0,0 +1,90 @@ +# Copyright 2016 Catalyst +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +package Koha::ExternalContent::OneClickDigital; + +use Modern::Perl; +use Carp; + +use base qw(Koha::ExternalContent); +use WebService::ILS::OneClickDigital::PartnerPatron; +use C4::Context; +use Koha::Logger; + +use constant logger => Koha::Logger->get(); + +=head1 NAME + +Koha::ExternalContent::OneClickDigital + +=head1 SYNOPSIS + + use Koha::ExternalContent::OneClickDigital; + my $od_client = Koha::ExternalContent::OneClickDigital->new(); + my $od_auth_url = $od_client->auth_url(); + +=head1 DESCRIPTION + +A (very) thin wrapper around C + +Takes "OneClickDigital*" Koha preferences + +=cut + +sub new { + my $class = shift; + my $params = shift || {}; + $params->{koha_session_id} or croak "No koha_session_id"; + + my $self = $class->SUPER::new($params); + unless ($params->{client}) { + my $client_secret = C4::Context->preference('OneClickDigitalClientSecret') + or croak("OneClickDigitalClientSecret pref not set"); + my $library_id = C4::Context->preference('OneClickDigitalLibraryID') + or croak("OneClickDigitalLibraryID pref not set"); + my $patron = $self->koha_patron; + $self->client( WebService::ILS::OneClickDigital::PartnerPatron->new( + client_secret => $client_secret, + library_id => $library_id, + user_id => $patron->email, + user_agent_params => { agent => $class->agent_string } + ) ); + } + return $self; +} + +=head1 METHODS + +L methods used without mods: + +=over 4 + +=item C + +=back + +=cut + +use vars qw{$AUTOLOAD}; +sub AUTOLOAD { + my $self = shift; + (my $method = $AUTOLOAD) =~ s/.*:://; + return $self->client->$method(@_); +} +sub DESTROY { } + +1; diff --git a/t/db_dependent/Koha_ExternalContent_OneClickDigital.t b/t/db_dependent/Koha_ExternalContent_OneClickDigital.t new file mode 100755 index 0000000..9b7e4c8 --- /dev/null +++ b/t/db_dependent/Koha_ExternalContent_OneClickDigital.t @@ -0,0 +1,57 @@ +use Modern::Perl; + +use t::lib::Mocks; +use t::lib::TestBuilder; +use Test::More tests => 3; # last test to print +use C4::Context; +use C4::Auth; +use Koha::Patron::Categories; + +my $dbh = C4::Context->dbh; +# Start transaction +$dbh->{AutoCommit} = 0; +$dbh->begin_work; +die; + +local $@; +eval { require WebService::ILS::OneClickDigital::PartnerPatron; } + or diag($@); +SKIP: { + skip "cannot filnd WebService::ILS::OneClickDigital::PartnerPatron", 3 if $@; + + use_ok('Koha::ExternalContent::OneClickDigital'); + + my $ocd_user_email = $ENV{ONECLICKDIGITAL_TEST_USER_EMAIL}; + SKIP: { + skip "Env ONECLICKDIGITAL_TEST_USER_EMAIL not set", 2 unless $ocd_user_email; + + my $ocd_secret = $ENV{ONECLICKDIGITAL_TEST_CLIENT_SECRET} + || C4::Context->preference('OneClickDigitalClientSecret'); + my $ocd_library_id = $ENV{ONECLICKDIGITAL_TEST_LIBRARY_ID} + || C4::Context->preference('OneClickDigitalLibraryID'); + skip "Env ONECLICKDIGITAL_TEST_CLIENT_SECRET ONECLICKDIGITAL_TEST_LIBRARY_ID not set", 2 unless $ocd_secret && $ocd_library_id; + + my $builder = t::lib::TestBuilder->new(); + + t::lib::Mocks::mock_preference('OneClickDigitalClientSecret', $ocd_secret); + t::lib::Mocks::mock_preference('OneClickDigitalLibraryID', $ocd_library_id); + + my $patron = $builder->build({ + source => 'Borrower', + value => { + email => $ocd_user_email, + } + }); + + my $session = C4::Auth::get_session(""); + $session->param('number', $patron->{borrowernumber}); + $session->flush; + my $client = Koha::ExternalContent::OneClickDigital->new({koha_session_id => $session->id}); + + my $user_agent_string = $client->user_agent->agent(); + ok ($user_agent_string =~ m/^Koha/, 'User Agent string is set') + or diag("User Agent string: $user_agent_string"); + + ok ($client->search({query => "school"}), 'search()'); + } +} -- 2.10.2