Koha/t/lib/Mocks.pm
Olli-Antti Kivilahti 617988a7c1 Bug 18226 - Remove "use Test::DBIx::Class" instantiations' dangerous code duplication. Replace mock_dbh 2
Couldn't make the tests pass using Test::DBIx::Class, so reverted to the "usual way" since these tests are
in db_dependent anyway.

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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-06-05 17:52:47 -03:00

44 lines
1,021 B
Perl

package t::lib::Mocks;
use Modern::Perl;
use C4::Context;
use Koha::Schema;
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;