|
Lines 1-23
Link Here
|
| 1 |
package t::lib::Mocks; |
1 |
package t::lib::Mocks; |
| 2 |
|
2 |
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
|
|
4 |
use C4::Context; |
| 4 |
use Test::MockModule; |
5 |
use Test::MockModule; |
| 5 |
use t::lib::Mocks::Context; |
|
|
| 6 |
|
6 |
|
| 7 |
our (@ISA,@EXPORT,@EXPORT_OK); |
7 |
my %configs; |
| 8 |
BEGIN { |
8 |
sub mock_config { |
| 9 |
require Exporter; |
9 |
my $context = new Test::MockModule('C4::Context'); |
| 10 |
@ISA = qw(Exporter); |
10 |
my ( $conf, $value ) = @_; |
| 11 |
push @EXPORT, qw( |
11 |
$configs{$conf} = $value; |
| 12 |
&set_solr |
12 |
$context->mock('config', sub { |
| 13 |
&set_zebra |
13 |
my ( $self, $conf ) = @_; |
| 14 |
); |
14 |
if ( grep /$conf/, keys %configs ) { |
|
|
15 |
return $configs{$conf} |
| 16 |
} else { |
| 17 |
my $method = $context->original('config'); |
| 18 |
return $method->($self, $conf); |
| 19 |
} |
| 20 |
}); |
| 15 |
} |
21 |
} |
| 16 |
|
22 |
|
| 17 |
my $context = new Test::MockModule('C4::Context'); |
23 |
my %preferences; |
| 18 |
sub set_solr { |
24 |
sub mock_preference { |
| 19 |
$context->mock('preference', sub { &t::lib::Mocks::Context::MockPreference( @_, "Solr", $context ) }); |
25 |
my $context = new Test::MockModule('C4::Context'); |
| 20 |
} |
26 |
my ( $pref, $value ) = @_; |
| 21 |
sub set_zebra { |
27 |
$preferences{$pref} = $value; |
| 22 |
$context->mock('preference', sub { &t::lib::Mocks::Context::MockPreference( @_, "Zebra", $context ) }); |
28 |
$context->mock('preference', sub { |
|
|
29 |
my ( $self, $pref ) = @_; |
| 30 |
if ( grep /$pref/, keys %preferences ) { |
| 31 |
return $preferences{$pref} |
| 32 |
} else { |
| 33 |
my $method = $context->original('preference'); |
| 34 |
return $method->($self, $pref); |
| 35 |
} |
| 36 |
}); |
| 23 |
} |
37 |
} |
|
|
38 |
|
| 39 |
1; |