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>
100 lines
3 KiB
Perl
Executable file
100 lines
3 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
use Modern::Perl;
|
|
use C4::Circulation qw( AddOfflineOperation GetOfflineOperation GetOfflineOperations DeleteOfflineOperation );
|
|
|
|
use Koha::Database;
|
|
use Koha::DateUtils qw( dt_from_string output_pref );
|
|
use Koha::Library;
|
|
|
|
use Test::More tests => 7;
|
|
|
|
BEGIN {
|
|
use_ok('C4::Circulation', qw( AddOfflineOperation GetOfflineOperation GetOfflineOperations DeleteOfflineOperation ));
|
|
}
|
|
can_ok(
|
|
'C4::Circulation',
|
|
qw(
|
|
AddOfflineOperation
|
|
GetOfflineOperation
|
|
GetOfflineOperations
|
|
DeleteOfflineOperation
|
|
)
|
|
);
|
|
|
|
my $schema = Koha::Database->new->schema;
|
|
$schema->storage->txn_begin;
|
|
my $dbh = C4::Context->dbh;
|
|
|
|
$dbh->do(q|DELETE FROM issues|);
|
|
$dbh->do(q|DELETE FROM borrowers|);
|
|
$dbh->do(q|DELETE FROM items|);
|
|
$dbh->do(q|DELETE FROM branches|);
|
|
$dbh->do(q|DELETE FROM pending_offline_operations|);
|
|
|
|
#Add branch
|
|
my $samplebranch1 = {
|
|
branchcode => 'SAB1',
|
|
branchname => 'Sample Branch',
|
|
branchaddress1 => 'sample adr1',
|
|
branchaddress2 => 'sample adr2',
|
|
branchaddress3 => 'sample adr3',
|
|
branchzip => 'sample zip',
|
|
branchcity => 'sample city',
|
|
branchstate => 'sample state',
|
|
branchcountry => 'sample country',
|
|
branchphone => 'sample phone',
|
|
branchfax => 'sample fax',
|
|
branchemail => 'sample email',
|
|
branchurl => 'sample url',
|
|
branchip => 'sample ip',
|
|
opac_info => 'sample opac',
|
|
};
|
|
Koha::Library->new($samplebranch1)->store;
|
|
|
|
my $now = dt_from_string->truncate( to => 'minute' );
|
|
|
|
#Begin Tests
|
|
#Test AddOfflineOperation
|
|
is(
|
|
AddOfflineOperation(
|
|
'User1', $samplebranch1->{branchcode},
|
|
$now, 'Action1', 'CODE', 'Cardnumber1', 10
|
|
),
|
|
'Added.',
|
|
"OfflineOperation has been added"
|
|
);
|
|
my $offline_id =
|
|
$dbh->last_insert_id( undef, undef, 'pending_offline_operations', undef );
|
|
|
|
#Test GetOfflineOperations
|
|
is_deeply(
|
|
GetOfflineOperation($offline_id),
|
|
{
|
|
operationid => $offline_id,
|
|
userid => 'User1',
|
|
branchcode => $samplebranch1->{branchcode},
|
|
# FIXME sounds like we need a 'timestamp' dateformat
|
|
timestamp => output_pref({ dt => $now, dateformat => 'iso', dateonly => 0 }) . ':00',
|
|
action => 'Action1',
|
|
barcode => 'CODE',
|
|
cardnumber => 'Cardnumber1',
|
|
amount => '10.000000'
|
|
},
|
|
"GetOffline returns offlineoperation's informations"
|
|
);
|
|
is( GetOfflineOperation(), undef,
|
|
'GetOfflineOperation without parameters returns undef' );
|
|
is( GetOfflineOperation(-1), undef,
|
|
'GetOfflineOperation with wrong parameters returns undef' );
|
|
|
|
#Test GetOfflineOperations
|
|
#TODO later: test GetOfflineOperations
|
|
# Actually we cannot mock C4::Context->userenv in unit tests
|
|
|
|
#Test DeleteOfflineOperation
|
|
is( DeleteOfflineOperation($offline_id),
|
|
'Deleted.', 'Offlineoperation has been deleted' );
|
|
|
|
#is (DeleteOfflineOperation(), undef, 'DeleteOfflineOperation without id returns undef');
|
|
#is (DeleteOfflineOperation(-1),undef, 'DeleteOfflineOperation with a wrong id returns undef');#FIXME
|