View | Details | Raw Unified | Return to bug 11912
Collapse All | Expand All

(-)a/t/db_dependent/Biblio.t (-19 / +4 lines)
Lines 21-26 use Test::More tests => 3; Link Here
21
use Test::MockModule;
21
use Test::MockModule;
22
22
23
use MARC::Record;
23
use MARC::Record;
24
use t::lib::Mocks qw( mock_preference );
24
25
25
BEGIN {
26
BEGIN {
26
    use_ok('C4::Biblio');
27
    use_ok('C4::Biblio');
Lines 31-42 my $dbh = C4::Context->dbh; Link Here
31
$dbh->{AutoCommit} = 0;
32
$dbh->{AutoCommit} = 0;
32
$dbh->{RaiseError} = 1;
33
$dbh->{RaiseError} = 1;
33
34
34
my $global_marcflavour;
35
# Mocking variables
35
# Mocking variables
36
my $original_preference = C4::Context->can( 'preference' );
36
my $original_preference = C4::Context->can( 'preference' );
37
my $context             = new Test::MockModule('C4::Context');
37
my $context             = new Test::MockModule('C4::Context');
38
38
39
mock_preference();
40
mock_marcfromkohafield();
39
mock_marcfromkohafield();
41
40
42
sub run_tests {
41
sub run_tests {
Lines 46-52 sub run_tests { Link Here
46
    undef $C4::Biblio::inverted_field_map;
45
    undef $C4::Biblio::inverted_field_map;
47
46
48
    my $marcflavour = shift;
47
    my $marcflavour = shift;
49
    $global_marcflavour = $marcflavour;
48
    t::lib::Mocks::mock_preference('marcflavour', $marcflavour);
50
49
51
    my $isbn = '0590353403';
50
    my $isbn = '0590353403';
52
    my $title = 'Foundation';
51
    my $title = 'Foundation';
Lines 183-208 sub run_tests { Link Here
183
182
184
}
183
}
185
184
186
sub mock_preference {
187
188
    $context->mock( 'preference', sub {
189
        my ( $self, $pref ) = @_;
190
        if ( $pref eq 'marcflavour' ) {
191
            return $global_marcflavour;
192
        } else {
193
            &$original_preference(@_);
194
        }
195
    });
196
197
}
198
199
sub mock_marcfromkohafield {
185
sub mock_marcfromkohafield {
200
186
201
    $context->mock('marcfromkohafield',
187
    $context->mock('marcfromkohafield',
202
        sub {
188
        sub {
203
            my ( $self ) = shift;
189
            my ( $self ) = shift;
204
190
205
            if ( $global_marcflavour eq 'MARC21' ) {
191
            if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {
206
192
207
                return  {
193
                return  {
208
                '' => {
194
                '' => {
Lines 213-219 sub mock_marcfromkohafield { Link Here
213
                    'biblioitems.biblioitemnumber' => [ '999', 'd' ]
199
                    'biblioitems.biblioitemnumber' => [ '999', 'd' ]
214
                    }
200
                    }
215
                };
201
                };
216
            } elsif ( $global_marcflavour eq 'UNIMARC' ) {
202
            } elsif ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
217
203
218
                return {
204
                return {
219
                '' => {
205
                '' => {
220
- 

Return to bug 11912