Jonathan Druart
9d6d641d1f
On bug 17591 we discovered that there was something weird going on with the way we export and use subroutines/modules. This patch tries to standardize our EXPORT to use EXPORT_OK only. That way we will need to explicitely define the subroutine we want to use from a module. This patch is a squashed version of: Bug 17600: After export.pl Bug 17600: After perlimport Bug 17600: Manual changes Bug 17600: Other manual changes after second perlimports run Bug 17600: Fix tests And a lot of other manual changes. export.pl is a dirty script that can be found on bug 17600. "perlimport" is: git clone https://github.com/oalders/App-perlimports.git cd App-perlimports/ cpanm --installdeps . export PERL5LIB="$PERL5LIB:/kohadevbox/koha/App-perlimports/lib" find . \( -name "*.pl" -o -name "*.pm" \) -exec perl App-perlimports/script/perlimports --inplace-edit --no-preserve-unused --filename {} \; The ideas of this patch are to: * use EXPORT_OK instead of EXPORT * perltidy the EXPORT_OK list * remove '&' before the subroutine names * remove some uneeded use statements * explicitely import the subroutines we need within the controllers or modules Note that the private subroutines (starting with _) should not be exported (and not used from outside of the module except from tests). EXPORT vs EXPORT_OK (from https://www.thegeekstuff.com/2010/06/perl-exporter-examples/) """ Export allows to export the functions and variables of modules to user’s namespace using the standard import method. This way, we don’t need to create the objects for the modules to access it’s members. @EXPORT and @EXPORT_OK are the two main variables used during export operation. @EXPORT contains list of symbols (subroutines and variables) of the module to be exported into the caller namespace. @EXPORT_OK does export of symbols on demand basis. """ If this patch caused a conflict with a patch you wrote prior to its push: * Make sure you are not reintroducing a "use" statement that has been removed * "$subroutine" is not exported by the C4::$MODULE module means that you need to add the subroutine to the @EXPORT_OK list * Bareword "$subroutine" not allowed while "strict subs" means that you didn't imported the subroutine from the module: - use $MODULE qw( $subroutine list ); You can also use the fully qualified namespace: C4::$MODULE::$subroutine Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
220 lines
10 KiB
Perl
Executable file
220 lines
10 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
use Modern::Perl;
|
|
use Test::More tests => 74;
|
|
use List::Util qw( shuffle );
|
|
use MARC::Field;
|
|
use MARC::Record;
|
|
|
|
use C4::Context;
|
|
use C4::Items;
|
|
use C4::Biblio qw( AddBiblio );
|
|
use Koha::Database;
|
|
|
|
use t::lib::TestBuilder;
|
|
|
|
use_ok('C4::ShelfBrowser', qw( GetNearbyItems ));
|
|
|
|
my $schema = Koha::Database->schema;
|
|
$schema->storage->txn_begin;
|
|
my $builder = t::lib::TestBuilder->new;
|
|
my $dbh = C4::Context->dbh;
|
|
|
|
$dbh->do(q|DELETE FROM reserves|);
|
|
$dbh->do(q|DELETE FROM issues|);
|
|
$dbh->do(q|DELETE FROM items|);
|
|
|
|
my $library = $builder->build({
|
|
source => 'Branch',
|
|
});
|
|
|
|
my $cn;
|
|
|
|
# 100.100 150.100 200.100 210.100 300.000 320.000 400.100 410.100 500.100 510.100 520.100 600.000 610.000 700.100 710.100 720.100 730.100 740.100 750.100
|
|
my @callnumbers = qw(
|
|
100.100
|
|
150.100
|
|
200.100
|
|
210.100
|
|
300.000
|
|
320.000
|
|
400.100
|
|
410.100
|
|
500.100
|
|
510.100
|
|
520.100
|
|
600.000
|
|
610.000
|
|
700.100
|
|
710.100
|
|
720.100
|
|
730.100
|
|
740.100
|
|
750.100
|
|
);
|
|
|
|
my $record = MARC::Record->new();
|
|
$record->append_fields(
|
|
MARC::Field->new('100', ' ', ' ', a => 'Donald E. Knuth.'),
|
|
MARC::Field->new('245', ' ', ' ', a => 'The art of computer programming'),
|
|
);
|
|
my ( $biblionumber ) = C4::Biblio::AddBiblio($record, '');
|
|
|
|
for my $callnumber ( shuffle @callnumbers ) {
|
|
my $itemnumber = $builder->build_sample_item(
|
|
{
|
|
biblionumber => $biblionumber,
|
|
library => $library->{branchcode},
|
|
itemcallnumber => $callnumber,
|
|
}
|
|
)->itemnumber;
|
|
$cn->{$callnumber} = {
|
|
biblionumber => $biblionumber,
|
|
itemnumber => $itemnumber,
|
|
itemcallnumber => $callnumber,
|
|
}
|
|
}
|
|
|
|
my $nearby;
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'500.100'}{itemnumber} );
|
|
# We have
|
|
# < 320.000 400.100 410.100 500.100 510.100 520.100 600.000 >
|
|
# 6 7 8 [9] 10 11 12
|
|
# Clicking on previous, we want a link to 150.100
|
|
is( $nearby->{prev_item}{itemcallnumber}, '150.100', "Simple case: previous link 1/2" );
|
|
is( $nearby->{prev_item}{itemnumber}, $cn->{'150.100'}{itemnumber}, "Simple case: previous link 2/2" );
|
|
# Clicking on next, we want a link to 730.100
|
|
is( $nearby->{next_item}{itemcallnumber}, '720.100', "Simple case: next link 1/2" );
|
|
is( $nearby->{next_item}{itemnumber}, $cn->{'720.100'}{itemnumber}, "Simple case: next link 2/2" );
|
|
|
|
is( $nearby->{items}[0]{itemcallnumber}, '320.000', "Simple case: item 1");
|
|
is( $nearby->{items}[1]{itemcallnumber}, '400.100', "Simple case: item 2");
|
|
is( $nearby->{items}[2]{itemcallnumber}, '410.100', "Simple case: item 3");
|
|
is( $nearby->{items}[3]{itemcallnumber}, '500.100', "Simple case: item 4");
|
|
is( $nearby->{items}[4]{itemcallnumber}, '510.100', "Simple case: item 5");
|
|
is( $nearby->{items}[5]{itemcallnumber}, '520.100', "Simple case: item 6");
|
|
is( $nearby->{items}[6]{itemcallnumber}, '600.000', "Simple case: item 7");
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'500.100'}{itemnumber}, 2, 3 );
|
|
# We have
|
|
# < 400.100 410.100 500.100 510.100 520.100 >
|
|
# 7 8 [9] 10 11
|
|
# Clicking on previous, we want a link to 320.000
|
|
is( $nearby->{prev_item}{itemcallnumber}, '320.000', "Test gap: previous link 1/2" );
|
|
is( $nearby->{prev_item}{itemnumber}, $cn->{'320.000'}{itemnumber}, "Test gap: previous link 2/2" );
|
|
# Clicking on next, we want a link to 600.000
|
|
is( $nearby->{next_item}{itemcallnumber}, '600.000', "Test gap: next link 1/2" );
|
|
is( $nearby->{next_item}{itemnumber}, $cn->{'600.000'}{itemnumber}, "Test gap: next link 2/2" );
|
|
|
|
is( scalar( @{$nearby->{items}} ), 5, "Test gap: got 5 items" );
|
|
is( $nearby->{items}[0]{itemcallnumber}, '400.100', "Test gap: item 1");
|
|
is( $nearby->{items}[1]{itemcallnumber}, '410.100', "Test gap: item 2");
|
|
is( $nearby->{items}[2]{itemcallnumber}, '500.100', "Test gap: item 3");
|
|
is( $nearby->{items}[3]{itemcallnumber}, '510.100', "Test gap: item 4");
|
|
is( $nearby->{items}[4]{itemcallnumber}, '520.100', "Test gap: item 5");
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'300.000'}{itemnumber} );
|
|
# We have
|
|
# < 150.100 200.100 210.100 300.000 320.000 400.100 410.100 >
|
|
# 2 3 4 [5] 6 7 8
|
|
# Clicking on previous, we want a link to 100.100
|
|
is( $nearby->{prev_item}{itemcallnumber}, '100.100', "Test start shelf: previous link 1/2" );
|
|
is( $nearby->{prev_item}{itemnumber}, $cn->{'100.100'}{itemnumber}, "Test start shelf: previous link 2/2" );
|
|
# Clicking on next, we want a link to 600.000
|
|
is( $nearby->{next_item}{itemcallnumber}, '600.000', "Test start shelf: next link 1/2" );
|
|
is( $nearby->{next_item}{itemnumber}, $cn->{'600.000'}{itemnumber}, "Test start shelf: next link 2/2" );
|
|
|
|
is( $nearby->{items}[0]{itemcallnumber}, '150.100', "Test start shelf: item 1");
|
|
is( $nearby->{items}[1]{itemcallnumber}, '200.100', "Test start shelf: item 2");
|
|
is( $nearby->{items}[2]{itemcallnumber}, '210.100', "Test start shelf: item 3");
|
|
is( $nearby->{items}[3]{itemcallnumber}, '300.000', "Test start shelf: item 4");
|
|
is( $nearby->{items}[4]{itemcallnumber}, '320.000', "Test start shelf: item 5");
|
|
is( $nearby->{items}[5]{itemcallnumber}, '400.100', "Test start shelf: item 6");
|
|
is( $nearby->{items}[6]{itemcallnumber}, '410.100', "Test start shelf: item 7");
|
|
|
|
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'100.100'}{itemnumber} );
|
|
# We have
|
|
# 100.100 150.100 200.100 210.100 >
|
|
# [1] 2 3 4
|
|
# There is no previous link
|
|
is( $nearby->{prev_item}, undef, "Test first item on a shelf: no previous link" );
|
|
# Clicking on next, we want a link to 410.100
|
|
is( $nearby->{next_item}{itemcallnumber}, '410.100', "Test first item on a shelf: next link 1/2" );
|
|
is( $nearby->{next_item}{itemnumber}, $cn->{'410.100'}{itemnumber}, "Test first item on a shelf: next link 2/2" );
|
|
|
|
is( scalar( @{$nearby->{items}} ), 4, "Test first item on a shelf: There are 4 items displayed" );
|
|
is( $nearby->{items}[0]{itemcallnumber}, '100.100', "Test first item on a shelf: item 1");
|
|
is( $nearby->{items}[1]{itemcallnumber}, '150.100', "Test first item on a shelf: item 2");
|
|
is( $nearby->{items}[2]{itemcallnumber}, '200.100', "Test first item on a shelf: item 3");
|
|
is( $nearby->{items}[3]{itemcallnumber}, '210.100', "Test first item on a shelf: item 4");
|
|
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'150.100'}{itemnumber} );
|
|
# We have
|
|
# 100.100 150.100 200.100 210.100 300.000 >
|
|
# 1 [2] 3 4 5
|
|
# There is no previous link
|
|
is( $nearby->{prev_item}, undef, "Test second item on a shelf: no previous link" );
|
|
# Clicking on next, we want a link to 500.100
|
|
is( $nearby->{next_item}{itemcallnumber}, '500.100', "Test second item on a shelf: next link 1/2" );
|
|
is( $nearby->{next_item}{itemnumber}, $cn->{'500.100'}{itemnumber}, "Test second item on a shelf: next link 2/2" );
|
|
|
|
is( scalar( @{$nearby->{items}} ), 5, "Test second item on a shelf: got 5 items" );
|
|
is( $nearby->{items}[0]{itemcallnumber}, '100.100', "Test second item on a shelf: item 1");
|
|
is( $nearby->{items}[1]{itemcallnumber}, '150.100', "Test second item on a shelf: item 2");
|
|
is( $nearby->{items}[2]{itemcallnumber}, '200.100', "Test second item on a shelf: item 3");
|
|
is( $nearby->{items}[3]{itemcallnumber}, '210.100', "Test second item on a shelf: item 4");
|
|
is( $nearby->{items}[4]{itemcallnumber}, '300.000', "Test second item on a shelf: item 5");
|
|
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'710.100'}{itemnumber} );
|
|
# We have
|
|
# < 600.000 610.000 700.100 710.100 720.100 730.100 740.100 >
|
|
# 12 13 14 [15] 16 17 18
|
|
# Clicking on previous, we want a link to 410.100
|
|
is( $nearby->{prev_item}{itemcallnumber}, '410.100', "Test end shelf: previous link 1/2" );
|
|
is( $nearby->{prev_item}{itemnumber}, $cn->{'410.100'}{itemnumber}, "Test end shelf: previous link 2/2" );
|
|
# Clicking on next, we want a link to 730.100
|
|
is( $nearby->{next_item}{itemcallnumber}, '750.100', "Test end shelf: next link is a link to the last item 1/2" );
|
|
is( $nearby->{next_item}{itemnumber}, $cn->{'750.100'}{itemnumber}, "Test end shelf: next link is a link to the last item 2/2" );
|
|
|
|
is( $nearby->{items}[0]{itemcallnumber}, '600.000', "Test end shelf: item 1");
|
|
is( $nearby->{items}[1]{itemcallnumber}, '610.000', "Test end shelf: item 2");
|
|
is( $nearby->{items}[2]{itemcallnumber}, '700.100', "Test end shelf: item 3");
|
|
is( $nearby->{items}[3]{itemcallnumber}, '710.100', "Test end shelf: item 4");
|
|
is( $nearby->{items}[4]{itemcallnumber}, '720.100', "Test end shelf: item 5");
|
|
is( $nearby->{items}[5]{itemcallnumber}, '730.100', "Test end shelf: item 6");
|
|
is( $nearby->{items}[6]{itemcallnumber}, '740.100', "Test end shelf: item 7");
|
|
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'740.100'}{itemnumber} );
|
|
# We have
|
|
# < 710.100 720.100 730.100 740.100 750.100
|
|
# 15 16 17 [18] 19
|
|
# Clicking on previous, we want a link to
|
|
is( $nearby->{prev_item}{itemcallnumber}, '520.100', "Test end of the shelf: previous link 1/2" );
|
|
is( $nearby->{prev_item}{itemnumber}, $cn->{'520.100'}{itemnumber}, "Test end of the shelf: previous link 2/2" );
|
|
# No next link
|
|
is( $nearby->{next_item}, undef, "Test end of the shelf: no next link" );
|
|
|
|
is( scalar( @{$nearby->{items}} ), 5, "Test end of the shelf: got 5 items" );
|
|
is( $nearby->{items}[0]{itemcallnumber}, '710.100', "Test end of the shelf: item 1");
|
|
is( $nearby->{items}[1]{itemcallnumber}, '720.100', "Test end of the shelf: item 2");
|
|
is( $nearby->{items}[2]{itemcallnumber}, '730.100', "Test end of the shelf: item 3");
|
|
is( $nearby->{items}[3]{itemcallnumber}, '740.100', "Test end of the shelf: item 4");
|
|
is( $nearby->{items}[4]{itemcallnumber}, '750.100', "Test end of the shelf: item 5");
|
|
|
|
$nearby = C4::ShelfBrowser::GetNearbyItems( $cn->{'750.100'}{itemnumber} );
|
|
# We have
|
|
# < 720.100 730.100 740.100 750.100
|
|
# 16 17 18 [19]
|
|
# Clicking on previous, we want a link to
|
|
is( $nearby->{prev_item}{itemcallnumber}, '600.000', "Test last item of the shelf: previous link 1/2" );
|
|
is( $nearby->{prev_item}{itemnumber}, $cn->{'600.000'}{itemnumber}, "Test last item of the shelf: previous link 2/2" );
|
|
# No next link
|
|
is( $nearby->{next_item}, undef, "Test end of the shelf: no next link" );
|
|
|
|
is( scalar( @{$nearby->{items}} ), 4, "Test last item of the shelf: got 4 items" );
|