Koha/t/Matcher.t
Bart Jorgensen 118754c653 Bug 5327 Tests for C4::Matcher
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
2012-09-07 14:31:52 +02:00

64 lines
1.6 KiB
Perl
Executable file

#!/usr/bin/perl
#
#testing C4 matcher
use strict;
use warnings;
use Test::More tests => 10;
use Test::MockModule;
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' );