test suite cleanup
authorGalen Charlton <galen.charlton@liblime.com>
Tue, 8 Jan 2008 18:57:33 +0000 (12:57 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 8 Jan 2008 20:08:02 +0000 (14:08 -0600)
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 <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
23 files changed:
C4/Context.pm
C4/Output.pm
t/Accounts.t
t/AuthoritiesMarc.t
t/Biblio.t
t/Boolean.t
t/Breeding.t
t/Circulation.t
t/Date.t
t/Dates.t
t/Items.t
t/Letters.t
t/Log.t
t/Members.t
t/NewsChannels.t
t/Overdues.t
t/Print.t
t/Reserves.t
t/Search.t
t/Serials.t
t/Suggestions.t
t/Z3950.t
t/override_context_prefs.pm [new file with mode: 0644]

index ca7316b..94fb745 100644 (file)
@@ -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(<<EOT);
         SELECT    value
         FROM    systempreferences
index 98c8e79..1c12a73 100644 (file)
@@ -160,7 +160,7 @@ sub themelanguage {
     if ( $interface eq "intranet" ) {
         @languages = split " ", C4::Context->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
index f0d8e4d..27c5f6f 100755 (executable)
@@ -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');
 }
 
index d59b43b..68fe6d0 100755 (executable)
@@ -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');
 }
 
index c186058..bed3a45 100755 (executable)
@@ -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');
 }
 
index eba01eb..1d179c5 100755 (executable)
@@ -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;
 }
index e672bf1..69151d9 100755 (executable)
@@ -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');
 }
 
index fc531f4..7d47efc 100755 (executable)
@@ -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');
 }
 
index 6b98a5b..28c32b2 100755 (executable)
--- 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');
 }
 
index 5a3c5ec..c1db4ba 100755 (executable)
--- 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));
 }
 
index b98e340..3a10e08 100644 (file)
--- 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');
 }
 
index 603e37e..ad02beb 100755 (executable)
@@ -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 eca6b9c..823a14e 100755 (executable)
--- 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');
 }
 
index bbcfc95..6f5f588 100755 (executable)
@@ -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');
 }
 
index bbcaab1..1de9281 100755 (executable)
@@ -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');
 }
 
index 62725cb..4a76e00 100755 (executable)
@@ -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');
 }
 
index 1a05304..1064d33 100755 (executable)
--- 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');
 }
 
index f61d258..a1ea60f 100755 (executable)
@@ -10,5 +10,8 @@ use Test::More tests => 1;
 
 BEGIN {
         use_ok('C4::Reserves');
+       use FindBin;
+       use lib $FindBin::Bin;
+       use override_context_prefs;
 }
 
index 3527060..916507b 100755 (executable)
@@ -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');
 }
 
index b583746..b078869 100755 (executable)
@@ -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');
 }
 
index afc0f00..fcf6bfd 100755 (executable)
@@ -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');
 }
 
index 4fb4c37..5b720bd 100755 (executable)
--- 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 (file)
index 0000000..588fd68
--- /dev/null
@@ -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;