Browse Source
Signed-off-by: Chris Cormack <crc@liblime.com> Signed-off-by: Joshua Ferraro <jmf@liblime.com>3.0.x
Joe Atzberger
17 years ago
committed by
Joshua Ferraro
5 changed files with 204 additions and 156 deletions
@ -0,0 +1,48 @@ |
|||
package C4::Utils; |
|||
|
|||
# Useful code I didn't feel like duplicating all over the place. |
|||
# |
|||
|
|||
use strict; |
|||
use warnings; |
|||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug); |
|||
|
|||
BEGIN { |
|||
require Exporter; |
|||
$VERSION = 1.00; # set the version for version checking |
|||
$debug = $ENV{DEBUG} || 0; |
|||
@ISA = qw(Exporter); |
|||
@EXPORT_OK = qw(&maxwidth &hashdump); |
|||
%EXPORT_TAGS = ( all => [qw(&maxwidth &hashdump)], ); |
|||
} |
|||
|
|||
|
|||
sub maxwidth (@) { |
|||
(@_) or return 0; |
|||
return (sort {$a <=> $b} map {length} @_)[-1]; |
|||
} |
|||
|
|||
sub hashdump ($$) { |
|||
my $pre = shift; |
|||
my $val = shift; |
|||
if (ref($val) =~ /HASH/) { |
|||
print "$pre = HASH w/ " . scalar(keys %$val) . " keys.\n"; |
|||
my $w2 = maxwidth(keys %$val); |
|||
foreach (sort keys %$val) { |
|||
&hashdump($pre . '->{' . sprintf('%' . $w2 .'s', $_) . '}', $val->{$_}); |
|||
} |
|||
print "\n"; |
|||
} elsif (ref($val) =~ /ARRAY/) { |
|||
print "$pre = ARRAY w/ " . scalar(@$val) . " members.\n"; |
|||
my $w2 = maxwidth(@$val); |
|||
foreach (@$val) { |
|||
&hashdump($pre . '->{' . sprintf('%' . $w2 .'s', $_) . '}', $_); |
|||
} |
|||
print "\n"; |
|||
} else { |
|||
print "$pre = $val\n"; |
|||
} |
|||
} |
|||
|
|||
1; |
|||
__END__ |
@ -1,14 +1,49 @@ |
|||
#!/usr/bin/perl |
|||
# |
|||
# This Koha test module is a stub! |
|||
# Add more tests here!!! |
|||
|
|||
use strict; |
|||
use warnings; |
|||
|
|||
use Test::More tests => 1; |
|||
use Test::More tests => 91; |
|||
use vars qw($debug $koha $dbh $config $ret); |
|||
|
|||
BEGIN { |
|||
use_ok('C4::Context'); |
|||
$debug = $ENV{DEBUG} || 0; |
|||
diag("Note: The overall number of tests may vary by configuration."); |
|||
diag("First we need to check your environmental variables"); |
|||
for (qw(KOHA_CONF PERL5LIB)) { |
|||
ok($ret = $ENV{$_}, "ENV{$_} = $ret"); |
|||
} |
|||
use_ok('C4::Context'); |
|||
use_ok('C4::Utils', qw/ :all /); |
|||
} |
|||
|
|||
ok($koha = C4::Context->new, 'C4::Context->new'); |
|||
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context'); |
|||
ok($ret = C4::Context->KOHAVERSION, ' (function) KOHAVERSION = ' . ($ret||'')); |
|||
ok($ret = $koha->KOHAVERSION, ' $koha->KOHAVERSION = ' . ($ret||'')); |
|||
my @keys = keys %$koha; |
|||
diag("Number of keys in \%\$koha: " . scalar @keys); |
|||
our $width = 0; |
|||
if (ok(@keys)) { |
|||
$width = maxwidth(@keys); |
|||
$debug and diag "widest key is $width"; |
|||
} |
|||
foreach (sort @keys) { |
|||
ok(exists $koha->{$_}, |
|||
'$koha->{' . sprintf('%' . $width . 's', $_) . '} exists ' |
|||
. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.") |
|||
); |
|||
} |
|||
diag "Examining defined key values."; |
|||
foreach (grep {defined $koha->{$_}} sort @keys) { |
|||
print "\n"; |
|||
hashdump('$koha->{' . sprintf('%' . $width . 's', $_) . '}', $koha->{$_}); |
|||
} |
|||
ok($config = $koha->{config}, 'Getting $koha->{config} '); |
|||
|
|||
# diag("Examining configuration."); |
|||
diag("Note: The overall number of tests may vary by configuration. Disregard the projected number."); |
|||
1; |
|||
__END__ |
|||
|
|||
|
Loading…
Reference in new issue