Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
use Test::MockModule; |
5 |
use Test::More tests => 42; |
6 |
|
7 |
use C4::Acquisition; |
8 |
|
9 |
my $C4_Acquisition_module = new Test::MockModule('C4::Acquisition'); |
10 |
$C4_Acquisition_module->mock('GetBasketUsers', \&Mock_GetBasketUsers); |
11 |
my $C4_Context_module = new Test::MockModule('C4::Context'); |
12 |
$C4_Context_module->mock('preference', \&Mock_preference); |
13 |
|
14 |
my $AcqViewBaskets; |
15 |
my %basketusers = ( |
16 |
1 => [], |
17 |
2 => [1, 2], |
18 |
3 => [], |
19 |
4 => [1, 2], |
20 |
); |
21 |
|
22 |
# Borrowers |
23 |
my $borrower1 = { |
24 |
borrowernumber => 1, |
25 |
branchcode => 'B1', |
26 |
}; |
27 |
|
28 |
my $borrower2 = { |
29 |
borrowernumber => 2, |
30 |
branchcode => 'B2', |
31 |
}; |
32 |
|
33 |
# Baskets |
34 |
my $basket1 = { |
35 |
basketno => 1, |
36 |
authorisedby => 1 |
37 |
}; |
38 |
|
39 |
my $basket2 = { |
40 |
basketno => 2, |
41 |
authorisedby => 2, |
42 |
}; |
43 |
|
44 |
my $basket3 = { |
45 |
basketno => 3, |
46 |
authorisedby => 3, |
47 |
branch => 'B1' |
48 |
}; |
49 |
|
50 |
my $basket4 = { |
51 |
basketno => 4, |
52 |
authorisedby => 4, |
53 |
branch => 'B1' |
54 |
}; |
55 |
|
56 |
|
57 |
my $flags = { |
58 |
acquisition => { |
59 |
order_manage => 1 |
60 |
} |
61 |
}; |
62 |
|
63 |
################# |
64 |
# Start testing # |
65 |
################# |
66 |
|
67 |
# ---------------------- |
68 |
# AcqViewBaskets = 'all' |
69 |
# ---------------------- |
70 |
|
71 |
$AcqViewBaskets = 'all'; |
72 |
|
73 |
# Simple cases where user can't manage basket |
74 |
ok( not CanUserManageBasket($borrower1, $basket1, {}) ); |
75 |
ok( not CanUserManageBasket($borrower1, $basket1, { |
76 |
acquisition => 0 |
77 |
}) ); |
78 |
ok( not CanUserManageBasket($borrower1, $basket1, { |
79 |
acquisition => { |
80 |
order_manage => 0 |
81 |
} |
82 |
}) ); |
83 |
|
84 |
# Simple cases where user can manage basket |
85 |
ok( CanUserManageBasket($borrower1, $basket1, { |
86 |
superlibrarian => 1 |
87 |
}) ); |
88 |
ok( CanUserManageBasket($borrower1, $basket1, { |
89 |
acquisition => 1 |
90 |
}) ); |
91 |
ok( CanUserManageBasket($borrower1, $basket1, { |
92 |
acquisition => { |
93 |
order_manage_all => 1 |
94 |
} |
95 |
}) ); |
96 |
|
97 |
ok( CanUserManageBasket($borrower1, $basket1, $flags) ); |
98 |
ok( CanUserManageBasket($borrower1, $basket2, $flags) ); |
99 |
ok( CanUserManageBasket($borrower1, $basket3, $flags) ); |
100 |
ok( CanUserManageBasket($borrower1, $basket4, $flags) ); |
101 |
ok( CanUserManageBasket($borrower2, $basket1, $flags) ); |
102 |
ok( CanUserManageBasket($borrower2, $basket2, $flags) ); |
103 |
ok( CanUserManageBasket($borrower2, $basket3, $flags) ); |
104 |
ok( CanUserManageBasket($borrower2, $basket4, $flags) ); |
105 |
|
106 |
# ------------------------- |
107 |
# AcqViewBaskets = 'branch' |
108 |
# ------------------------- |
109 |
|
110 |
$AcqViewBaskets = 'branch'; |
111 |
|
112 |
# Simple cases where user can't manage basket |
113 |
ok( not CanUserManageBasket($borrower1, $basket1, {}) ); |
114 |
ok( not CanUserManageBasket($borrower1, $basket1, { |
115 |
acquisition => 0 |
116 |
}) ); |
117 |
ok( not CanUserManageBasket($borrower1, $basket1, { |
118 |
acquisition => { |
119 |
order_manage => 0 |
120 |
} |
121 |
}) ); |
122 |
|
123 |
# Simple cases where user can manage basket |
124 |
ok( CanUserManageBasket($borrower1, $basket1, { |
125 |
superlibrarian => 1 |
126 |
}) ); |
127 |
ok( CanUserManageBasket($borrower1, $basket1, { |
128 |
acquisition => 1 |
129 |
}) ); |
130 |
ok( CanUserManageBasket($borrower1, $basket1, { |
131 |
acquisition => { |
132 |
order_manage_all => 1 |
133 |
} |
134 |
}) ); |
135 |
|
136 |
ok( CanUserManageBasket($borrower1, $basket1, $flags) ); |
137 |
ok( CanUserManageBasket($borrower1, $basket2, $flags) ); |
138 |
ok( CanUserManageBasket($borrower1, $basket3, $flags) ); |
139 |
ok( CanUserManageBasket($borrower1, $basket4, $flags) ); |
140 |
ok( CanUserManageBasket($borrower2, $basket1, $flags) ); |
141 |
ok( CanUserManageBasket($borrower2, $basket2, $flags) ); |
142 |
# borrower2 is not on the same branch as basket3 and basket4 |
143 |
ok( not CanUserManageBasket($borrower2, $basket3, $flags) ); |
144 |
ok( not CanUserManageBasket($borrower2, $basket4, $flags) ); |
145 |
|
146 |
# ----------------------- |
147 |
# AcqViewBaskets = 'user' |
148 |
# ----------------------- |
149 |
|
150 |
$AcqViewBaskets = 'user'; |
151 |
|
152 |
# Simple cases where user can't manage basket |
153 |
ok( not CanUserManageBasket($borrower1, $basket1, {}) ); |
154 |
ok( not CanUserManageBasket($borrower1, $basket1, { |
155 |
acquisition => 0 |
156 |
}) ); |
157 |
ok( not CanUserManageBasket($borrower1, $basket1, { |
158 |
acquisition => { |
159 |
order_manage => 0 |
160 |
} |
161 |
}) ); |
162 |
|
163 |
# Simple cases where user can manage basket |
164 |
ok( CanUserManageBasket($borrower1, $basket1, { |
165 |
superlibrarian => 1 |
166 |
}) ); |
167 |
ok( CanUserManageBasket($borrower1, $basket1, { |
168 |
acquisition => 1 |
169 |
}) ); |
170 |
ok( CanUserManageBasket($borrower1, $basket1, { |
171 |
acquisition => { |
172 |
order_manage_all => 1 |
173 |
} |
174 |
}) ); |
175 |
|
176 |
ok( CanUserManageBasket($borrower1, $basket1, $flags) ); |
177 |
ok( CanUserManageBasket($borrower1, $basket2, $flags) ); |
178 |
# basket3 is not managed or created by borrower1 |
179 |
ok( not CanUserManageBasket($borrower1, $basket3, $flags) ); |
180 |
ok( CanUserManageBasket($borrower1, $basket4, $flags) ); |
181 |
# basket 1 is not managed or created by borrower2 |
182 |
ok( not CanUserManageBasket($borrower2, $basket1, $flags) ); |
183 |
ok( CanUserManageBasket($borrower2, $basket2, $flags) ); |
184 |
# basket 3 is not managed or created by borrower2 |
185 |
ok( not CanUserManageBasket($borrower2, $basket3, $flags) ); |
186 |
ok( CanUserManageBasket($borrower2, $basket4, $flags) ); |
187 |
|
188 |
|
189 |
# Mocked subs |
190 |
|
191 |
# C4::Acquisition::GetBasketUsers |
192 |
sub Mock_GetBasketUsers { |
193 |
my ($basketno) = @_; |
194 |
|
195 |
return @{ $basketusers{$basketno} }; |
196 |
} |
197 |
|
198 |
# C4::Context->preference |
199 |
sub Mock_preference { |
200 |
my ($self, $variable) = @_; |
201 |
if (lc($variable) eq 'acqviewbaskets') { |
202 |
return $AcqViewBaskets; |
203 |
} |
204 |
} |