Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Test::More tests => 15; |
4 |
|
5 |
BEGIN { |
6 |
use_ok('C4::Circulation'); |
7 |
} |
8 |
|
9 |
my $CircControl = C4::Context->preference('CircControl'); |
10 |
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch'); |
11 |
|
12 |
my $item = { |
13 |
homebranch => 'ItemHomeBranch', |
14 |
holdingbranch => 'ItemHoldingBranch' |
15 |
}; |
16 |
|
17 |
my $borrower = { |
18 |
branchcode => 'BorrowerBranch' |
19 |
}; |
20 |
|
21 |
# No userenv, PickupLibrary |
22 |
C4::Context->set_preference('CircControl', 'PickupLibrary'); |
23 |
is( |
24 |
C4::Context->preference('CircControl'), |
25 |
'PickupLibrary', |
26 |
'CircControl changed to PickupLibrary' |
27 |
); |
28 |
is( |
29 |
C4::Circulation::_GetCircControlBranch($item, $borrower), |
30 |
$item->{$HomeOrHoldingBranch}, |
31 |
'_GetCircControlBranch returned item branch (no userenv defined)' |
32 |
); |
33 |
|
34 |
# No userenv, PatronLibrary |
35 |
C4::Context->set_preference('CircControl', 'PatronLibrary'); |
36 |
is( |
37 |
C4::Context->preference('CircControl'), |
38 |
'PatronLibrary', |
39 |
'CircControl changed to PatronLibrary' |
40 |
); |
41 |
is( |
42 |
C4::Circulation::_GetCircControlBranch($item, $borrower), |
43 |
$borrower->{branchcode}, |
44 |
'_GetCircControlBranch returned borrower branch' |
45 |
); |
46 |
|
47 |
# No userenv, ItemHomeLibrary |
48 |
C4::Context->set_preference('CircControl', 'ItemHomeLibrary'); |
49 |
is( |
50 |
C4::Context->preference('CircControl'), |
51 |
'ItemHomeLibrary', |
52 |
'CircControl changed to ItemHomeLibrary' |
53 |
); |
54 |
is( |
55 |
$item->{$HomeOrHoldingBranch}, |
56 |
C4::Circulation::_GetCircControlBranch($item, $borrower), |
57 |
'_GetCircControlBranch returned item branch' |
58 |
); |
59 |
|
60 |
diag('Now, set a userenv'); |
61 |
C4::Context->_new_userenv('xxx'); |
62 |
C4::Context::set_userenv(0,0,0,'firstname','surname', 'CurrentBranch', 'CurrentBranchName', '', '', ''); |
63 |
is(C4::Context->userenv->{branch}, 'CurrentBranch', 'userenv set'); |
64 |
|
65 |
# Userenv set, PickupLibrary |
66 |
C4::Context->set_preference('CircControl', 'PickupLibrary'); |
67 |
is( |
68 |
C4::Context->preference('CircControl'), |
69 |
'PickupLibrary', |
70 |
'CircControl changed to PickupLibrary' |
71 |
); |
72 |
is( |
73 |
C4::Circulation::_GetCircControlBranch($item, $borrower), |
74 |
'CurrentBranch', |
75 |
'_GetCircControlBranch returned current branch' |
76 |
); |
77 |
|
78 |
# Userenv set, PatronLibrary |
79 |
C4::Context->set_preference('CircControl', 'PatronLibrary'); |
80 |
is( |
81 |
C4::Context->preference('CircControl'), |
82 |
'PatronLibrary', |
83 |
'CircControl changed to PatronLibrary' |
84 |
); |
85 |
is( |
86 |
C4::Circulation::_GetCircControlBranch($item, $borrower), |
87 |
$borrower->{branchcode}, |
88 |
'_GetCircControlBranch returned borrower branch' |
89 |
); |
90 |
|
91 |
# Userenv set, ItemHomeLibrary |
92 |
C4::Context->set_preference('CircControl', 'ItemHomeLibrary'); |
93 |
is( |
94 |
C4::Context->preference('CircControl'), |
95 |
'ItemHomeLibrary', |
96 |
'CircControl changed to ItemHomeLibrary' |
97 |
); |
98 |
is( |
99 |
C4::Circulation::_GetCircControlBranch($item, $borrower), |
100 |
$item->{$HomeOrHoldingBranch}, |
101 |
'_GetCircControlBranch returned item branch' |
102 |
); |
103 |
|
104 |
# Reset initial configuration |
105 |
C4::Context->set_preference('CircControl', $CircControl); |
106 |
is( |
107 |
C4::Context->preference('CircControl'), |
108 |
$CircControl, |
109 |
'CircControl reset to its initial value' |
110 |
); |