Bug 9659: Move new unit test to db-dependent directory
authorJared Camins-Esakov <jcamins@cpbibliography.com>
Fri, 26 Apr 2013 12:08:07 +0000 (08:08 -0400)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Fri, 26 Apr 2013 12:08:07 +0000 (08:08 -0400)
C4::Reports::Guided requires a koha-conf.xml file to be in place in
order to load. This means that any test which uses it has to go in
t/db_dependent

Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
t/ReportsGuided.t [deleted file]
t/db_dependent/ReportsGuided.t [new file with mode: 0755]

diff --git a/t/ReportsGuided.t b/t/ReportsGuided.t
deleted file mode 100755 (executable)
index 26e1a49..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/usr/bin/perl
-
-use Modern::Perl;
-
-use Test::More tests => 12;
-use Test::MockModule;
-use DBD::Mock;
-
-use_ok('C4::Reports::Guided');
-
-my $context = new Test::MockModule('C4::Context');
-my $koha = new Test::MockModule('C4::Koha');
-
-$context->mock(
-    '_new_dbh',
-    sub {
-        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
-          || die "Cannot create handle: $DBI::errstr\n";
-        return $dbh;
-    }
-);
-
-
-sub MockedIsAuthorisedValueCategory {
-    my $authorised_value = shift;
-
-    if ( $authorised_value eq 'LOC' ) {
-        return 1;
-    } else {
-        return 0;
-    }
-}
-
-$koha->mock(
-    'IsAuthorisedValueCategory',
-    \&MockedIsAuthorisedValueCategory
-);
-
-{   # GetReservedAuthorisedValues tests
-    # This one will catch new reserved words not added
-    # to GetReservedAuthorisedValues
-    my %test_authval = (
-        'date' => 1,
-        'branches' => 1,
-        'itemtypes' => 1,
-        'cn_source' => 1,
-        'categorycode' => 1
-    );
-
-    my $reserved_authorised_values = GetReservedAuthorisedValues();
-    is_deeply(\%test_authval, $reserved_authorised_values,
-                'GetReservedAuthorisedValues returns a fixed list');
-}
-
-SKIP: {
-
-    skip "DBD::Mock is too old", 7
-        unless $DBD::Mock::VERSION >= 1.45;
-
-    ok( IsAuthorisedValueValid('LOC'),
-        'User defined authorised value category is valid');
-
-    ok( ! IsAuthorisedValueValid('XXX'),
-        'Not defined authorised value category is invalid');
-
-    # Loop through the reserved authorised values
-    foreach my $authorised_value ( keys GetReservedAuthorisedValues() ) {
-        ok( IsAuthorisedValueValid($authorised_value),
-            '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
-    }
-}
-
-{   # GetParametersFromSQL tests
-
-    my $test_query_1 = "
-        SELECT date_due
-        FROM old_issues
-        WHERE YEAR(timestamp) = <<Year|custom_list>> AND
-              branchcode = <<Branch|branches>> AND
-              borrowernumber = <<Borrower>>
-    ";
-
-    my @test_parameters_with_custom_list = (
-        { 'name' => 'Year', 'authval' => 'custom_list' },
-        { 'name' => 'Branch', 'authval' => 'branches' },
-        { 'name' => 'Borrower', 'authval' => undef }
-    );
-
-    is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
-        'SQL params are correctly parsed');
-
-    # ValidateSQLParameters tests
-    my @problematic_parameters = ();
-    push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
-    is_deeply( ValidateSQLParameters( $test_query_1 ),
-               \@problematic_parameters,
-               '\'custom_list\' not a valid category' );
-
-    my $test_query_2 = "
-        SELECT date_due
-        FROM old_issues
-        WHERE YEAR(timestamp) = <<Year|date>> AND
-              branchcode = <<Branch|branches>> AND
-              borrowernumber = <<Borrower|LOC>>
-    ";
-
-    is_deeply( ValidateSQLParameters( $test_query_2 ),
-        [],
-        'All parameters valid, empty problematic authvals list');
-}
diff --git a/t/db_dependent/ReportsGuided.t b/t/db_dependent/ReportsGuided.t
new file mode 100755 (executable)
index 0000000..26e1a49
--- /dev/null
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+
+use Modern::Perl;
+
+use Test::More tests => 12;
+use Test::MockModule;
+use DBD::Mock;
+
+use_ok('C4::Reports::Guided');
+
+my $context = new Test::MockModule('C4::Context');
+my $koha = new Test::MockModule('C4::Koha');
+
+$context->mock(
+    '_new_dbh',
+    sub {
+        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
+          || die "Cannot create handle: $DBI::errstr\n";
+        return $dbh;
+    }
+);
+
+
+sub MockedIsAuthorisedValueCategory {
+    my $authorised_value = shift;
+
+    if ( $authorised_value eq 'LOC' ) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+$koha->mock(
+    'IsAuthorisedValueCategory',
+    \&MockedIsAuthorisedValueCategory
+);
+
+{   # GetReservedAuthorisedValues tests
+    # This one will catch new reserved words not added
+    # to GetReservedAuthorisedValues
+    my %test_authval = (
+        'date' => 1,
+        'branches' => 1,
+        'itemtypes' => 1,
+        'cn_source' => 1,
+        'categorycode' => 1
+    );
+
+    my $reserved_authorised_values = GetReservedAuthorisedValues();
+    is_deeply(\%test_authval, $reserved_authorised_values,
+                'GetReservedAuthorisedValues returns a fixed list');
+}
+
+SKIP: {
+
+    skip "DBD::Mock is too old", 7
+        unless $DBD::Mock::VERSION >= 1.45;
+
+    ok( IsAuthorisedValueValid('LOC'),
+        'User defined authorised value category is valid');
+
+    ok( ! IsAuthorisedValueValid('XXX'),
+        'Not defined authorised value category is invalid');
+
+    # Loop through the reserved authorised values
+    foreach my $authorised_value ( keys GetReservedAuthorisedValues() ) {
+        ok( IsAuthorisedValueValid($authorised_value),
+            '\''.$authorised_value.'\' is a reserved word, and thus a valid authorised value');
+    }
+}
+
+{   # GetParametersFromSQL tests
+
+    my $test_query_1 = "
+        SELECT date_due
+        FROM old_issues
+        WHERE YEAR(timestamp) = <<Year|custom_list>> AND
+              branchcode = <<Branch|branches>> AND
+              borrowernumber = <<Borrower>>
+    ";
+
+    my @test_parameters_with_custom_list = (
+        { 'name' => 'Year', 'authval' => 'custom_list' },
+        { 'name' => 'Branch', 'authval' => 'branches' },
+        { 'name' => 'Borrower', 'authval' => undef }
+    );
+
+    is_deeply( GetParametersFromSQL($test_query_1), \@test_parameters_with_custom_list,
+        'SQL params are correctly parsed');
+
+    # ValidateSQLParameters tests
+    my @problematic_parameters = ();
+    push @problematic_parameters, { 'name' => 'Year', 'authval' => 'custom_list' };
+    is_deeply( ValidateSQLParameters( $test_query_1 ),
+               \@problematic_parameters,
+               '\'custom_list\' not a valid category' );
+
+    my $test_query_2 = "
+        SELECT date_due
+        FROM old_issues
+        WHERE YEAR(timestamp) = <<Year|date>> AND
+              branchcode = <<Branch|branches>> AND
+              borrowernumber = <<Borrower|LOC>>
+    ";
+
+    is_deeply( ValidateSQLParameters( $test_query_2 ),
+        [],
+        'All parameters valid, empty problematic authvals list');
+}