Lines 34-49
BEGIN {
Link Here
|
34 |
|
34 |
|
35 |
# Mock the call to create a database handler |
35 |
# Mock the call to create a database handler |
36 |
my $module = new Test::MockModule('C4::Context'); |
36 |
my $module = new Test::MockModule('C4::Context'); |
37 |
$module->mock('_new_dbh', sub { |
37 |
$module->mock( |
38 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
38 |
'_new_dbh', |
39 |
|| die "Cannot create handle: $DBI::errstr\n"; |
39 |
sub { |
40 |
return $dbh |
40 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
41 |
}); |
41 |
|| die "Cannot create handle: $DBI::errstr\n"; |
42 |
$module->mock('preference', sub { |
42 |
return $dbh; |
43 |
return 'MARC21' if (pop @_ eq 'marcflavour'); |
43 |
} |
44 |
return 0; |
44 |
); |
45 |
}); |
45 |
$module->mock( |
46 |
|
46 |
'preference', |
|
|
47 |
sub { |
48 |
return 'MARC21' if ( pop @_ eq 'marcflavour' ); |
49 |
return 0; |
50 |
} |
51 |
); |
47 |
|
52 |
|
48 |
# Mock data |
53 |
# Mock data |
49 |
my $auth = MARC::Record->new; |
54 |
my $auth = MARC::Record->new; |
Lines 53-121
$auth->add_fields(
Link Here
|
53 |
[ '450', ' ', ' ', a => 'Cookery' ], |
58 |
[ '450', ' ', ' ', a => 'Cookery' ], |
54 |
); |
59 |
); |
55 |
|
60 |
|
56 |
my $mockauthority = [ |
61 |
my $mockauthority = |
57 |
['authtypecode','marcxml'], |
62 |
[ [ 'authtypecode', 'marcxml' ], [ 'TOPIC', $auth->as_xml_record() ], ]; |
58 |
['TOPIC', $auth->as_xml_record() ], |
|
|
59 |
]; |
60 |
|
63 |
|
61 |
my $dbh = C4::Context->dbh(); # since we mocked _new_dbh we get a mock handle |
64 |
my $dbh = C4::Context->dbh(); # since we mocked _new_dbh we get a mock handle |
62 |
|
65 |
|
63 |
my $bib = MARC::Record->new; |
66 |
my $bib = MARC::Record->new; |
64 |
$bib->add_fields( |
67 |
$bib->add_fields( |
65 |
[ '245', '0', '4', a => 'The Ifrane cookbook' ], |
68 |
[ '245', '0', '4', a => 'The Ifrane cookbook' ], |
66 |
[ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ] |
69 |
[ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ] |
67 |
); |
70 |
); |
68 |
|
71 |
|
69 |
my $resultbib = MARC::Record->new; |
72 |
my $resultbib = MARC::Record->new; |
70 |
$resultbib->add_fields( |
73 |
$resultbib->add_fields( |
71 |
[ '245', '0', '4', a => 'The Ifrane cookbook' ], |
74 |
[ '245', '0', '4', a => 'The Ifrane cookbook' ], |
72 |
[ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ], |
75 |
[ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ], |
73 |
[ '650', 'z', ' ', a => 'Cookery' ] |
76 |
[ '650', 'z', ' ', a => 'Cookery' ] |
74 |
); |
77 |
); |
75 |
|
78 |
|
76 |
my $processor = Koha::RecordProcessor->new( { filters => ( 'EmbedSeeFromHeadings' ) } ); |
79 |
my $processor = |
77 |
is(ref($processor), 'Koha::RecordProcessor', 'Created record processor'); |
80 |
Koha::RecordProcessor->new( { filters => ('EmbedSeeFromHeadings') } ); |
78 |
is(ref($processor->filters->[0]), 'Koha::Filter::MARC::EmbedSeeFromHeadings', 'Loaded EmbedSeeFromHeadings filter'); |
81 |
is( ref($processor), 'Koha::RecordProcessor', 'Created record processor' ); |
|
|
82 |
is( |
83 |
ref( $processor->filters->[0] ), |
84 |
'Koha::Filter::MARC::EmbedSeeFromHeadings', |
85 |
'Loaded EmbedSeeFromHeadings filter' |
86 |
); |
79 |
|
87 |
|
80 |
$dbh->{mock_add_resultset} = $mockauthority; |
88 |
$dbh->{mock_add_resultset} = $mockauthority; |
81 |
|
89 |
|
82 |
my $result = $processor->process(undef); |
90 |
my $result = $processor->process(undef); |
83 |
|
91 |
|
84 |
is($result, undef, "Don't flip out when asked to process nothing"); |
92 |
is( $result, undef, "Don't flip out when asked to process nothing" ); |
85 |
|
93 |
|
86 |
$result = $processor->process($bib); |
94 |
$result = $processor->process($bib); |
87 |
|
95 |
|
88 |
my $history = $dbh->{mock_all_history}; |
96 |
my $history = $dbh->{mock_all_history}; |
89 |
is(scalar(@{$history}), 1, 'Correct number of statements executed') ; |
97 |
is( scalar( @{$history} ), 1, 'Correct number of statements executed' ); |
90 |
$dbh->{mock_clear_history} = 1; |
98 |
$dbh->{mock_clear_history} = 1; |
91 |
|
99 |
|
92 |
is_deeply($result, $resultbib, 'Inserted see-from heading to record'); |
100 |
is_deeply( $result, $resultbib, 'Inserted see-from heading to record' ); |
93 |
|
101 |
|
94 |
my @bibs; |
102 |
my @bibs; |
95 |
$bib = MARC::Record->new; |
103 |
$bib = MARC::Record->new; |
96 |
$bib->add_fields( |
104 |
$bib->add_fields( |
97 |
[ '245', '0', '4', a => 'The Ifrane cookbook' ], |
105 |
[ '245', '0', '4', a => 'The Ifrane cookbook' ], |
98 |
[ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ] |
106 |
[ '650', ' ', ' ', a => 'Cooking', 9 => '1234' ] |
99 |
); |
107 |
); |
100 |
push @bibs, $bib; |
108 |
push @bibs, $bib; |
101 |
$bib = MARC::Record->new; |
109 |
$bib = MARC::Record->new; |
102 |
$bib->add_fields( |
110 |
$bib->add_fields( |
103 |
[ '245', '0', '2', a => 'A story of great tragedy, and fish' ], |
111 |
[ '245', '0', '2', a => 'A story of great tragedy, and fish' ], |
104 |
[ '650', ' ', ' ', a => 'Fish', 9 => '5432' ] |
112 |
[ '650', ' ', ' ', a => 'Fish', 9 => '5432' ] ); |
105 |
); |
|
|
106 |
push @bibs, $bib; |
113 |
push @bibs, $bib; |
107 |
my @resultbibs; |
114 |
my @resultbibs; |
108 |
push @resultbibs, $resultbib; |
115 |
push @resultbibs, $resultbib; |
109 |
push @resultbibs, $bib; |
116 |
push @resultbibs, $bib; |
110 |
|
117 |
|
111 |
|
|
|
112 |
$dbh->{mock_add_resultset} = $mockauthority; |
118 |
$dbh->{mock_add_resultset} = $mockauthority; |
113 |
|
119 |
|
114 |
$result = $processor->process(\@bibs); |
120 |
$result = $processor->process( \@bibs ); |
115 |
|
121 |
|
116 |
is(scalar(@$result), 2, 'Processed two records'); |
122 |
is( scalar(@$result), 2, 'Processed two records' ); |
117 |
|
123 |
|
118 |
$history = $dbh->{mock_all_history}; |
124 |
$history = $dbh->{mock_all_history}; |
119 |
is(scalar(@{$history}), 2, 'Correct number of statements executed'); |
125 |
is( scalar( @{$history} ), 2, 'Correct number of statements executed' ); |
120 |
|
126 |
|
121 |
is_deeply($result, \@resultbibs, 'Handled both records correctly'); |
127 |
is_deeply( $result, \@resultbibs, 'Handled both records correctly' ); |