Bug 16849: Move IsDebarred to Koha::Patron->is_debarred
[koha.git] / t / Matcher.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More;
21 use Test::MockModule;
22
23 use Module::Load::Conditional qw/check_install/;
24
25 BEGIN {
26     if ( check_install( module => 'Test::DBIx::Class' ) ) {
27         plan tests => 11;
28     } else {
29         plan skip_all => "Need Test::DBIx::Class"
30     }
31 }
32
33 use_ok('C4::Matcher');
34
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' ;
41
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 ]
47     ],
48 ], 'add fixtures';
49
50 my $db = Test::MockModule->new('Koha::Database');
51 $db->mock( _new_schema => sub { return Schema(); } );
52
53 my @matchers = C4::Matcher::GetMatcherList();
54
55 is( $matchers[0]->{'matcher_id'}, 1, 'First matcher_id value is 1' );
56
57 is( $matchers[1]->{'matcher_id'}, 2, 'Second matcher_id value is 2' );
58
59 my $matcher_id = C4::Matcher::GetMatcherId('ISBN');
60
61 is( $matcher_id, 1, 'testing getmatcherid' );
62
63 my $testmatcher;
64
65 ok( $testmatcher = C4::Matcher->new( 'red', 1 ), 'testing matcher new' );
66
67 ok( $testmatcher = C4::Matcher->new( 'blue', 0 ), 'testing matcher new' );
68
69 $testmatcher->threshold(1000);
70
71 is( $testmatcher->threshold(), 1000, 'testing threshhold accessor method' );
72
73 $testmatcher->_id(53);
74
75 is( $testmatcher->_id(), 53, 'testing _id accessor' );
76
77 $testmatcher->code('match on ISBN');
78
79 is( $testmatcher->code(), 'match on ISBN', 'testing code accessor' );
80
81 $testmatcher->description('match on ISSN');
82
83 is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' );
84
85 1;