Lines 1-14
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
# |
2 |
# |
3 |
# This Koha test module is a stub! |
3 |
#testing C4 matcher |
4 |
# Add more tests here!!! |
|
|
5 |
|
4 |
|
6 |
use strict; |
5 |
use strict; |
7 |
use warnings; |
6 |
use warnings; |
|
|
7 |
use Test::More tests => 10; |
8 |
use Test::MockModule; |
9 |
|
8 |
|
10 |
|
9 |
use Test::More tests => 1; |
|
|
10 |
|
11 |
|
11 |
BEGIN { |
12 |
BEGIN { |
12 |
use_ok('C4::Matcher'); |
13 |
use_ok('C4::Matcher'); |
13 |
} |
14 |
} |
14 |
|
15 |
|
15 |
- |
16 |
my $module = new Test::MockModule('C4::Context'); |
|
|
17 |
$module->mock('_new_dbh', sub { |
18 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
19 |
|| die "Cannot create handle: $DBI::errstr\n"; |
20 |
return $dbh }); |
21 |
my $matcher = [ |
22 |
['matcher_id','code','description','record_type','threshold'], |
23 |
[1,'ISBN','ISBN','red',1], |
24 |
[2,'ISSN','ISSN','blue',0] |
25 |
]; |
26 |
my $dbh = C4::Context->dbh(); |
27 |
|
28 |
$dbh->{mock_add_resultset} = $matcher; |
29 |
|
30 |
my @matchers = C4::Matcher::GetMatcherList(); |
31 |
|
32 |
is($matchers[0]->{'matcher_id'},1, 'First matcher_id value is 1'); |
33 |
|
34 |
is($matchers[1]->{'matcher_id'},2, 'Second matcher_id value is 2'); |
35 |
|
36 |
$dbh->{mock_add_resultset} = $matcher; |
37 |
|
38 |
my $matcher_id = C4::Matcher::GetMatcherId('ISBN'); |
39 |
|
40 |
is($matcher_id,1,'testing getmatcherid'); |
41 |
|
42 |
my $testmatcher; |
43 |
|
44 |
ok($testmatcher = C4::Matcher->new('red', 1), 'testing matcher new'); |
45 |
|
46 |
ok($testmatcher = C4::Matcher->new('blue', 0), 'testing matcher new'); |
47 |
|
48 |
$testmatcher->threshold(1000); |
49 |
|
50 |
is($testmatcher->threshold(),1000, 'testing threshhold accessor method'); |
51 |
|
52 |
$testmatcher->_id(53); |
53 |
|
54 |
is($testmatcher->_id(),53, 'testing _id accessor'); |
55 |
|
56 |
$testmatcher->code('match on ISBN'); |
57 |
|
58 |
is($testmatcher->code(),'match on ISBN', 'testing code accessor'); |
59 |
|
60 |
$testmatcher->description('match on ISSN'); |
61 |
|
62 |
is($testmatcher->description(),'match on ISSN', 'testing code accessor'); |