Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / t / lib / Mocks.pm
blob46a87cb7992b1748b36535bf654d0df545b574ab
1 package t::lib::Mocks;
3 use Modern::Perl;
4 use C4::Context;
6 use Koha::Schema;
7 use Test::MockModule;
9 my %configs;
10 sub mock_config {
11 my $context = new Test::MockModule('C4::Context');
12 my ( $conf, $value ) = @_;
13 $configs{$conf} = $value;
14 $context->mock('config', sub {
15 my ( $self, $conf ) = @_;
16 if ( exists $configs{$conf} ) {
17 return $configs{$conf}
18 } else {
19 my $method = $context->original('config');
20 return $method->($self, $conf);
22 });
25 my %preferences;
26 sub mock_preference {
27 my ( $pref, $value ) = @_;
29 $preferences{lc($pref)} = $value;
31 my $context = new Test::MockModule('C4::Context');
32 $context->mock('preference', sub {
33 my ( $self, $pref ) = @_;
34 $pref = lc($pref);
35 if ( exists $preferences{$pref} ) {
36 return $preferences{$pref}
37 } else {
38 my $method = $context->original('preference');
39 return $method->($self, $pref);
41 });
44 sub mock_dbh {
45 our $context = new Test::MockModule('Koha::Database');
46 $context->mock( '_new_schema', sub {
47 my $dbh = Koha::Schema->connect( 'DBI:Mock:', '', '' );
48 return $dbh;
49 } );
50 return $context;