Bug 8890 - move two more db dependent tests
authorRobin Sheat <robin@catalyst.net.nz>
Wed, 24 Oct 2012 05:51:07 +0000 (18:51 +1300)
committerPaul Poulain <paul.poulain@biblibre.com>
Wed, 24 Oct 2012 15:52:42 +0000 (17:52 +0200)
* t/AuthoritiesMarc.t
* t/SuggestionEngine_ExplodedTerms.t

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
t/AuthoritiesMarc.t [deleted file]
t/SuggestionEngine_ExplodedTerms.t [deleted file]
t/db_dependent/AuthoritiesMarc.t [new file with mode: 0755]
t/db_dependent/SuggestionEngine_ExplodedTerms.t [new file with mode: 0755]

diff --git a/t/AuthoritiesMarc.t b/t/AuthoritiesMarc.t
deleted file mode 100755 (executable)
index 9c8c1fd..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/perl
-#
-# This Koha test module is a stub!  
-# Add more tests here!!!
-
-use strict;
-use warnings;
-
-use Test::More tests => 5;
-use Test::MockModule;
-use MARC::Record;
-
-BEGIN {
-        use_ok('C4::AuthoritiesMarc');
-}
-
-# We are now going to be testing the authorities hierarchy code, and
-# therefore need to pretend that we have consistent data in our database
-my $module = new Test::MockModule('C4::AuthoritiesMarc');
-$module->mock('GetHeaderAuthority', sub {
-    return {'authtrees' => ''};
-});
-$module->mock('AddAuthorityTrees', sub {
-    return;
-});
-$module->mock('GetAuthority', sub {
-    my ($authid) = @_;
-    my $record = MARC::Record->new();
-    if ($authid eq '1') {
-        $record->add_fields(
-            [ '001', '1' ],
-            [ '151', ' ', ' ', a => 'United States' ]
-            );
-    } elsif ($authid eq '2') {
-        $record->add_fields(
-            [ '001', '2' ],
-            [ '151', ' ', ' ', a => 'New York (State)' ],
-            [ '551', ' ', ' ', a => 'United States', w => 'g', 9 => '1' ]
-            );
-    } elsif ($authid eq '3') {
-        $record->add_fields(
-            [ '001', '3' ],
-            [ '151', ' ', ' ', a => 'New York (City)' ],
-            [ '551', ' ', ' ', a => 'New York (State)', w => 'g', 9 => '2' ]
-            );
-    } elsif ($authid eq '4') {
-        $record->add_fields(
-            [ '001', '4' ],
-            [ '151', ' ', ' ', a => 'New York (City)' ],
-            [ '551', ' ', ' ', a => 'New York (State)', w => 'g' ]
-            );
-    } else {
-        undef $record;
-    }
-    return $record;
-});
-
-is(BuildAuthHierarchies(3, 1), '1,2,3', "Built linked authtrees hierarchy string");
-
-my $expectedhierarchy = [ [ {
-        'authid' => '1',
-        'value' => 'United States',
-        'class' => 'child0',
-        'children' => [ {
-            'authid' => '2',
-            'value' => 'New York (State)',
-            'class' => 'child1',
-            'children' => [ {
-                'authid' => '3',
-                'current_value' => 1,
-                'value' => 'New York (City)',
-                'class' => 'child2',
-                'children' => [],
-                'parents' => [ {
-                    'authid' => '2',
-                    'value' => 'New York (State)'
-                } ]
-            } ],
-            'parents' => [ {
-                'authid' => '1',
-                'value' => 'United States'
-            } ]
-        } ],
-        'parents' => []
-} ] ];
-
-is_deeply(GenerateHierarchy(3), $expectedhierarchy, "Generated hierarchy data structure for linked hierarchy");
-
-is(BuildAuthHierarchies(4, 1), '4', "Built unlinked authtrees hierarchy string");
-$expectedhierarchy = [ [ {
-    'authid' => '4',
-    'current_value' => 1,
-    'value' => 'New York (City)',
-    'class' => 'child0',
-    'children' => [],
-    'parents' => []
-} ] ];
-is_deeply(GenerateHierarchy(4), $expectedhierarchy, "Generated hierarchy data structure for unlinked hierarchy");
diff --git a/t/SuggestionEngine_ExplodedTerms.t b/t/SuggestionEngine_ExplodedTerms.t
deleted file mode 100755 (executable)
index 52683b2..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use Test::More;
-
-BEGIN {
-        use_ok('Koha::SuggestionEngine');
-}
-
-my $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'ExplodedTerms' ] } );
-is(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
-
-my $result = $suggestor->get_suggestions({search => 'Cookery'});
-
-ok((grep { $_->{'search'} eq 'su-na=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-br=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-rl=Cookery' } @$result), "Suggested correct alternatives for keyword search 'Cookery'");
-
-$result = $suggestor->get_suggestions({search => 'su:Cookery'});
-
-ok((grep { $_->{'search'} eq 'su-na=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-br=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-rl=Cookery' } @$result), "Suggested correct alternatives for subject search 'Cookery'");
-
-$result = $suggestor->get_suggestions({search => 'nt:Cookery'});
-
-is(scalar @$result, 0, "No suggestions for fielded search");
-
-$result = $suggestor->get_suggestions({search => 'ccl=su:Cookery'});
-
-is(scalar @$result, 0, "No suggestions for CCL search");
-
-done_testing();
diff --git a/t/db_dependent/AuthoritiesMarc.t b/t/db_dependent/AuthoritiesMarc.t
new file mode 100755 (executable)
index 0000000..9c8c1fd
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+#
+# This Koha test module is a stub!  
+# Add more tests here!!!
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Test::MockModule;
+use MARC::Record;
+
+BEGIN {
+        use_ok('C4::AuthoritiesMarc');
+}
+
+# We are now going to be testing the authorities hierarchy code, and
+# therefore need to pretend that we have consistent data in our database
+my $module = new Test::MockModule('C4::AuthoritiesMarc');
+$module->mock('GetHeaderAuthority', sub {
+    return {'authtrees' => ''};
+});
+$module->mock('AddAuthorityTrees', sub {
+    return;
+});
+$module->mock('GetAuthority', sub {
+    my ($authid) = @_;
+    my $record = MARC::Record->new();
+    if ($authid eq '1') {
+        $record->add_fields(
+            [ '001', '1' ],
+            [ '151', ' ', ' ', a => 'United States' ]
+            );
+    } elsif ($authid eq '2') {
+        $record->add_fields(
+            [ '001', '2' ],
+            [ '151', ' ', ' ', a => 'New York (State)' ],
+            [ '551', ' ', ' ', a => 'United States', w => 'g', 9 => '1' ]
+            );
+    } elsif ($authid eq '3') {
+        $record->add_fields(
+            [ '001', '3' ],
+            [ '151', ' ', ' ', a => 'New York (City)' ],
+            [ '551', ' ', ' ', a => 'New York (State)', w => 'g', 9 => '2' ]
+            );
+    } elsif ($authid eq '4') {
+        $record->add_fields(
+            [ '001', '4' ],
+            [ '151', ' ', ' ', a => 'New York (City)' ],
+            [ '551', ' ', ' ', a => 'New York (State)', w => 'g' ]
+            );
+    } else {
+        undef $record;
+    }
+    return $record;
+});
+
+is(BuildAuthHierarchies(3, 1), '1,2,3', "Built linked authtrees hierarchy string");
+
+my $expectedhierarchy = [ [ {
+        'authid' => '1',
+        'value' => 'United States',
+        'class' => 'child0',
+        'children' => [ {
+            'authid' => '2',
+            'value' => 'New York (State)',
+            'class' => 'child1',
+            'children' => [ {
+                'authid' => '3',
+                'current_value' => 1,
+                'value' => 'New York (City)',
+                'class' => 'child2',
+                'children' => [],
+                'parents' => [ {
+                    'authid' => '2',
+                    'value' => 'New York (State)'
+                } ]
+            } ],
+            'parents' => [ {
+                'authid' => '1',
+                'value' => 'United States'
+            } ]
+        } ],
+        'parents' => []
+} ] ];
+
+is_deeply(GenerateHierarchy(3), $expectedhierarchy, "Generated hierarchy data structure for linked hierarchy");
+
+is(BuildAuthHierarchies(4, 1), '4', "Built unlinked authtrees hierarchy string");
+$expectedhierarchy = [ [ {
+    'authid' => '4',
+    'current_value' => 1,
+    'value' => 'New York (City)',
+    'class' => 'child0',
+    'children' => [],
+    'parents' => []
+} ] ];
+is_deeply(GenerateHierarchy(4), $expectedhierarchy, "Generated hierarchy data structure for unlinked hierarchy");
diff --git a/t/db_dependent/SuggestionEngine_ExplodedTerms.t b/t/db_dependent/SuggestionEngine_ExplodedTerms.t
new file mode 100755 (executable)
index 0000000..52683b2
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+BEGIN {
+        use_ok('Koha::SuggestionEngine');
+}
+
+my $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'ExplodedTerms' ] } );
+is(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
+
+my $result = $suggestor->get_suggestions({search => 'Cookery'});
+
+ok((grep { $_->{'search'} eq 'su-na=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-br=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-rl=Cookery' } @$result), "Suggested correct alternatives for keyword search 'Cookery'");
+
+$result = $suggestor->get_suggestions({search => 'su:Cookery'});
+
+ok((grep { $_->{'search'} eq 'su-na=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-br=Cookery' } @$result) && (grep { $_->{'search'} eq 'su-rl=Cookery' } @$result), "Suggested correct alternatives for subject search 'Cookery'");
+
+$result = $suggestor->get_suggestions({search => 'nt:Cookery'});
+
+is(scalar @$result, 0, "No suggestions for fielded search");
+
+$result = $suggestor->get_suggestions({search => 'ccl=su:Cookery'});
+
+is(scalar @$result, 0, "No suggestions for CCL search");
+
+done_testing();