Lines 28-47
t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ) if $marcflavour;
Link Here
|
28 |
|
28 |
|
29 |
my $schema = Koha::Database->new->schema; |
29 |
my $schema = Koha::Database->new->schema; |
30 |
$schema->storage->txn_begin; |
30 |
$schema->storage->txn_begin; |
31 |
my $dbh = C4::Context->dbh; |
|
|
32 |
|
31 |
|
33 |
# Some advanced mocking :) |
32 |
# Global variables, mocking and framework modifications |
34 |
my ( @zebrarecords, $index ); |
33 |
our ( @zebrarecords, $index ); |
35 |
my $context_mod = Test::MockModule->new( 'C4::Context' ); |
34 |
my $mocks = set_mocks(); |
36 |
my $search_mod = Test::MockModule->new( 'C4::Search' ); |
35 |
our ( $authtype1, $authtype2 ) = modify_framework(); |
37 |
my $zoom_mod = Test::MockModule->new( 'ZOOM::Query::CCL2RPN', no_auto => 1 ); |
|
|
38 |
my $conn_obj = Test::MockObject->new; |
39 |
my $zoom_obj = Test::MockObject->new; |
40 |
my $zoom_record_obj = Test::MockObject->new; |
41 |
set_mocks(); |
42 |
|
43 |
# Framework operations |
44 |
my ( $authtype1, $authtype2 ) = modify_framework(); |
45 |
|
36 |
|
46 |
subtest 'Test merge A1 to A2 (within same authtype)' => sub { |
37 |
subtest 'Test merge A1 to A2 (within same authtype)' => sub { |
47 |
# Tests originate from bug 11700 |
38 |
# Tests originate from bug 11700 |
Lines 229-247
sub set_mocks {
Link Here
|
229 |
# Mock ZOOM objects: They do nothing actually |
220 |
# Mock ZOOM objects: They do nothing actually |
230 |
# Get new_record_from_zebra to return the records |
221 |
# Get new_record_from_zebra to return the records |
231 |
|
222 |
|
232 |
$context_mod->mock( 'Zconn', sub { $conn_obj; } ); |
223 |
my $mocks; |
233 |
$search_mod->mock( 'new_record_from_zebra', sub { |
224 |
$mocks->{context_mod} = Test::MockModule->new( 'C4::Context' ); |
|
|
225 |
$mocks->{search_mod} = Test::MockModule->new( 'C4::Search' ); |
226 |
$mocks->{zoom_mod} = Test::MockModule->new( 'ZOOM::Query::CCL2RPN', no_auto => 1 ); |
227 |
$mocks->{conn_obj} = Test::MockObject->new; |
228 |
$mocks->{zoom_obj} = Test::MockObject->new; |
229 |
$mocks->{zoom_record_obj} = Test::MockObject->new; |
230 |
|
231 |
$mocks->{context_mod}->mock( 'Zconn', sub { $mocks->{conn_obj}; } ); |
232 |
$mocks->{search_mod}->mock( 'new_record_from_zebra', sub { |
234 |
return if $index >= @zebrarecords; |
233 |
return if $index >= @zebrarecords; |
235 |
return $zebrarecords[ $index++ ]; |
234 |
return $zebrarecords[ $index++ ]; |
236 |
}); |
235 |
}); |
237 |
$zoom_mod->mock( 'new', sub {} ); |
236 |
$mocks->{zoom_mod}->mock( 'new', sub {} ); |
238 |
|
237 |
|
239 |
$conn_obj->mock( 'search', sub { $zoom_obj; } ); |
238 |
$mocks->{conn_obj}->mock( 'search', sub { $mocks->{zoom_obj}; } ); |
240 |
$zoom_obj->mock( 'destroy', sub {} ); |
239 |
$mocks->{zoom_obj}->mock( 'destroy', sub {} ); |
241 |
$zoom_obj->mock( 'record', sub { $zoom_record_obj; } ); |
240 |
$mocks->{zoom_obj}->mock( 'record', sub { $mocks->{zoom_record_obj}; } ); |
242 |
$zoom_obj->mock( 'search', sub {} ); |
241 |
$mocks->{zoom_obj}->mock( 'search', sub {} ); |
243 |
$zoom_obj->mock( 'size', sub { @zebrarecords } ); |
242 |
$mocks->{zoom_obj}->mock( 'size', sub { @zebrarecords } ); |
244 |
$zoom_record_obj->mock( 'raw', sub {} ); |
243 |
$mocks->{zoom_record_obj}->mock( 'raw', sub {} ); |
|
|
244 |
|
245 |
return $mocks; |
245 |
} |
246 |
} |
246 |
|
247 |
|
247 |
sub modify_framework { |
248 |
sub modify_framework { |
248 |
- |
|
|