Bug 19489: Koha::Account::Line->issue method and Unit test
[koha.git] / t / SuggestionEngine_AuthorityFile.t
index 9ffe8f7..eab5fb6 100755 (executable)
@@ -26,15 +26,22 @@ use MARC::Record;
 
 use Test::More;
 use Test::MockModule;
-use DBD::Mock;
+use t::lib::Mocks;
 
-# Mock the DB connexion and C4::Context
-my $context = new Test::MockModule('C4::Context');
-$context->mock( '_new_dbh', sub {
-        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
-          || die "Cannot create handle: $DBI::errstr\n";
-        return $dbh;
-});
+use Module::Load::Conditional qw/check_install/;
+
+BEGIN {
+    if ( check_install( module => 'Test::DBIx::Class' ) ) {
+        plan tests => 3;
+    } else {
+        plan skip_all => "Need Test::DBIx::Class"
+    }
+}
+
+# Mock the DB connexion
+use Test::DBIx::Class;
+my $db = Test::MockModule->new('Koha::Database');
+$db->mock( _new_schema => sub { return Schema(); } );
 
 use_ok('Koha::SuggestionEngine');
 
@@ -60,8 +67,7 @@ is(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
 
 my $result = $suggestor->get_suggestions({search => 'Cookery'});
 
-is_deeply($result, [ { 'search' => 'an=1234', 'relevance' => 1, 'label' => 'Cooking' } ], "Suggested correct alternative to 'Cookery'");
+is_deeply($result, [ { 'search' => 'an:1234', 'relevance' => 1, 'label' => 'Cooking' } ], "Suggested correct alternative to 'Cookery'");
 
 done_testing();
 
-1;