Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
use Test::MockModule; |
5 |
use Test::More tests => 30; |
6 |
|
7 |
use C4::Acquisition; |
8 |
|
9 |
my $C4_Acquisition_module = new Test::MockModule('C4::Acquisition'); |
10 |
$C4_Acquisition_module->mock('GetBasket', \&Mock_GetBasket); |
11 |
my $C4_Context_module = new Test::MockModule('C4::Context'); |
12 |
$C4_Context_module->mock('userenv', \&Mock_userenv); |
13 |
|
14 |
my $baskets = { |
15 |
1 => {}, |
16 |
2 => { |
17 |
branch => 'B1' |
18 |
}, |
19 |
3 => { |
20 |
branch => 'B2' |
21 |
} |
22 |
}; |
23 |
|
24 |
my $userenv = {}; |
25 |
|
26 |
my $borrower = {}; |
27 |
|
28 |
my $order1 = { |
29 |
basketno => 1 |
30 |
}; |
31 |
my $order2 = { |
32 |
basketno => 1, |
33 |
branch => 'B1' |
34 |
}; |
35 |
my $order3 = { |
36 |
basketno => 1, |
37 |
branch => 'B2' |
38 |
}; |
39 |
my $order4 = { |
40 |
basketno => 2 |
41 |
}; |
42 |
my $order5 = { |
43 |
basketno => 2, |
44 |
branch => 'B1' |
45 |
}; |
46 |
my $order6 = { |
47 |
basketno => 2, |
48 |
branch => 'B2' |
49 |
}; |
50 |
my $order7 = { |
51 |
basketno => 3 |
52 |
}; |
53 |
my $order8 = { |
54 |
basketno => 3, |
55 |
branch => 'B1' |
56 |
}; |
57 |
my $order9 = { |
58 |
basketno => 3, |
59 |
branch => 'B2' |
60 |
}; |
61 |
|
62 |
$userenv->{branch} = 'B1'; |
63 |
|
64 |
ok( CanUserReceiveOrder($borrower, $order1, {superlibrarian => 1}) ); |
65 |
ok( CanUserReceiveOrder($borrower, $order1, {acquisition => 1}) ); |
66 |
ok( CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive_all => 1 }}) ); |
67 |
|
68 |
ok( not CanUserReceiveOrder($borrower, $order1, {}) ); |
69 |
ok( not CanUserReceiveOrder($borrower, $order1, {acquisition => 0}) ); |
70 |
ok( not CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive => 0 }}) ); |
71 |
|
72 |
ok( CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive => 1 }}) ); |
73 |
ok( CanUserReceiveOrder($borrower, $order2, {acquisition => { order_receive => 1 }}) ); |
74 |
ok( not CanUserReceiveOrder($borrower, $order3, {acquisition => { order_receive => 1 }}) ); |
75 |
ok( CanUserReceiveOrder($borrower, $order4, {acquisition => { order_receive => 1 }}) ); |
76 |
ok( CanUserReceiveOrder($borrower, $order5, {acquisition => { order_receive => 1 }}) ); |
77 |
ok( not CanUserReceiveOrder($borrower, $order6, {acquisition => { order_receive => 1 }}) ); |
78 |
ok( not CanUserReceiveOrder($borrower, $order7, {acquisition => { order_receive => 1 }}) ); |
79 |
ok( CanUserReceiveOrder($borrower, $order8, {acquisition => { order_receive => 1 }}) ); |
80 |
ok( not CanUserReceiveOrder($borrower, $order9, {acquisition => { order_receive => 1 }}) ); |
81 |
|
82 |
|
83 |
$userenv->{branch} = 'B2'; |
84 |
|
85 |
ok( CanUserReceiveOrder($borrower, $order1, {superlibrarian => 1}) ); |
86 |
ok( CanUserReceiveOrder($borrower, $order1, {acquisition => 1}) ); |
87 |
ok( CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive_all => 1 }}) ); |
88 |
|
89 |
ok( not CanUserReceiveOrder($borrower, $order1, {}) ); |
90 |
ok( not CanUserReceiveOrder($borrower, $order1, {acquisition => 0}) ); |
91 |
ok( not CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive => 0 }}) ); |
92 |
|
93 |
ok( CanUserReceiveOrder($borrower, $order1, {acquisition => { order_receive => 1 }}) ); |
94 |
ok( not CanUserReceiveOrder($borrower, $order2, {acquisition => { order_receive => 1 }}) ); |
95 |
ok( CanUserReceiveOrder($borrower, $order3, {acquisition => { order_receive => 1 }}) ); |
96 |
ok( not CanUserReceiveOrder($borrower, $order4, {acquisition => { order_receive => 1 }}) ); |
97 |
ok( not CanUserReceiveOrder($borrower, $order5, {acquisition => { order_receive => 1 }}) ); |
98 |
ok( CanUserReceiveOrder($borrower, $order6, {acquisition => { order_receive => 1 }}) ); |
99 |
ok( CanUserReceiveOrder($borrower, $order7, {acquisition => { order_receive => 1 }}) ); |
100 |
ok( not CanUserReceiveOrder($borrower, $order8, {acquisition => { order_receive => 1 }}) ); |
101 |
ok( CanUserReceiveOrder($borrower, $order9, {acquisition => { order_receive => 1 }}) ); |
102 |
|
103 |
sub Mock_GetBasket { |
104 |
my ($basketno) = @_; |
105 |
|
106 |
return $baskets->{$basketno}; |
107 |
} |
108 |
|
109 |
sub Mock_userenv { |
110 |
return $userenv; |
111 |
} |