Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 16; |
4 |
use Test::More tests => 17; |
|
|
5 |
use Test::Exception; |
5 |
use Try::Tiny; |
6 |
use Try::Tiny; |
6 |
|
7 |
|
7 |
use t::lib::TestBuilder; |
8 |
use t::lib::TestBuilder; |
Lines 11-16
use C4::Context;
Link Here
|
11 |
use Koha::AuthorisedValue; |
12 |
use Koha::AuthorisedValue; |
12 |
use Koha::AuthorisedValues; |
13 |
use Koha::AuthorisedValues; |
13 |
use Koha::AuthorisedValueCategories; |
14 |
use Koha::AuthorisedValueCategories; |
|
|
15 |
use Koha::Exceptions; |
14 |
use Koha::MarcSubfieldStructures; |
16 |
use Koha::MarcSubfieldStructures; |
15 |
|
17 |
|
16 |
my $schema = Koha::Database->new->schema; |
18 |
my $schema = Koha::Database->new->schema; |
Lines 332-335
subtest 'search_by_*_field + find_by_koha_field + get_description + authorised_v
Link Here
|
332 |
}; |
334 |
}; |
333 |
}; |
335 |
}; |
334 |
|
336 |
|
|
|
337 |
subtest 'is_integer_only' => sub { |
338 |
plan tests => 13; |
339 |
$schema->storage->txn_begin; |
340 |
|
341 |
my $avcat1 = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
342 |
my $avcat2 = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
343 |
$avcat2->is_integer_only(1)->store; |
344 |
is( $avcat1->is_integer_only, 0, 'No numeric requirement expected' ); |
345 |
is( $avcat2->is_integer_only, 1, 'Numeric requirement expected' ); |
346 |
|
347 |
my $avval1 = $builder->build_object( |
348 |
{ |
349 |
class => 'Koha::AuthorisedValues', |
350 |
value => { category => $avcat1->category_name, authorised_value => 'abc' } |
351 |
} |
352 |
); |
353 |
my $avval2 = $builder->build_object( |
354 |
{ |
355 |
class => 'Koha::AuthorisedValues', |
356 |
value => { category => $avcat2->category_name, authorised_value => '123' } |
357 |
} |
358 |
); |
359 |
|
360 |
# Test helper method on child (authval) |
361 |
is( $avval1->is_integer_only, 0, 'No numeric requirement expected' ); |
362 |
is( $avval2->is_integer_only, 1, 'Numeric requirement expected' ); |
363 |
|
364 |
lives_ok { $avval2->authorised_value(-1)->store } 'No exception expected'; |
365 |
lives_ok { $avval2->authorised_value(0)->store } 'No exception expected'; |
366 |
lives_ok { $avval2->authorised_value(22)->store } 'No exception expected'; |
367 |
|
368 |
# Test ->store with bad data |
369 |
throws_ok { $avval2->authorised_value(undef)->store } 'Koha::Exceptions::NoInteger', |
370 |
'Exception expected (undefined)'; |
371 |
throws_ok { $avval2->authorised_value('')->store } 'Koha::Exceptions::NoInteger', 'Exception expected (empty)'; |
372 |
throws_ok { $avval2->authorised_value('abc')->store } 'Koha::Exceptions::NoInteger', 'Exception expected for abc'; |
373 |
throws_ok { $avval2->authorised_value('+12')->store } 'Koha::Exceptions::NoInteger', |
374 |
'Exception expected for + sign'; |
375 |
throws_ok { $avval2->authorised_value(' 12')->store } 'Koha::Exceptions::NoInteger', |
376 |
'Exception expected for preceding space'; |
377 |
throws_ok { $avval2->authorised_value('12 ')->store } 'Koha::Exceptions::NoInteger', |
378 |
'Exception expected for trailing space'; |
379 |
|
380 |
$schema->storage->txn_rollback; |
381 |
}; |
382 |
|
335 |
$schema->storage->txn_rollback; |
383 |
$schema->storage->txn_rollback; |