4 use Test
::More tests
=> 43;
8 # Avoid "redefined subroutine" warnings
9 local $SIG{__WARN__
} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
11 *C4
::Acquisition
::GetBasketUsers
= \
&Mock_GetBasketUsers
;
12 *C4
::Context
::preference
= \
&Mock_preference
;
72 # ----------------------
73 # AcqViewBaskets = 'all'
74 # ----------------------
76 $AcqViewBaskets = 'all';
78 # Simple cases where user can't manage basket
79 ok
( not CanUserManageBasket
($borrower1, $basket1, {}) );
80 ok
( not CanUserManageBasket
($borrower1, $basket1, {
83 ok
( not CanUserManageBasket
($borrower1, $basket1, {
89 # Simple cases where user can manage basket
90 ok
( CanUserManageBasket
($borrower1, $basket1, {
93 ok
( CanUserManageBasket
($borrower1, $basket1, {
96 ok
( CanUserManageBasket
($borrower1, $basket1, {
102 ok
( CanUserManageBasket
($borrower1, $basket1, $flags) );
103 ok
( CanUserManageBasket
($borrower1, $basket2, $flags) );
104 ok
( CanUserManageBasket
($borrower1, $basket3, $flags) );
105 ok
( CanUserManageBasket
($borrower1, $basket4, $flags) );
106 ok
( CanUserManageBasket
($borrower2, $basket1, $flags) );
107 ok
( CanUserManageBasket
($borrower2, $basket2, $flags) );
108 ok
( CanUserManageBasket
($borrower2, $basket3, $flags) );
109 ok
( CanUserManageBasket
($borrower2, $basket4, $flags) );
111 # -------------------------
112 # AcqViewBaskets = 'branch'
113 # -------------------------
115 $AcqViewBaskets = 'branch';
117 # Simple cases where user can't manage basket
118 ok
( not CanUserManageBasket
($borrower1, $basket1, {}) );
119 ok
( not CanUserManageBasket
($borrower1, $basket1, {
122 ok
( not CanUserManageBasket
($borrower1, $basket1, {
128 # Simple cases where user can manage basket
129 ok
( CanUserManageBasket
($borrower1, $basket1, {
132 ok
( CanUserManageBasket
($borrower1, $basket1, {
135 ok
( CanUserManageBasket
($borrower1, $basket1, {
137 order_manage_all
=> 1
141 ok
( CanUserManageBasket
($borrower1, $basket1, $flags) );
142 ok
( CanUserManageBasket
($borrower1, $basket2, $flags) );
143 ok
( CanUserManageBasket
($borrower1, $basket3, $flags) );
144 ok
( CanUserManageBasket
($borrower1, $basket4, $flags) );
145 ok
( CanUserManageBasket
($borrower2, $basket1, $flags) );
146 ok
( CanUserManageBasket
($borrower2, $basket2, $flags) );
147 # borrower2 is not on the same branch as basket3 and basket4
148 ok
( not CanUserManageBasket
($borrower2, $basket3, $flags) );
149 ok
( not CanUserManageBasket
($borrower2, $basket4, $flags) );
151 # -----------------------
152 # AcqViewBaskets = 'user'
153 # -----------------------
155 $AcqViewBaskets = 'user';
157 # Simple cases where user can't manage basket
158 ok
( not CanUserManageBasket
($borrower1, $basket1, {}) );
159 ok
( not CanUserManageBasket
($borrower1, $basket1, {
162 ok
( not CanUserManageBasket
($borrower1, $basket1, {
168 # Simple cases where user can manage basket
169 ok
( CanUserManageBasket
($borrower1, $basket1, {
172 ok
( CanUserManageBasket
($borrower1, $basket1, {
175 ok
( CanUserManageBasket
($borrower1, $basket1, {
177 order_manage_all
=> 1
181 ok
( CanUserManageBasket
($borrower1, $basket1, $flags) );
182 ok
( CanUserManageBasket
($borrower1, $basket2, $flags) );
183 # basket3 is not managed or created by borrower1
184 ok
( not CanUserManageBasket
($borrower1, $basket3, $flags) );
185 ok
( CanUserManageBasket
($borrower1, $basket4, $flags) );
186 # basket 1 is not managed or created by borrower2
187 ok
( not CanUserManageBasket
($borrower2, $basket1, $flags) );
188 ok
( CanUserManageBasket
($borrower2, $basket2, $flags) );
189 # basket 3 is not managed or created by borrower2
190 ok
( not CanUserManageBasket
($borrower2, $basket3, $flags) );
191 ok
( CanUserManageBasket
($borrower2, $basket4, $flags) );
193 # basket 4 is not managed by borrower3 but by other borrowers
194 ok
( not CanUserManageBasket
($borrower3, $basket4, $flags) );
198 # C4::Acquisition::GetBasketUsers
199 sub Mock_GetBasketUsers
{
202 return @
{ $basketusers{$basketno} };
205 # C4::Context->preference
206 sub Mock_preference
{
207 my ($self, $variable) = @_;
208 if (lc($variable) eq 'acqviewbaskets') {
209 return $AcqViewBaskets;