|
Lines 491-513
subtest 'build_object() tests' => sub {
Link Here
|
| 491 |
$module =~ s|^.*/(Koha.*)\.pm$|$1|; |
491 |
$module =~ s|^.*/(Koha.*)\.pm$|$1|; |
| 492 |
$module =~ s|/|::|g; |
492 |
$module =~ s|/|::|g; |
| 493 |
next if $module eq 'Koha::Objects'; |
493 |
next if $module eq 'Koha::Objects'; |
|
|
494 |
|
| 494 |
eval "require $module"; |
495 |
eval "require $module"; |
| 495 |
my $object = $builder->build_object( { class => $module } ); |
|
|
| 496 |
is( ref($object), $module->object_class, "Testing $module" ); |
| 497 |
|
496 |
|
| 498 |
if ( !grep { $module eq $_ } qw( Koha::Old::Patrons Koha::Statistics ) ) |
497 |
# Check if this is a polymorphic class |
| 499 |
{ # FIXME deletedborrowers and statistics do not have a PK |
498 |
my $is_polymorphic = $module->can('_polymorphic_field') && $module->can('_polymorphic_map'); |
| 500 |
eval { $object->get_from_storage }; |
499 |
|
| 501 |
is( $@, '', "Module $module should have koha_object[s]_class method if needed" ); |
500 |
if ($is_polymorphic) { |
|
|
501 |
|
| 502 |
# Test each concrete implementation |
| 503 |
my $polymorphic_field = $module->_polymorphic_field(); |
| 504 |
my $polymorphic_map = $module->_polymorphic_map(); |
| 505 |
|
| 506 |
foreach my $type_value ( keys %$polymorphic_map ) { |
| 507 |
my $expected_class = $polymorphic_map->{$type_value}; |
| 508 |
|
| 509 |
# Create an object of this type |
| 510 |
my $object = $builder->build_object( |
| 511 |
{ |
| 512 |
class => $module, |
| 513 |
value => { $polymorphic_field => $type_value } |
| 514 |
} |
| 515 |
); |
| 516 |
|
| 517 |
is( |
| 518 |
ref($object), $expected_class, |
| 519 |
"Testing polymorphic $module with $polymorphic_field=$type_value" |
| 520 |
); |
| 521 |
|
| 522 |
# Do the storage test |
| 523 |
if ( !grep { $module eq $_ } qw(Koha::Old::Patrons Koha::Statistics) ) { |
| 524 |
eval { $object->get_from_storage }; |
| 525 |
is( |
| 526 |
$@, '', |
| 527 |
"Module $module with $polymorphic_field=$type_value should have koha_object[s]_class method if needed" |
| 528 |
); |
| 529 |
} |
| 530 |
|
| 531 |
# Test class loading |
| 532 |
my $object_class = Koha::Object::_get_object_class( $object->_result->result_class ); |
| 533 |
eval "require $object_class"; |
| 534 |
is( $@, '', "Module $object_class should be defined" ); |
| 535 |
|
| 536 |
my $objects_class = Koha::Objects::_get_objects_class( $object->_result->result_class ); |
| 537 |
eval "require $objects_class"; |
| 538 |
is( $@, '', "Module $objects_class should be defined" ); |
| 539 |
} |
| 540 |
} else { |
| 541 |
|
| 542 |
# Regular class |
| 543 |
my $object = $builder->build_object( { class => $module } ); |
| 544 |
is( ref($object), $module->object_class, "Testing $module" ); |
| 545 |
|
| 546 |
if ( !grep { $module eq $_ } qw( Koha::Old::Patrons Koha::Statistics ) ) |
| 547 |
{ # FIXME deletedborrowers and statistics do not have a PK |
| 548 |
eval { $object->get_from_storage }; |
| 549 |
is( $@, '', "Module $module should have koha_object[s]_class method if needed" ); |
| 550 |
} |
| 551 |
|
| 552 |
# Testing koha_object_class and koha_objects_class |
| 553 |
my $object_class = Koha::Object::_get_object_class( $object->_result->result_class ); |
| 554 |
eval "require $object_class"; |
| 555 |
is( $@, '', "Module $object_class should be defined" ); |
| 556 |
my $objects_class = Koha::Objects::_get_objects_class( $object->_result->result_class ); |
| 557 |
eval "require $objects_class"; |
| 558 |
is( $@, '', "Module $objects_class should be defined" ); |
| 502 |
} |
559 |
} |
| 503 |
|
|
|
| 504 |
# Testing koha_object_class and koha_objects_class |
| 505 |
my $object_class = Koha::Object::_get_object_class( $object->_result->result_class ); |
| 506 |
eval "require $object_class"; |
| 507 |
is( $@, '', "Module $object_class should be defined" ); |
| 508 |
my $objects_class = Koha::Objects::_get_objects_class( $object->_result->result_class ); |
| 509 |
eval "require $objects_class"; |
| 510 |
is( $@, '', "Module $objects_class should be defined" ); |
| 511 |
} |
560 |
} |
| 512 |
}; |
561 |
}; |
| 513 |
|
562 |
|
| 514 |
- |
|
|