From b4acf9115521755e1a03a47888137efdca140f27 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Mar 2014 11:14:58 +0100 Subject: [PATCH] Bug 11912: Use the common way to mock syspref t::lib::Mocks::mock_preference provides a simple way to mock syspref. Test plan: Verify that t/db_dependent/Biblio.t returns green. Signed-off-by: Jonathan Druart --- t/db_dependent/Biblio.t | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index b861023..3c0a159 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -21,6 +21,7 @@ use Test::More tests => 3; use Test::MockModule; use MARC::Record; +use t::lib::Mocks qw( mock_preference ); BEGIN { use_ok('C4::Biblio'); @@ -31,12 +32,9 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $global_marcflavour; # Mocking variables -my $original_preference = C4::Context->can( 'preference' ); my $context = new Test::MockModule('C4::Context'); -mock_preference(); mock_marcfromkohafield(); sub run_tests { @@ -46,7 +44,7 @@ sub run_tests { undef $C4::Biblio::inverted_field_map; my $marcflavour = shift; - $global_marcflavour = $marcflavour; + t::lib::Mocks::mock_preference('marcflavour', $marcflavour); my $isbn = '0590353403'; my $title = 'Foundation'; @@ -183,26 +181,13 @@ sub run_tests { } -sub mock_preference { - - $context->mock( 'preference', sub { - my ( $self, $pref ) = @_; - if ( $pref eq 'marcflavour' ) { - return $global_marcflavour; - } else { - &$original_preference(@_); - } - }); - -} - sub mock_marcfromkohafield { $context->mock('marcfromkohafield', sub { my ( $self ) = shift; - if ( $global_marcflavour eq 'MARC21' ) { + if ( C4::Context->preference('marcflavour') eq 'MARC21' ) { return { '' => { @@ -213,7 +198,7 @@ sub mock_marcfromkohafield { 'biblioitems.biblioitemnumber' => [ '999', 'd' ] } }; - } elsif ( $global_marcflavour eq 'UNIMARC' ) { + } elsif ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { return { '' => { -- 1.7.10.4