Bug 23091: (QA follow-up) POD fixes
[koha.git] / t / lib / Mocks.pm
blob17d54f1a53218acdea11fd131054e993f9c9bace
1 package t::lib::Mocks;
3 use Modern::Perl;
4 use C4::Context;
6 use Test::MockModule;
8 my %configs;
9 sub mock_config {
10 my $context = Test::MockModule->new('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);
21 });
24 my %preferences;
25 sub mock_preference {
26 my ( $pref, $value ) = @_;
28 $preferences{lc($pref)} = $value;
30 my $context = Test::MockModule->new('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);
40 });
43 sub mock_userenv {
44 my ( $params ) = @_;
46 C4::Context->_new_userenv(42);
48 my $userenv;
49 if ( $params and my $patron = $params->{patron} ) {
50 $userenv = $patron->unblessed;
51 $userenv->{branchcode} = $params->{branchcode} || $patron->library->branchcode;
52 $userenv->{branchname} = $params->{branchname} || $patron->library->branchname;
54 my $usernum = $params->{borrowernumber} || $userenv->{borrowernumber} || 51;
55 my $userid = $params->{userid} || $userenv->{userid} || 'userid4tests';
56 my $cardnumber = $params->{cardnumber} || $userenv->{cardnumber};
57 my $firstname = $params->{firstname} || $userenv->{firstname} || 'firstname';
58 my $surname = $params->{surname} || $userenv->{surname} || 'surname';
59 my $branchcode = $params->{branchcode} || $userenv->{branchcode} || 'Branch4T';
60 my $branchname = $params->{branchname} || $userenv->{branchname};
61 my $flags = $params->{flags} || $userenv->{flags} || 0;
62 my $emailaddress = $params->{emailaddress} || $userenv->{emailaddress};
63 my $desk_id = $params->{desk_id} || $userenv->{desk_id};
64 my $desk_name = $params->{desk_name} || $userenv->{desk_name};
65 my $register_id = $params->{register_id} || $userenv->{register_id};
66 my $register_name = $params->{register_name} || $userenv->{register_name};
67 my ( $shibboleth );
69 C4::Context->set_userenv(
70 $usernum, $userid, $cardnumber, $firstname,
71 $surname, $branchcode, $branchname, $flags,
72 $emailaddress, $shibboleth, $desk_id, $desk_name,
73 $register_id, $register_name