Bug 5327 Tests for C4::Matcher
authorBart Jorgensen <bart.tj@gmail.com>
Thu, 2 Aug 2012 04:56:58 +0000 (16:56 +1200)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 7 Sep 2012 12:31:52 +0000 (14:31 +0200)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
t/Matcher.t

index f374877..484afe0 100755 (executable)
@@ -1,14 +1,64 @@
 #!/usr/bin/perl
 #
-# This Koha test module is a stub!  
-# Add more tests here!!!
+#testing C4 matcher
 
 use strict;
 use warnings;
-
-use Test::More tests => 1;
+use Test::More tests => 10;
+use Test::MockModule;
 
 BEGIN {
-        use_ok('C4::Matcher');
+    use_ok('C4::Matcher');
 }
 
+my $module = new Test::MockModule('C4::Context');
+$module->mock(
+    '_new_dbh',
+    sub {
+        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
+          || die "Cannot create handle: $DBI::errstr\n";
+        return $dbh;
+    }
+);
+my $matcher = [
+    [ 'matcher_id', 'code', 'description', 'record_type', 'threshold' ],
+    [ 1,            'ISBN', 'ISBN',        'red',         1 ],
+    [ 2,            'ISSN', 'ISSN',        'blue',        0 ]
+];
+my $dbh = C4::Context->dbh();
+
+$dbh->{mock_add_resultset} = $matcher;
+
+my @matchers = C4::Matcher::GetMatcherList();
+
+is( $matchers[0]->{'matcher_id'}, 1, 'First matcher_id value is 1' );
+
+is( $matchers[1]->{'matcher_id'}, 2, 'Second matcher_id value is 2' );
+
+$dbh->{mock_add_resultset} = $matcher;
+
+my $matcher_id = C4::Matcher::GetMatcherId('ISBN');
+
+is( $matcher_id, 1, 'testing getmatcherid' );
+
+my $testmatcher;
+
+ok( $testmatcher = C4::Matcher->new( 'red', 1 ), 'testing matcher new' );
+
+ok( $testmatcher = C4::Matcher->new( 'blue', 0 ), 'testing matcher new' );
+
+$testmatcher->threshold(1000);
+
+is( $testmatcher->threshold(), 1000, 'testing threshhold accessor method' );
+
+$testmatcher->_id(53);
+
+is( $testmatcher->_id(), 53, 'testing _id accessor' );
+
+$testmatcher->code('match on ISBN');
+
+is( $testmatcher->code(), 'match on ISBN', 'testing code accessor' );
+
+$testmatcher->description('match on ISSN');
+
+is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' );