4 use Test
::More tests
=> 37;
8 use C4
::Biblio
qw( AddBiblio );
9 use C4
::Members
qw( AddMember );
11 use_ok
('C4::Serials');
12 use_ok
('C4::Budgets');
15 local $SIG{__WARN__
} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
17 *C4
::Context
::userenv
= \
&Mock_userenv
;
19 my $dbh = C4
::Context
->dbh;
20 $dbh->{AutoCommit
} = 0;
21 $dbh->{RaiseError
} = 1;
24 my $supplierlist=eval{GetSuppliersWithLateIssues
()};
25 ok
(length($@
)==0,"No SQL problem in GetSuppliersWithLateIssues");
27 my $record = MARC
::Record
->new();
28 $record->append_fields(
29 MARC
::Field
->new( '952', '0', '0', a
=> 'CPL', b
=> 'CPL' )
31 my ( $biblionumber, $biblioitemnumber ) = C4
::Biblio
::AddBiblio
($record, '');
33 my $my_branch = 'CPL';
34 my $another_branch = 'MPL';
36 my $bpid = AddBudgetPeriod
({
37 budget_period_startdate
=> '2015-01-01',
38 budget_period_enddate
=> '2015-12-31',
39 budget_description
=> "budget desc"
42 my $budget_id = AddBudget
({
43 budget_code
=> "ABCD",
44 budget_amount
=> "123.132",
45 budget_name
=> "Périodiques",
46 budget_notes
=> "This is a note",
47 budget_description
=> "Serials",
49 budget_period_id
=> $bpid
52 my $subscriptionid_from_my_branch = NewSubscription
(
53 undef, $my_branch, undef, undef, $budget_id, $biblionumber,
54 '2013-01-01', undef, undef, undef, undef,
55 undef, undef, undef, undef, undef, undef,
56 1, "notes",undef, '2013-01-01', undef, undef,
57 undef, undef, 0, "intnotes", 0,
58 undef, undef, 0, undef, '2013-12-31', 0
60 die unless $subscriptionid_from_my_branch;
62 my $subscriptionid_from_another_branch = NewSubscription
(
63 undef, $another_branch, undef, undef, $budget_id, $biblionumber,
64 '2013-01-01', undef, undef, undef, undef,
65 undef, undef, undef, undef, undef, undef,
66 1, "notes",undef, '2013-01-01', undef, undef,
67 undef, undef, 0, "intnotes", 0,
68 undef, undef, 0, undef, '2013-12-31', 0
72 my $subscription_from_my_branch = GetSubscription
( $subscriptionid_from_my_branch );
73 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 0, "cannot edit a subscription without userenv set");
75 my $userid = 'my_userid';
76 my $borrowernumber = C4
::Members
::AddMember
(
77 firstname
=> 'my fistname',
78 surname
=> 'my surname',
80 branchcode
=> $my_branch,
84 $userenv = { flags
=> 1, id
=> $borrowernumber, branch
=> '' };
86 # Can edit a subscription
88 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 1, "User can edit a subscription with an empty branchcode");
90 my $subscription_from_another_branch = GetSubscription
( $subscriptionid_from_another_branch );
92 $userenv->{id
} = $userid;
93 $userenv->{branch
} = $my_branch;
95 # Branches are independent
96 t
::lib
::Mocks
::mock_preference
( "IndependentBranches", 1 );
97 set_flags
( 'superlibrarian', $borrowernumber );
98 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 1,
99 "With IndependentBranches, superlibrarian can edit a subscription from his branch"
101 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 1,
102 "With IndependentBranches, superlibrarian can edit a subscription from another branch"
104 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
105 "With IndependentBranches, superlibrarian can show a subscription from his branch"
107 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 1,
108 "With IndependentBranches, superlibrarian can show a subscription from another branch"
111 set_flags
( 'superserials', $borrowernumber );
112 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 1,
113 "With IndependentBranches, superserials can edit a subscription from his branch"
115 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 1,
116 "With IndependentBranches, superserials can edit a subscription from another branch"
118 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
119 "With IndependentBranches, superserials can show a subscription from his branch"
121 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 1,
122 "With IndependentBranches, superserials can show a subscription from another branch"
126 set_flags
( 'edit_subscription', $borrowernumber );
127 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 1,
128 "With IndependentBranches, edit_subscription can edit a subscription from his branch"
130 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 0,
131 "With IndependentBranches, edit_subscription cannot edit a subscription from another branch"
133 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
134 "With IndependentBranches, show_subscription can show a subscription from his branch"
136 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 0,
137 "With IndependentBranches, show_subscription cannot show a subscription from another branch"
140 set_flags
( 'renew_subscription', $borrowernumber );
141 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 0,
142 "With IndependentBranches, renew_subscription cannot edit a subscription from his branch"
144 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 0,
145 "With IndependentBranches, renew_subscription cannot edit a subscription from another branch"
147 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
148 "With IndependentBranches, renew_subscription can show a subscription from his branch"
150 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 0,
151 "With IndependentBranches, renew_subscription cannot show a subscription from another branch"
155 # Branches are not independent
156 t
::lib
::Mocks
::mock_preference
( "IndependentBranches", 0 );
157 set_flags
( 'superlibrarian', $borrowernumber );
158 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 1,
159 "Without IndependentBranches, superlibrarian can edit a subscription from his branch"
161 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 1,
162 "Without IndependentBranches, superlibrarian can edit a subscription from another branch"
164 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
165 "Without IndependentBranches, superlibrarian can show a subscription from his branch"
167 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 1,
168 "Without IndependentBranches, superlibrarian can show a subscription from another branch"
171 set_flags
( 'superserials', $borrowernumber );
172 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 1,
173 "Without IndependentBranches, superserials can edit a subscription from his branch"
175 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 1,
176 "Without IndependentBranches, superserials can edit a subscription from another branch"
178 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
179 "Without IndependentBranches, superserials can show a subscription from his branch"
181 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 1,
182 "Without IndependentBranches, superserials can show a subscription from another branch"
185 set_flags
( 'edit_subscription', $borrowernumber );
186 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 1,
187 "Without IndependentBranches, edit_subscription can edit a subscription from his branch"
189 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 1,
190 "Without IndependentBranches, edit_subscription can edit a subscription from another branch"
192 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
193 "Without IndependentBranches, show_subscription can show a subscription from his branch"
195 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 1,
196 "Without IndependentBranches, show_subscription can show a subscription from another branch"
199 set_flags
( 'renew_subscription', $borrowernumber );
200 is
( C4
::Serials
::can_edit_subscription
($subscription_from_my_branch), 0,
201 "Without IndependentBranches, renew_subscription cannot edit a subscription from his branch"
203 is
( C4
::Serials
::can_edit_subscription
($subscription_from_another_branch), 0,
204 "Without IndependentBranches, renew_subscription cannot edit a subscription from another branch"
206 is
( C4
::Serials
::can_show_subscription
($subscription_from_my_branch), 1,
207 "Without IndependentBranches, renew_subscription cannot show a subscription from his branch"
209 is
( C4
::Serials
::can_show_subscription
($subscription_from_another_branch), 1,
210 "Without IndependentBranches, renew_subscription cannot show a subscription from another branch"
215 # C4::Context->userenv
221 my ( $flags, $borrowernumber ) = @_;
222 my $superlibrarian_flags = 1;
223 if ( $flags eq 'superlibrarian' ) {
226 UPDATE borrowers SET flags
=? WHERE borrowernumber
=?
227 |, {}, $superlibrarian_flags, $borrowernumber
229 $userenv->{flags
} = $superlibrarian_flags;
234 UPDATE borrowers SET flags
=? WHERE borrowernumber
=?
235 |, {}, 0, $borrowernumber
237 $userenv->{flags
} = 0;
238 my ( $module_bit, $code ) = ( '15', $flags );
241 DELETE FROM user_permissions where borrowernumber
=?
242 |, {}, $borrowernumber
247 INSERT INTO user_permissions
( borrowernumber
, module_bit
, code
) VALUES
( ?
, ?
, ?
)
248 |, {}, $borrowernumber, $module_bit, $code