Browse Source

Bug 21299: (QA follow-up) Rename module and subroutine

See QA request at comment7.
Removing camelcase from subroutinename.
Renaming module to Koha::Util::Navigation (after cmty feedback).

Test plan:
Run t/Koha/Util/Navigation.t.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
18.11.x
Marcel de Rooy 3 years ago
committed by Nick Clemens
parent
commit
5755f30b1b
  1. 12
      Koha/Util/Navigation.pm
  2. 4
      changelanguage.pl
  3. 4
      opac/opac-changelanguage.pl
  4. 24
      t/Koha/Util/Navigation.t

12
Koha/Util.pm → Koha/Util/Navigation.pm

@ -1,4 +1,4 @@
package Koha::Util;
package Koha::Util::Navigation;
# Copyright Rijksmuseum 2018
#
@ -26,9 +26,9 @@ Koha::Util
=head1 SYNOPSIS
use Koha::Util;
use Koha::Util::Navigation;
my $cgi = CGI->new;
my $referer = Koha::Util::localReferer($cgi);
my $referer = Koha::Util::Navigation::local_referer($cgi);
=head1 DESCRIPTION
@ -36,9 +36,9 @@ Utility class
=head1 FUNCTIONS
=head2 localReferer
=head2 local_referer
my $referer = Koha::Util::localReferer( $cgi, { fallback => '/', remove_language => 1, staff => 1 });
my $referer = Koha::Util::Navigation::local_referer( $cgi, { fallback => '/', remove_language => 1, staff => 1 });
If the referer is a local URI, return local path.
Otherwise return fallback.
@ -47,7 +47,7 @@ Utility class
=cut
sub localReferer {
sub local_referer {
my ( $cgi, $params ) = @_;
my $referer = $cgi->referer;
my $fallback = $params->{fallback} // '/';

4
changelanguage.pl

@ -18,10 +18,10 @@
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Templates;
use Koha::Util;
use Koha::Util::Navigation;
my $query = new CGI;
my $language = $query->param('language');
my $url = Koha::Util::localReferer($query, {remove_language => 1, staff => 1});
my $url = Koha::Util::Navigation::local_referer($query, {remove_language => 1, staff => 1});
C4::Templates::setlanguagecookie( $query, $language, $url );

4
opac/opac-changelanguage.pl

@ -18,10 +18,10 @@
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Templates;
use Koha::Util;
use Koha::Util::Navigation;
my $query = new CGI;
my $language = $query->param('language');
my $url = Koha::Util::localReferer($query, { remove_language => 1 });
my $url = Koha::Util::Navigation::local_referer($query, { remove_language => 1 });
C4::Templates::setlanguagecookie( $query, $language, $url );

24
t/Koha/Util/localReferer.t → t/Koha/Util/Navigation.t

@ -4,9 +4,9 @@ use Test::More tests => 1;
use Test::MockObject;
use t::lib::Mocks;
use Koha::Util;
use Koha::Util::Navigation;
subtest 'Tests for localReferer' => sub {
subtest 'Tests for local_referer' => sub {
plan tests => 10;
my ( $referer, $base );
@ -17,31 +17,31 @@ subtest 'Tests for localReferer' => sub {
# Start with filled OPACBaseIRL
t::lib::Mocks::mock_preference('OPACBaseURL', 'https://koha.nl' );
$referer = 'https://somewhere.com/myscript';
is( Koha::Util::localReferer($cgi), '/', 'External referer' );
is( Koha::Util::Navigation::local_referer($cgi), '/', 'External referer' );
my $search = '/cgi-bin/koha/opac-search.pl?q=perl';
$referer = "https://koha.nl$search";
is( Koha::Util::localReferer($cgi), $search, 'opac-search' );
is( Koha::Util::Navigation::local_referer($cgi), $search, 'opac-search' );
$referer = 'https://koha.nl/custom/stuff';
is( Koha::Util::localReferer($cgi), '/', 'custom url' );
is( Koha::Util::Navigation::local_referer($cgi), '/', 'custom url' );
# trailing backslash
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://koha.nl/' );
$referer = "http://koha.nl$search";
is( Koha::Util::localReferer($cgi), $search, 'opac-search, trailing backslash' );
is( Koha::Util::Navigation::local_referer($cgi), $search, 'opac-search, trailing backslash' );
# no OPACBaseURL
t::lib::Mocks::mock_preference('OPACBaseURL', '');
$referer = 'https://somewhere.com/myscript';
$base = 'http://koha.nl';
is( Koha::Util::localReferer($cgi), '/', 'no opacbaseurl, external' );
is( Koha::Util::Navigation::local_referer($cgi), '/', 'no opacbaseurl, external' );
$referer = "https://koha.nl$search";
$base = 'https://koha.nl';
is( Koha::Util::localReferer($cgi), $search, 'no opacbaseurl, opac-search' );
is( Koha::Util::Navigation::local_referer($cgi), $search, 'no opacbaseurl, opac-search' );
$base = 'http://koha.nl';
is( Koha::Util::localReferer($cgi), $search, 'no opacbaseurl, opac-search, protocol diff' );
is( Koha::Util::Navigation::local_referer($cgi), $search, 'no opacbaseurl, opac-search, protocol diff' );
# base contains https, referer http (this should be very unusual)
# test parameters remove_language. staff
@ -49,12 +49,12 @@ subtest 'Tests for localReferer' => sub {
$search = '/cgi-bin/koha/catalogue/search.pl?q=perl'; # staff
$referer = "http://koha.nl:8080$search&language=zz-ZZ&debug=1";
$base = 'https://koha.nl:8080';
is( Koha::Util::localReferer($cgi, { remove_language => 1, staff => 1 }), $search.'&debug=1', 'no baseurl, staff search, protocol diff (base https)' );
is( Koha::Util::Navigation::local_referer($cgi, { remove_language => 1, staff => 1 }), $search.'&debug=1', 'no baseurl, staff search, protocol diff (base https)' );
# custom script, test fallback parameter
$referer = 'https://koha.nl/custom/stuff';
$base = 'https://koha.nl';
is( Koha::Util::localReferer($cgi, { fallback => 'ZZZ' }), 'ZZZ', 'no opacbaseurl, custom url, test fallback' );
is( Koha::Util::Navigation::local_referer($cgi, { fallback => 'ZZZ' }), 'ZZZ', 'no opacbaseurl, custom url, test fallback' );
$base = 'http://koha.nl';
is( Koha::Util::localReferer($cgi), '/', 'no opacbaseurl, custom url, protocol diff' );
is( Koha::Util::Navigation::local_referer($cgi), '/', 'no opacbaseurl, custom url, protocol diff' );
};
Loading…
Cancel
Save