Revert "Update release notes for 3.18.09 release"
[koha.git] / t / Matcher.t
blob484afe0473b76d7608804d201c93e3728edcdf51
1 #!/usr/bin/perl
3 #testing C4 matcher
5 use strict;
6 use warnings;
7 use Test::More tests => 10;
8 use Test::MockModule;
10 BEGIN {
11 use_ok('C4::Matcher');
14 my $module = new Test::MockModule('C4::Context');
15 $module->mock(
16 '_new_dbh',
17 sub {
18 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19 || die "Cannot create handle: $DBI::errstr\n";
20 return $dbh;
23 my $matcher = [
24 [ 'matcher_id', 'code', 'description', 'record_type', 'threshold' ],
25 [ 1, 'ISBN', 'ISBN', 'red', 1 ],
26 [ 2, 'ISSN', 'ISSN', 'blue', 0 ]
28 my $dbh = C4::Context->dbh();
30 $dbh->{mock_add_resultset} = $matcher;
32 my @matchers = C4::Matcher::GetMatcherList();
34 is( $matchers[0]->{'matcher_id'}, 1, 'First matcher_id value is 1' );
36 is( $matchers[1]->{'matcher_id'}, 2, 'Second matcher_id value is 2' );
38 $dbh->{mock_add_resultset} = $matcher;
40 my $matcher_id = C4::Matcher::GetMatcherId('ISBN');
42 is( $matcher_id, 1, 'testing getmatcherid' );
44 my $testmatcher;
46 ok( $testmatcher = C4::Matcher->new( 'red', 1 ), 'testing matcher new' );
48 ok( $testmatcher = C4::Matcher->new( 'blue', 0 ), 'testing matcher new' );
50 $testmatcher->threshold(1000);
52 is( $testmatcher->threshold(), 1000, 'testing threshhold accessor method' );
54 $testmatcher->_id(53);
56 is( $testmatcher->_id(), 53, 'testing _id accessor' );
58 $testmatcher->code('match on ISBN');
60 is( $testmatcher->code(), 'match on ISBN', 'testing code accessor' );
62 $testmatcher->description('match on ISSN');
64 is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' );