|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 6; |
| 23 |
|
23 |
|
| 24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
| 25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
|
Lines 255-273
subtest 'replace_library_limits() tests' => sub {
Link Here
|
| 255 |
my $library_limits = $attribute_type->library_limits; |
255 |
my $library_limits = $attribute_type->library_limits; |
| 256 |
is( $library_limits, undef, 'Replacing with empty array yields no library limits' ); |
256 |
is( $library_limits, undef, 'Replacing with empty array yields no library limits' ); |
| 257 |
|
257 |
|
| 258 |
my $library_1 = $builder->build({ source => 'Branch'})->{branchcode}; |
258 |
my $library_1 = $builder->build({ source => 'Branch' })->{branchcode}; |
| 259 |
my $library_2 = $builder->build({ source => 'Branch'})->{branchcode}; |
259 |
my $library_2 = $builder->build({ source => 'Branch' })->{branchcode}; |
| 260 |
my $library_3 = $builder->build({ source => 'Branch'})->{branchcode}; |
260 |
my $library_3 = $builder->build({ source => 'Branch' })->{branchcode}; |
| 261 |
|
261 |
|
| 262 |
$attribute_type->replace_library_limits( [$library_1] ); |
262 |
$attribute_type->replace_library_limits( [$library_1] ); |
| 263 |
$library_limits = $attribute_type->library_limits; |
263 |
$library_limits = $attribute_type->library_limits; |
| 264 |
is( $library_limits->count, 1, 'Successfully adds a single library limit' ); |
264 |
is( $library_limits->count, 1, |
|
|
265 |
'Successfully adds a single library limit' ); |
| 265 |
my $library_limit = $library_limits->next; |
266 |
my $library_limit = $library_limits->next; |
| 266 |
is( $library_limit->branchcode, $library_1, 'Library limit correctly set' ); |
267 |
is( $library_limit->branchcode, |
|
|
268 |
$library_1, 'Library limit correctly set' ); |
| 267 |
|
269 |
|
| 268 |
|
270 |
my @branchcodes_list = ( $library_1, $library_2, $library_3 ); |
| 269 |
my @branchcodes_list = ($library_1, $library_2, $library_3); |
271 |
$attribute_type->replace_library_limits( |
| 270 |
$attribute_type->replace_library_limits( [$library_1, $library_2, $library_3] ); |
272 |
[ $library_1, $library_2, $library_3 ] ); |
| 271 |
$library_limits = $attribute_type->library_limits; |
273 |
$library_limits = $attribute_type->library_limits; |
| 272 |
is( $library_limits->count, 3, 'Successfully adds two library limit' ); |
274 |
is( $library_limits->count, 3, 'Successfully adds two library limit' ); |
| 273 |
|
275 |
|
|
Lines 285-288
subtest 'replace_library_limits() tests' => sub {
Link Here
|
| 285 |
$schema->storage->txn_rollback; |
287 |
$schema->storage->txn_rollback; |
| 286 |
}; |
288 |
}; |
| 287 |
|
289 |
|
|
|
290 |
subtest 'search() with branch limits tests' => sub { |
| 291 |
|
| 292 |
plan tests => 3; |
| 293 |
|
| 294 |
$schema->storage->txn_begin; |
| 295 |
|
| 296 |
# Cleanup before running the tests |
| 297 |
Koha::Patron::Attribute::Types->search()->delete(); |
| 298 |
|
| 299 |
my $object_code_1 |
| 300 |
= Koha::Patron::Attribute::Type->new( { code => 'code_1', } ) |
| 301 |
->store(); |
| 302 |
|
| 303 |
my $object_code_2 |
| 304 |
= Koha::Patron::Attribute::Type->new( { code => 'code_2', } ) |
| 305 |
->store(); |
| 306 |
|
| 307 |
my $object_code_3 |
| 308 |
= Koha::Patron::Attribute::Type->new( { code => 'code_3', } ) |
| 309 |
->store(); |
| 310 |
|
| 311 |
my $object_code_4 |
| 312 |
= Koha::Patron::Attribute::Type->new( { code => 'code_4', } ) |
| 313 |
->store(); |
| 314 |
|
| 315 |
is( Koha::Patron::Attribute::Types->search()->count, |
| 316 |
4, 'Three objects created' ); |
| 317 |
|
| 318 |
my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 319 |
my $branch_2 = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 320 |
|
| 321 |
$object_code_1->library_limits( [$branch_1] ); |
| 322 |
$object_code_2->library_limits( [$branch_2] ); |
| 323 |
$object_code_3->library_limits( [ $branch_1, $branch_2 ] ); |
| 324 |
|
| 325 |
is( Koha::Patron::Attribute::Types->search( { branchcode => $branch_1 } ) |
| 326 |
->count, |
| 327 |
3, |
| 328 |
'3 attribute types are available for the specified branch' |
| 329 |
); |
| 330 |
is( Koha::Patron::Attribute::Types->search( { branchcode => $branch_2 } ) |
| 331 |
->count, |
| 332 |
3, |
| 333 |
'3 attribute types are available for the specified branch' |
| 334 |
); |
| 335 |
|
| 336 |
$schema->storage->txn_rollback; |
| 337 |
}; |
| 338 |
|
| 288 |
1; |
339 |
1; |
| 289 |
- |
|
|