Bug 16163: Show message if there are no dictionary definitions
[koha.git] / t / Matcher.t
blob652f061f2938eae7f3796316f2aa3ac98738e8c0
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use Test::More;
21 use Test::MockModule;
23 use Module::Load::Conditional qw/check_install/;
25 BEGIN {
26 if ( check_install( module => 'Test::DBIx::Class' ) ) {
27 plan tests => 11;
28 } else {
29 plan skip_all => "Need Test::DBIx::Class"
33 use_ok('C4::Matcher');
35 use Test::DBIx::Class {
36 schema_class => 'Koha::Schema',
37 connect_info => ['dbi:SQLite:dbname=:memory:','',''],
38 connect_opts => { name_sep => '.', quote_char => '`', },
39 fixture_class => '::Populate',
40 }, 'MarcMatcher' ;
42 fixtures_ok [
43 MarcMatcher => [
44 [ 'matcher_id', 'code', 'description', 'record_type', 'threshold' ],
45 [ 1, 'ISBN', 'ISBN', 'red', 1 ],
46 [ 2, 'ISSN', 'ISSN', 'blue', 0 ]
48 ], 'add fixtures';
50 my $db = Test::MockModule->new('Koha::Database');
51 $db->mock( _new_schema => sub { return Schema(); } );
53 my @matchers = C4::Matcher::GetMatcherList();
55 is( $matchers[0]->{'matcher_id'}, 1, 'First matcher_id value is 1' );
57 is( $matchers[1]->{'matcher_id'}, 2, 'Second matcher_id value is 2' );
59 my $matcher_id = C4::Matcher::GetMatcherId('ISBN');
61 is( $matcher_id, 1, 'testing getmatcherid' );
63 my $testmatcher;
65 ok( $testmatcher = C4::Matcher->new( 'red', 1 ), 'testing matcher new' );
67 ok( $testmatcher = C4::Matcher->new( 'blue', 0 ), 'testing matcher new' );
69 $testmatcher->threshold(1000);
71 is( $testmatcher->threshold(), 1000, 'testing threshhold accessor method' );
73 $testmatcher->_id(53);
75 is( $testmatcher->_id(), 53, 'testing _id accessor' );
77 $testmatcher->code('match on ISBN');
79 is( $testmatcher->code(), 'match on ISBN', 'testing code accessor' );
81 $testmatcher->description('match on ISSN');
83 is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' );