From 5290ec559679f80fa3abb8845581e9634d26c649 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 8 Jan 2008 12:57:33 -0600 Subject: [PATCH] test suite cleanup Many of the tests were failing or putting warnings because a valid systempreferences table is usaully absent by the time 'make test' is run. Fortunately, only a few modules try to invoke C4::Context->preference during module initialization, so added to the test suite override_context_prefs.pm, which replaces preference() with a sub to return testing values for three variables: 'dateformat', 'marcflavour', and 'LibraryName'. Also fixed bug in t/Boolean.t With this patch and the patch to move the DB-dependent tests off to the side for the moment, 'make test' now runs cleanly, at least on Debian. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Context.pm | 1 + C4/Output.pm | 2 +- t/Accounts.t | 3 +++ t/AuthoritiesMarc.t | 3 +++ t/Biblio.t | 3 +++ t/Boolean.t | 2 +- t/Breeding.t | 3 +++ t/Circulation.t | 3 +++ t/Date.t | 14 +++----------- t/Dates.t | 3 +++ t/Items.t | 3 +++ t/Letters.t | 3 +++ t/Log.t | 3 +++ t/Members.t | 3 +++ t/NewsChannels.t | 3 +++ t/Overdues.t | 3 +++ t/Print.t | 3 +++ t/Reserves.t | 3 +++ t/Search.t | 3 +++ t/Serials.t | 3 +++ t/Suggestions.t | 3 +++ t/Z3950.t | 3 +++ t/override_context_prefs.pm | 23 +++++++++++++++++++++++ 23 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 t/override_context_prefs.pm diff --git a/C4/Context.pm b/C4/Context.pm index ca7316b07d..94fb7450e0 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -433,6 +433,7 @@ sub preference my $retval; # Return value my $dbh = C4::Context->dbh or return 0; # Look up systempreferences.variable==$var + warn $var; $retval = $dbh->selectrow_array(<preference("opaclanguages"); @themes = split " ", C4::Context->preference("template"); - pop @languages, $lang if $lang; # FIXME: pop takes only 1 arg. and if $lang always TRUE! + push @languages, $lang if $lang; } else { # we are in the opac here, what im trying to do is let the individual user diff --git a/t/Accounts.t b/t/Accounts.t index f0d8e4dcab..27c5f6f3bf 100755 --- a/t/Accounts.t +++ b/t/Accounts.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Accounts'); } diff --git a/t/AuthoritiesMarc.t b/t/AuthoritiesMarc.t index d59b43b2fe..68fe6d06de 100755 --- a/t/AuthoritiesMarc.t +++ b/t/AuthoritiesMarc.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::AuthoritiesMarc'); } diff --git a/t/Biblio.t b/t/Biblio.t index c18605869a..bed3a4599b 100755 --- a/t/Biblio.t +++ b/t/Biblio.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Biblio'); } diff --git a/t/Boolean.t b/t/Boolean.t index eba01eb0bf..1d179c5a4c 100755 --- a/t/Boolean.t +++ b/t/Boolean.t @@ -18,7 +18,7 @@ sub f ($) { }; if ($@) { $it = $@; - $it =~ s/ at \S+ line \d+$\.\n//s; + $it =~ s/ at \S+ line \d+\.\n//s; } return $it; } diff --git a/t/Breeding.t b/t/Breeding.t index e672bf1395..69151d9810 100755 --- a/t/Breeding.t +++ b/t/Breeding.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Breeding'); } diff --git a/t/Circulation.t b/t/Circulation.t index fc531f482c..7d47efce45 100755 --- a/t/Circulation.t +++ b/t/Circulation.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Circulation'); } diff --git a/t/Date.t b/t/Date.t index 6b98a5b506..28c32b2635 100755 --- a/t/Date.t +++ b/t/Date.t @@ -7,17 +7,9 @@ use warnings; use Test::More tests => 4; BEGIN { - use C4::Context; - package C4::Context; - no warnings; - sub preference { - my $self = shift; - my $pref = shift; - return 'us' if $pref eq "dateformat"; - return; - } - use warnings; - package main; + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Date'); } diff --git a/t/Dates.t b/t/Dates.t index 5a3c5ecd86..c1db4baba7 100755 --- a/t/Dates.t +++ b/t/Dates.t @@ -5,6 +5,9 @@ use warnings; use Test::More tests => 92; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Dates', qw(format_date format_date_in_iso)); } diff --git a/t/Items.t b/t/Items.t index b98e340a6b..3a10e080a9 100644 --- a/t/Items.t +++ b/t/Items.t @@ -5,6 +5,9 @@ use warnings; use Test::More tests => 28; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Items'); } diff --git a/t/Letters.t b/t/Letters.t index 603e37efa7..ad02beb8fe 100755 --- a/t/Letters.t +++ b/t/Letters.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Letters'); } diff --git a/t/Log.t b/t/Log.t index eca6b9c60e..823a14e307 100755 --- a/t/Log.t +++ b/t/Log.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Log'); } diff --git a/t/Members.t b/t/Members.t index bbcfc95c32..6f5f588683 100755 --- a/t/Members.t +++ b/t/Members.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Members'); } diff --git a/t/NewsChannels.t b/t/NewsChannels.t index bbcaab14cc..1de9281314 100755 --- a/t/NewsChannels.t +++ b/t/NewsChannels.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::NewsChannels'); } diff --git a/t/Overdues.t b/t/Overdues.t index 62725cb746..4a76e0051a 100755 --- a/t/Overdues.t +++ b/t/Overdues.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Overdues'); } diff --git a/t/Print.t b/t/Print.t index 1a05304e4d..1064d33665 100755 --- a/t/Print.t +++ b/t/Print.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Print'); } diff --git a/t/Reserves.t b/t/Reserves.t index f61d25852e..a1ea60fb01 100755 --- a/t/Reserves.t +++ b/t/Reserves.t @@ -10,5 +10,8 @@ use Test::More tests => 1; BEGIN { use_ok('C4::Reserves'); + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; } diff --git a/t/Search.t b/t/Search.t index 3527060307..916507b3e4 100755 --- a/t/Search.t +++ b/t/Search.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Search'); } diff --git a/t/Serials.t b/t/Serials.t index b583746b56..b078869701 100755 --- a/t/Serials.t +++ b/t/Serials.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Serials'); } diff --git a/t/Suggestions.t b/t/Suggestions.t index afc0f00ebf..fcf6bfd23d 100755 --- a/t/Suggestions.t +++ b/t/Suggestions.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Suggestions'); } diff --git a/t/Z3950.t b/t/Z3950.t index 4fb4c37917..5b720bd18c 100755 --- a/t/Z3950.t +++ b/t/Z3950.t @@ -9,6 +9,9 @@ use warnings; use Test::More tests => 1; BEGIN { + use FindBin; + use lib $FindBin::Bin; + use override_context_prefs; use_ok('C4::Z3950'); } diff --git a/t/override_context_prefs.pm b/t/override_context_prefs.pm new file mode 100644 index 0000000000..588fd68d4d --- /dev/null +++ b/t/override_context_prefs.pm @@ -0,0 +1,23 @@ +use strict; +use warnings; + +# This stub module is used to override +# the C4::Context sub preference for the +# purpose of the test suite. This allows +# non-DB-dependent tests of most modules, +# particularly the ones that include C4::Dates. + +use C4::Context; + +package C4::Context; +no warnings; +sub preference { + my $self = shift; + my $pref = shift; + return 'us' if $pref eq 'dateformat'; + return 'MARC21' if $pref eq 'marcflavour'; + return 'Test Library' if $pref eq 'LibraryName'; + return; +} + +1; -- 2.39.5