@@ -, +, @@ --- t/lib/Mocks.pm | 46 +++++++++++++++++++++++++++++++--------------- t/lib/Mocks/Context.pm | 13 ------------- 2 files changed, 31 insertions(+), 28 deletions(-) delete mode 100644 t/lib/Mocks/Context.pm --- a/t/lib/Mocks.pm +++ a/t/lib/Mocks.pm @@ -1,23 +1,39 @@ package t::lib::Mocks; use Modern::Perl; +use C4::Context; use Test::MockModule; -use t::lib::Mocks::Context; -our (@ISA,@EXPORT,@EXPORT_OK); -BEGIN { - require Exporter; - @ISA = qw(Exporter); - push @EXPORT, qw( - &set_solr - &set_zebra - ); +my %configs; +sub mock_config { + my $context = new Test::MockModule('C4::Context'); + my ( $conf, $value ) = @_; + $configs{$conf} = $value; + $context->mock('config', sub { + my ( $self, $conf ) = @_; + if ( exists $configs{$conf} ) { + return $configs{$conf} + } else { + my $method = $context->original('config'); + return $method->($self, $conf); + } + }); } -my $context = new Test::MockModule('C4::Context'); -sub set_solr { - $context->mock('preference', sub { &t::lib::Mocks::Context::MockPreference( @_, "Solr", $context ) }); -} -sub set_zebra { - $context->mock('preference', sub { &t::lib::Mocks::Context::MockPreference( @_, "Zebra", $context ) }); +my %preferences; +sub mock_preference { + my $context = new Test::MockModule('C4::Context'); + my ( $pref, $value ) = @_; + $preferences{$pref} = $value; + $context->mock('preference', sub { + my ( $self, $pref ) = @_; + if ( exists $preferences{$pref} ) { + return $preferences{$pref} + } else { + my $method = $context->original('preference'); + return $method->($self, $pref); + } + }); } + +1; --- a/t/lib/Mocks/Context.pm +++ a/t/lib/Mocks/Context.pm @@ -1,13 +0,0 @@ -package t::lib::Mocks::Context; -use t::lib::Mocks::Context; -use C4::Context; - -sub MockPreference { - my ( $self, $syspref, $value, $mock_object ) = @_; - return $value if $syspref eq 'SearchEngine'; - $mock_object->unmock("preference"); - my $r = C4::Context->preference($syspref); - $mock_object->mock('preference', sub { &t::lib::Mocks::Context::MockPreference( @_, $value, $mock_object ) }); - return $r; -} -1; --