|
Lines 1-11
Link Here
|
| 1 |
package t::lib::Mocks; |
1 |
package t::lib::Mocks; |
| 2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 4 |
use C4::Context; |
19 |
use C4::Context; |
| 5 |
|
20 |
|
| 6 |
use Test::MockModule; |
21 |
use Test::MockModule; |
|
|
22 |
use Test::MockObject; |
| 23 |
|
| 24 |
=head1 NAME |
| 25 |
|
| 26 |
t::lib::Mocks - A library to mock things for testing |
| 27 |
|
| 28 |
=head1 API |
| 29 |
|
| 30 |
=head2 Methods |
| 31 |
|
| 32 |
=cut |
| 7 |
|
33 |
|
| 8 |
my %configs; |
34 |
my %configs; |
|
|
35 |
|
| 36 |
=head3 mock_config |
| 37 |
|
| 38 |
t::lib::Mocks::mock_config( $config_entry, $value ); |
| 39 |
|
| 40 |
Mock the configuration I<$config_entry> with the specified I<$value>. |
| 41 |
|
| 42 |
=cut |
| 43 |
|
| 9 |
sub mock_config { |
44 |
sub mock_config { |
| 10 |
my $context = Test::MockModule->new('C4::Context'); |
45 |
my $context = Test::MockModule->new('C4::Context'); |
| 11 |
my ( $conf, $value ) = @_; |
46 |
my ( $conf, $value ) = @_; |
|
Lines 22-27
sub mock_config {
Link Here
|
| 22 |
} |
57 |
} |
| 23 |
|
58 |
|
| 24 |
my %preferences; |
59 |
my %preferences; |
|
|
60 |
|
| 61 |
=head3 mock_preference |
| 62 |
|
| 63 |
t::lib::Mocks::mock_preference( $preference, $value ); |
| 64 |
|
| 65 |
Mock the I<$preference> with the specified I<value>. |
| 66 |
|
| 67 |
=cut |
| 68 |
|
| 25 |
sub mock_preference { |
69 |
sub mock_preference { |
| 26 |
my ( $pref, $value ) = @_; |
70 |
my ( $pref, $value ) = @_; |
| 27 |
|
71 |
|
|
Lines 40-45
sub mock_preference {
Link Here
|
| 40 |
}); |
84 |
}); |
| 41 |
} |
85 |
} |
| 42 |
|
86 |
|
|
|
87 |
=head3 mock_userenv |
| 88 |
|
| 89 |
t::lib::Mocks::mock_userenv( |
| 90 |
{ |
| 91 |
[ patron => $patron, |
| 92 |
borrowernumber => $borrowernumber, |
| 93 |
userid => $userid, |
| 94 |
cardnumber => $cardnumber, |
| 95 |
firstname => $firstname, |
| 96 |
surname => $surname, |
| 97 |
branchcode => $branchcode, |
| 98 |
branchname => $branchname, |
| 99 |
flags => $flags, |
| 100 |
emailaddress => $emailaddress, |
| 101 |
desk_id => $desk_id, |
| 102 |
desk_name => $desk_name, |
| 103 |
register_id => $register_id, |
| 104 |
register_name => $register_name, ] |
| 105 |
} |
| 106 |
); |
| 107 |
|
| 108 |
Mock userenv in the context of tests. A I<patron> param is usually expected, but |
| 109 |
some other session attributes might be passed as well, that will override the patron's. |
| 110 |
|
| 111 |
Also, some sane defaults are set if no parameters are passed. |
| 112 |
|
| 113 |
=cut |
| 114 |
|
| 43 |
sub mock_userenv { |
115 |
sub mock_userenv { |
| 44 |
my ( $params ) = @_; |
116 |
my ( $params ) = @_; |
| 45 |
|
117 |
|
| 46 |
- |
|
|