Bug 12647: PQF QueryParser driver and unit tests fixes
[koha.git] / t / lib / Mocks.pm
1 package t::lib::Mocks;
2
3 use Modern::Perl;
4 use C4::Context;
5 use Test::MockModule;
6
7 my %configs;
8 sub mock_config {
9     my $context = new Test::MockModule('C4::Context');
10     my ( $conf, $value ) = @_;
11     $configs{$conf} = $value;
12     $context->mock('config', sub {
13         my ( $self, $conf ) = @_;
14         if ( exists $configs{$conf} ) {
15             return $configs{$conf}
16         } else {
17             my $method = $context->original('config');
18             return $method->($self, $conf);
19         }
20     });
21 }
22
23 my %preferences;
24 sub mock_preference {
25     my $context = new Test::MockModule('C4::Context');
26     my ( $pref, $value ) = @_;
27     $preferences{$pref} = $value;
28     $context->mock('preference', sub {
29         my ( $self, $pref ) = @_;
30         if ( exists $preferences{$pref} ) {
31             return $preferences{$pref}
32         } else {
33             my $method = $context->original('preference');
34             return $method->($self, $pref);
35         }
36     });
37 }
38
39 1;