Koha/t/lib/Mocks.pm
Jonathan Druart 9fb827d59d Bug 21015: Remove unecessary 'use Koha::Schema' statements in t/
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2018-11-08 02:18:48 +00:00

43 lines
1,003 B
Perl

package t::lib::Mocks;
use Modern::Perl;
use C4::Context;
use Test::MockModule;
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 %preferences;
sub mock_preference {
my ( $pref, $value ) = @_;
$preferences{lc($pref)} = $value;
my $context = new Test::MockModule('C4::Context');
$context->mock('preference', sub {
my ( $self, $pref ) = @_;
$pref = lc($pref);
if ( exists $preferences{$pref} ) {
return $preferences{$pref}
} else {
my $method = $context->original('preference');
return $method->($self, $pref);
}
});
}
1;