Lines 72-78
subtest 'new() tests' => sub {
Link Here
|
72 |
|
72 |
|
73 |
subtest 'library_limits() tests' => sub { |
73 |
subtest 'library_limits() tests' => sub { |
74 |
|
74 |
|
75 |
plan tests => 5; |
75 |
plan tests => 13; |
76 |
|
76 |
|
77 |
$schema->storage->txn_begin; |
77 |
$schema->storage->txn_begin; |
78 |
|
78 |
|
Lines 89-131
subtest 'library_limits() tests' => sub {
Link Here
|
89 |
my $library = $builder->build( { source => 'Branch' } )->{branchcode}; |
89 |
my $library = $builder->build( { source => 'Branch' } )->{branchcode}; |
90 |
|
90 |
|
91 |
my $library_limits = $attribute_type->library_limits(); |
91 |
my $library_limits = $attribute_type->library_limits(); |
92 |
is_deeply( $library_limits, [], |
92 |
is( $library_limits, undef, |
93 |
'No branch limitations defined for attribute type' ); |
93 |
'No branch limitations defined for attribute type' ); |
94 |
|
94 |
|
95 |
my $print_error = $dbh->{PrintError}; |
95 |
my $print_error = $dbh->{PrintError}; |
96 |
$dbh->{PrintError} = 0; |
96 |
$dbh->{PrintError} = 0; |
97 |
|
97 |
|
98 |
throws_ok { |
98 |
throws_ok { |
99 |
$library_limits = $attribute_type->library_limits( ['fake'] ); |
99 |
$attribute_type->library_limits( ['fake'] ); |
100 |
} |
100 |
} |
101 |
'Koha::Exceptions::CannotAddLibraryLimit', |
101 |
'Koha::Exceptions::CannotAddLibraryLimit', |
102 |
'Exception thrown on single invalid branchcode'; |
102 |
'Exception thrown on single invalid branchcode'; |
|
|
103 |
$library_limits = $attribute_type->library_limits(); |
104 |
is( $library_limits, undef, |
105 |
'No branch limitations defined for attribute type' ); |
103 |
|
106 |
|
104 |
throws_ok { |
107 |
throws_ok { |
105 |
$library_limits |
108 |
$attribute_type->library_limits( [ 'fake', $library ] ); |
106 |
= $attribute_type->library_limits( [ 'fake', $library ] ); |
|
|
107 |
} |
109 |
} |
108 |
'Koha::Exceptions::CannotAddLibraryLimit', |
110 |
'Koha::Exceptions::CannotAddLibraryLimit', |
109 |
'Exception thrown on invalid branchcode present'; |
111 |
'Exception thrown on invalid branchcode present'; |
110 |
|
112 |
|
|
|
113 |
$library_limits = $attribute_type->library_limits(); |
114 |
is( $library_limits, undef, |
115 |
'No branch limitations defined for attribute type' ); |
116 |
|
111 |
$dbh->{PrintError} = $print_error; |
117 |
$dbh->{PrintError} = $print_error; |
112 |
|
118 |
|
113 |
$library_limits = $attribute_type->library_limits( [$library] ); |
119 |
$attribute_type->library_limits( [$library] ); |
114 |
is_deeply( $library_limits, [1], 'Library limits correctly set' ); |
120 |
$library_limits = $attribute_type->library_limits; |
|
|
121 |
is( $library_limits->count, 1, 'Library limits correctly set (count)' ); |
122 |
my $limit_library = $library_limits->next; |
123 |
ok( $limit_library->isa('Koha::Library'), |
124 |
'Library limits correctly set (type)' |
125 |
); |
126 |
is( $limit_library->branchcode, |
127 |
$library, 'Library limits correctly set (value)' ); |
115 |
|
128 |
|
116 |
my $another_library |
129 |
my $another_library |
117 |
= $builder->build( { source => 'Branch' } )->{branchcode}; |
130 |
= $builder->build( { source => 'Branch' } )->{branchcode}; |
118 |
|
131 |
my @branchcodes_list = ( $library, $another_library ); |
119 |
$library_limits |
132 |
|
120 |
= $attribute_type->library_limits( [ $library, $another_library ] ); |
133 |
$attribute_type->library_limits( \@branchcodes_list ); |
121 |
is_deeply( $library_limits, [ 1, 1 ], 'Library limits correctly set' ); |
134 |
$library_limits = $attribute_type->library_limits; |
|
|
135 |
is( $library_limits->count, 2, 'Library limits correctly set (count)' ); |
136 |
|
137 |
while ( $limit_library = $library_limits->next ) { |
138 |
ok( $limit_library->isa('Koha::Library'), |
139 |
'Library limits correctly set (type)' |
140 |
); |
141 |
ok( eval { |
142 |
grep { $limit_library->branchcode eq $_ } @branchcodes_list; |
143 |
}, |
144 |
'Library limits correctly set (values)' |
145 |
); |
146 |
} |
122 |
|
147 |
|
123 |
$schema->storage->txn_rollback; |
148 |
$schema->storage->txn_rollback; |
124 |
}; |
149 |
}; |
125 |
|
150 |
|
126 |
subtest 'add_library_limit() tests' => sub { |
151 |
subtest 'add_library_limit() tests' => sub { |
127 |
|
152 |
|
128 |
plan tests => 3; |
153 |
plan tests => 4; |
129 |
|
154 |
|
130 |
$schema->storage->txn_begin; |
155 |
$schema->storage->txn_begin; |
131 |
|
156 |
|
Lines 140-151
subtest 'add_library_limit() tests' => sub {
Link Here
|
140 |
)->store(); |
165 |
)->store(); |
141 |
|
166 |
|
142 |
throws_ok { $attribute_type->add_library_limit() } |
167 |
throws_ok { $attribute_type->add_library_limit() } |
143 |
'Koha::Exceptions::MissingParameter', |
168 |
'Koha::Exceptions::MissingParameter', 'branchcode parameter is mandatory'; |
144 |
'branchcode parameter is mandatory'; |
|
|
145 |
|
169 |
|
146 |
my $library = $builder->build( { source => 'Branch' } )->{branchcode}; |
170 |
my $library = $builder->build( { source => 'Branch' } )->{branchcode}; |
147 |
is( $attribute_type->add_library_limit($library), |
171 |
$attribute_type->add_library_limit($library); |
148 |
1, 'Library limit successfully added' ); |
172 |
my $rs = Koha::Database->schema->resultset('BorrowerAttributeTypesBranch') |
|
|
173 |
->search( { bat_code => 'code' } ); |
174 |
is( $rs->count, 1, 'Library limit successfully added (count)' ); |
175 |
is( $rs->next->b_branchcode->branchcode, |
176 |
$library, 'Library limit successfully added (value)' ); |
149 |
|
177 |
|
150 |
my $print_error = $dbh->{PrintError}; |
178 |
my $print_error = $dbh->{PrintError}; |
151 |
$dbh->{PrintError} = 0; |
179 |
$dbh->{PrintError} = 0; |
Lines 209-215
subtest 'del_library_limit() tests' => sub {
Link Here
|
209 |
|
237 |
|
210 |
subtest 'replace_library_limits() tests' => sub { |
238 |
subtest 'replace_library_limits() tests' => sub { |
211 |
|
239 |
|
212 |
plan tests => 6; |
240 |
plan tests => 10; |
213 |
|
241 |
|
214 |
$schema->storage->txn_begin; |
242 |
$schema->storage->txn_begin; |
215 |
|
243 |
|
Lines 223-248
subtest 'replace_library_limits() tests' => sub {
Link Here
|
223 |
} |
251 |
} |
224 |
)->store(); |
252 |
)->store(); |
225 |
|
253 |
|
226 |
is_deeply( $attribute_type->replace_library_limits( [] ), |
254 |
$attribute_type->replace_library_limits( [] ); |
227 |
[], 'Replacing with empty array returns an empty array as expected' ); |
255 |
my $library_limits = $attribute_type->library_limits; |
228 |
|
256 |
is( $library_limits, undef, 'Replacing with empty array yields no library limits' ); |
229 |
is_deeply( $attribute_type->library_limits(), |
|
|
230 |
[], 'Replacing with empty array yields no library limits' ); |
231 |
|
257 |
|
232 |
my $library_1 = $builder->build({ source => 'Branch'})->{branchcode}; |
258 |
my $library_1 = $builder->build({ source => 'Branch'})->{branchcode}; |
233 |
my $library_2 = $builder->build({ source => 'Branch'})->{branchcode}; |
259 |
my $library_2 = $builder->build({ source => 'Branch'})->{branchcode}; |
234 |
|
260 |
my $library_3 = $builder->build({ source => 'Branch'})->{branchcode}; |
235 |
is_deeply( $attribute_type->replace_library_limits( [$library_1] ), |
261 |
|
236 |
[ 1 ], 'Successfully adds a single library limit' ); |
262 |
$attribute_type->replace_library_limits( [$library_1] ); |
237 |
|
263 |
$library_limits = $attribute_type->library_limits; |
238 |
is_deeply( $attribute_type->library_limits(), |
264 |
is( $library_limits->count, 1, 'Successfully adds a single library limit' ); |
239 |
[ $library_1 ], 'Library limit correctly set' ); |
265 |
my $library_limit = $library_limits->next; |
240 |
|
266 |
is( $library_limit->branchcode, $library_1, 'Library limit correctly set' ); |
241 |
is_deeply( $attribute_type->replace_library_limits( [$library_1, $library_2] ), |
267 |
|
242 |
[ 1, 1 ], 'Successfully adds two library limit' ); |
268 |
|
243 |
|
269 |
my @branchcodes_list = ($library_1, $library_2, $library_3); |
244 |
is_deeply( $attribute_type->library_limits(), |
270 |
$attribute_type->replace_library_limits( [$library_1, $library_2, $library_3] ); |
245 |
[ $library_1, $library_2 ], 'Library limit correctly set' ); |
271 |
$library_limits = $attribute_type->library_limits; |
|
|
272 |
is( $library_limits->count, 3, 'Successfully adds two library limit' ); |
273 |
|
274 |
while ( my $limit_library = $library_limits->next ) { |
275 |
ok( $limit_library->isa('Koha::Library'), |
276 |
'Library limits correctly set (type)' |
277 |
); |
278 |
ok( eval { |
279 |
grep { $limit_library->branchcode eq $_ } @branchcodes_list; |
280 |
}, |
281 |
'Library limits correctly set (values)' |
282 |
); |
283 |
} |
246 |
|
284 |
|
247 |
$schema->storage->txn_rollback; |
285 |
$schema->storage->txn_rollback; |
248 |
}; |
286 |
}; |
249 |
- |
|
|