From 4f173f17e716ae50393c0019e59d61b4592e2bbd Mon Sep 17 00:00:00 2001 From: Bart Jorgensen Date: Thu, 2 Aug 2012 16:56:58 +1200 Subject: [PATCH] [SIGNED-OFF] Bug 5327 Tests for C4::Matcher Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- t/Matcher.t | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/t/Matcher.t b/t/Matcher.t index f374877..c0caf50 100755 --- a/t/Matcher.t +++ b/t/Matcher.t @@ -1,14 +1,62 @@ #!/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 => 10; +use Test::MockModule; + -use Test::More tests => 1; BEGIN { 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'); -- 1.7.9.5