4 use Test
::More tests
=> 42;
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
;
67 # ----------------------
68 # AcqViewBaskets = 'all'
69 # ----------------------
71 $AcqViewBaskets = 'all';
73 # Simple cases where user can't manage basket
74 ok
( not CanUserManageBasket
($borrower1, $basket1, {}) );
75 ok
( not CanUserManageBasket
($borrower1, $basket1, {
78 ok
( not CanUserManageBasket
($borrower1, $basket1, {
84 # Simple cases where user can manage basket
85 ok
( CanUserManageBasket
($borrower1, $basket1, {
88 ok
( CanUserManageBasket
($borrower1, $basket1, {
91 ok
( CanUserManageBasket
($borrower1, $basket1, {
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) );
106 # -------------------------
107 # AcqViewBaskets = 'branch'
108 # -------------------------
110 $AcqViewBaskets = 'branch';
112 # Simple cases where user can't manage basket
113 ok
( not CanUserManageBasket
($borrower1, $basket1, {}) );
114 ok
( not CanUserManageBasket
($borrower1, $basket1, {
117 ok
( not CanUserManageBasket
($borrower1, $basket1, {
123 # Simple cases where user can manage basket
124 ok
( CanUserManageBasket
($borrower1, $basket1, {
127 ok
( CanUserManageBasket
($borrower1, $basket1, {
130 ok
( CanUserManageBasket
($borrower1, $basket1, {
132 order_manage_all
=> 1
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) );
146 # -----------------------
147 # AcqViewBaskets = 'user'
148 # -----------------------
150 $AcqViewBaskets = 'user';
152 # Simple cases where user can't manage basket
153 ok
( not CanUserManageBasket
($borrower1, $basket1, {}) );
154 ok
( not CanUserManageBasket
($borrower1, $basket1, {
157 ok
( not CanUserManageBasket
($borrower1, $basket1, {
163 # Simple cases where user can manage basket
164 ok
( CanUserManageBasket
($borrower1, $basket1, {
167 ok
( CanUserManageBasket
($borrower1, $basket1, {
170 ok
( CanUserManageBasket
($borrower1, $basket1, {
172 order_manage_all
=> 1
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) );
191 # C4::Acquisition::GetBasketUsers
192 sub Mock_GetBasketUsers
{
195 return @
{ $basketusers{$basketno} };
198 # C4::Context->preference
199 sub Mock_preference
{
200 my ($self, $variable) = @_;
201 if (lc($variable) eq 'acqviewbaskets') {
202 return $AcqViewBaskets;