View | Details | Raw Unified | Return to bug 6137
Collapse All | Expand All

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

Return to bug 6137