Lines 4-33
Link Here
|
4 |
|
4 |
|
5 |
use strict; |
5 |
use strict; |
6 |
use warnings; |
6 |
use warnings; |
7 |
use Test::More tests => 10; |
7 |
use Test::More tests => 11; |
8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
9 |
|
9 |
|
10 |
BEGIN { |
10 |
BEGIN { |
11 |
use_ok('C4::Matcher'); |
11 |
use_ok('C4::Matcher'); |
12 |
} |
12 |
} |
13 |
|
13 |
|
14 |
my $module = new Test::MockModule('C4::Context'); |
14 |
use Test::DBIx::Class { |
15 |
$module->mock( |
15 |
schema_class => 'Koha::Schema', |
16 |
'_new_dbh', |
16 |
connect_info => ['dbi:SQLite:dbname=:memory:','',''], |
17 |
sub { |
17 |
connect_opts => { name_sep => '.', quote_char => '`', }, |
18 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
18 |
fixture_class => '::Populate', |
19 |
|| die "Cannot create handle: $DBI::errstr\n"; |
19 |
}, 'MarcMatcher' ; |
20 |
return $dbh; |
20 |
|
21 |
} |
21 |
fixtures_ok [ |
22 |
); |
22 |
MarcMatcher => [ |
23 |
my $matcher = [ |
23 |
[ 'matcher_id', 'code', 'description', 'record_type', 'threshold' ], |
24 |
[ 'matcher_id', 'code', 'description', 'record_type', 'threshold' ], |
24 |
[ 1, 'ISBN', 'ISBN', 'red', 1 ], |
25 |
[ 1, 'ISBN', 'ISBN', 'red', 1 ], |
25 |
[ 2, 'ISSN', 'ISSN', 'blue', 0 ] |
26 |
[ 2, 'ISSN', 'ISSN', 'blue', 0 ] |
26 |
], |
27 |
]; |
27 |
], 'add fixtures'; |
28 |
my $dbh = C4::Context->dbh(); |
28 |
|
29 |
|
29 |
my $db = Test::MockModule->new('Koha::Database'); |
30 |
$dbh->{mock_add_resultset} = $matcher; |
30 |
$db->mock( _new_schema => sub { return Schema(); } ); |
31 |
|
31 |
|
32 |
my @matchers = C4::Matcher::GetMatcherList(); |
32 |
my @matchers = C4::Matcher::GetMatcherList(); |
33 |
|
33 |
|
Lines 35-42
is( $matchers[0]->{'matcher_id'}, 1, 'First matcher_id value is 1' );
Link Here
|
35 |
|
35 |
|
36 |
is( $matchers[1]->{'matcher_id'}, 2, 'Second matcher_id value is 2' ); |
36 |
is( $matchers[1]->{'matcher_id'}, 2, 'Second matcher_id value is 2' ); |
37 |
|
37 |
|
38 |
$dbh->{mock_add_resultset} = $matcher; |
|
|
39 |
|
40 |
my $matcher_id = C4::Matcher::GetMatcherId('ISBN'); |
38 |
my $matcher_id = C4::Matcher::GetMatcherId('ISBN'); |
41 |
|
39 |
|
42 |
is( $matcher_id, 1, 'testing getmatcherid' ); |
40 |
is( $matcher_id, 1, 'testing getmatcherid' ); |
43 |
- |
|
|