Bug 13578: Make sure the 'public' parameter is passed to the last step
[koha.git] / t / Acquisition / CanUserManageBasket.t
blob0733474f97c616195fde0f65f16b698bddd5267d
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use Test::More tests => 42;
6 use C4::Acquisition;
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;
14 my $AcqViewBaskets;
15 my %basketusers = (
16 1 => [],
17 2 => [1, 2],
18 3 => [],
19 4 => [1, 2],
22 # Borrowers
23 my $borrower1 = {
24 borrowernumber => 1,
25 branchcode => 'B1',
28 my $borrower2 = {
29 borrowernumber => 2,
30 branchcode => 'B2',
33 # Baskets
34 my $basket1 = {
35 basketno => 1,
36 authorisedby => 1
39 my $basket2 = {
40 basketno => 2,
41 authorisedby => 2,
44 my $basket3 = {
45 basketno => 3,
46 authorisedby => 3,
47 branch => 'B1'
50 my $basket4 = {
51 basketno => 4,
52 authorisedby => 4,
53 branch => 'B1'
57 my $flags = {
58 acquisition => {
59 order_manage => 1
63 #################
64 # Start testing #
65 #################
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, {
76 acquisition => 0
77 }) );
78 ok( not CanUserManageBasket($borrower1, $basket1, {
79 acquisition => {
80 order_manage => 0
82 }) );
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
95 }) );
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, {
115 acquisition => 0
116 }) );
117 ok( not CanUserManageBasket($borrower1, $basket1, {
118 acquisition => {
119 order_manage => 0
121 }) );
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
134 }) );
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, {
155 acquisition => 0
156 }) );
157 ok( not CanUserManageBasket($borrower1, $basket1, {
158 acquisition => {
159 order_manage => 0
161 }) );
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
174 }) );
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) );
189 # Mocked subs
191 # C4::Acquisition::GetBasketUsers
192 sub Mock_GetBasketUsers {
193 my ($basketno) = @_;
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;