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