From d31377ae5c89a9312643bbb9ff6d25d5d726a056 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Thu, 23 Aug 2018 07:47:47 +0000 Subject: [PATCH] Bug 17047: Fix unit tests Replace MANA_IP variable with subroutine Fix QA script warnings --- C4/Serials.pm | 1 + Koha/SharedContent.pm | 19 +++++++++++++------ .../prog/en/modules/admin/preferences.tt | 2 +- t/db_dependent/Koha/SharedContent.t | 7 +++++-- t/db_dependent/Koha/Subscription.t | 6 ++---- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 3915e3c..6bbfda9 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -35,6 +35,7 @@ use Koha::DateUtils; use Koha::Serial; use Koha::Subscriptions; use Koha::Subscription::Histories; +use Koha::SharedContent; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm index a6b8584..1e98add 100644 --- a/Koha/SharedContent.pm +++ b/Koha/SharedContent.pm @@ -26,8 +26,6 @@ use Koha::Serials; use Koha::Reports; use C4::Context; -our $MANA_IP = C4::Context->config('mana_config'); - =head1 DESCRIPTION Package for accessing shared content via Mana @@ -151,13 +149,14 @@ sub manaGetRequest { sub buildRequest { my $type = shift; my $resource = shift; + my $mana_url = manaUrl(); if ( $type eq 'get' ) { my $params = shift; $params = join '&', map { defined $params->{$_} ? $_ . "=" . $params->{$_} : () } keys %$params; - my $url = "$MANA_IP/$resource.json?$params"; + my $url = "$mana_url/$resource.json?$params"; return HTTP::Request->new( GET => $url ); } @@ -168,14 +167,14 @@ sub buildRequest { map { defined $params->{$_} ? $_ . "=" . $params->{$_} : () } keys %$params; - my $url = "$MANA_IP/$resource/$id.json?$params"; + my $url = "$mana_url/$resource/$id.json?$params"; return HTTP::Request->new( GET => $url ); } if ( $type eq 'post' ) { my $content = shift; - my $url = "$MANA_IP/$resource.json"; + my $url = "$mana_url/$resource.json"; my $request = HTTP::Request->new( POST => $url ); my $json = to_json( $content, { utf8 => 1 } ); @@ -196,10 +195,18 @@ sub buildRequest { $param = join '&', map { defined $param->{$_} ? $_ . "=" . $param->{$_} : () } keys %$param; - my $url = "$MANA_IP/$resource/$id.json/increment/$field?$param"; + my $url = "$mana_url/$resource/$id.json/increment/$field?$param"; my $request = HTTP::Request->new( POST => $url ); } } +=head3 manaUrl + +=cut + +sub manaUrl { + return C4::Context->config('mana_config'); +} + 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt index ba6a2d5..c4a9f4c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt @@ -194,7 +194,7 @@ - + [% Asset.js("lib/jquery/activatemana.js") | $raw %] [%# Add WYSIWYG editor for htmlarea system preferences %] [% INCLUDE 'wysiwyg-systempreferences.inc' %] [% END %] diff --git a/t/db_dependent/Koha/SharedContent.t b/t/db_dependent/Koha/SharedContent.t index 3925b30..5e41814 100644 --- a/t/db_dependent/Koha/SharedContent.t +++ b/t/db_dependent/Koha/SharedContent.t @@ -23,7 +23,7 @@ use t::lib::TestBuilder; use t::lib::Mocks; use Test::MockModule; use Test::MockObject; -use Test::More tests => 43; +use Test::More tests => 44; use Koha::Database; use Koha::Patrons; use Koha::Subscriptions; @@ -41,7 +41,10 @@ my $want_error = 0; my $post_request = 0; my $query = {}; -$Koha::SharedContent::MANA_IP = 'https://foo.bar'; +t::lib::Mocks::mock_config( 'mana_config', 'https://foo.bar'); + +is(Koha::SharedContent::manaUrl(), 'https://foo.bar', 'Mana URL'); + my $result = Koha::SharedContent::manaGetRequest('report', $query); ok($result->{msg} =~ /Can\'t connect to foo.bar:443$/, 'Unable to connect'); is($result->{code}, 500, 'Code is 500'); diff --git a/t/db_dependent/Koha/Subscription.t b/t/db_dependent/Koha/Subscription.t index 09c582f..14cf87f 100644 --- a/t/db_dependent/Koha/Subscription.t +++ b/t/db_dependent/Koha/Subscription.t @@ -31,7 +31,6 @@ use t::lib::TestBuilder; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; -my $builder = t::lib::TestBuilder->new; use_ok('Koha::Subscription'); @@ -135,12 +134,11 @@ is( $sub_1->{numberpattern}, my $ref = { 'title' => $biblio_1->{title}, - 'notes' => $sub_1->{notes}, 'sfdescription' => $sub_freq_1->{description}, - 'displayorder' => $sub_freq_1->{displayorder}, 'unit' => $sub_freq_1->{unit}, 'unitsperissue' => $sub_freq_1->{unitsperissue}, 'issuesperunit' => $sub_freq_1->{issuesperunit}, + 'label' => $sub_np_1->{label}, 'sndescription' => $sub_np_1->{description}, 'numberingmethod' => $sub_np_1->{numberingmethod}, 'label1' => $sub_np_1->{label1}, @@ -166,7 +164,7 @@ my $ref = { 'publishercode' => $bi_1->{publishercode} }; -is_deeply( Koha::Subscription::get_sharable_info( $sub_1->{subscriptionid} ), +is_deeply( Koha::Subscription->get_sharable_info( $sub_1->{subscriptionid} ), $ref, "get_sharable_info function is ok" ); $schema->storage->txn_rollback; -- 2.7.4