Bugzilla – Attachment 179412 Details for
Bug 39190
Rework new (S)FTP classes to be polymorphic classes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39190: Use introspection in TestBuilder tests
Bug-39190-Use-introspection-in-TestBuilder-tests.patch (text/plain), 4.93 KB, created by
Martin Renvoize (ashimema)
on 2025-03-17 15:21:42 UTC
(
hide
)
Description:
Bug 39190: Use introspection in TestBuilder tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-03-17 15:21:42 UTC
Size:
4.93 KB
patch
obsolete
>From 42acb321897754d7550c9e9e04fdc68ac5ce1198 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 17 Feb 2025 11:51:34 +0000 >Subject: [PATCH] Bug 39190: Use introspection in TestBuilder tests > >We update the testbuilder tests here to look for signs of a polymorphic >class map and use it to test the different class options for this base >class >--- > t/db_dependent/TestBuilder.t | 77 +++++++++++++++++++++++++++++------- > 1 file changed, 63 insertions(+), 14 deletions(-) > >diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t >index 121849fd943..1d2f9e1a96d 100755 >--- a/t/db_dependent/TestBuilder.t >+++ b/t/db_dependent/TestBuilder.t >@@ -491,23 +491,72 @@ subtest 'build_object() tests' => sub { > $module =~ s|^.*/(Koha.*)\.pm$|$1|; > $module =~ s|/|::|g; > next if $module eq 'Koha::Objects'; >+ > eval "require $module"; >- my $object = $builder->build_object( { class => $module } ); >- is( ref($object), $module->object_class, "Testing $module" ); > >- if ( !grep { $module eq $_ } qw( Koha::Old::Patrons Koha::Statistics ) ) >- { # FIXME deletedborrowers and statistics do not have a PK >- eval { $object->get_from_storage }; >- is( $@, '', "Module $module should have koha_object[s]_class method if needed" ); >+ # Check if this is a polymorphic class >+ my $is_polymorphic = $module->can('_polymorphic_field') && $module->can('_polymorphic_map'); >+ >+ if ($is_polymorphic) { >+ >+ # Test each concrete implementation >+ my $polymorphic_field = $module->_polymorphic_field(); >+ my $polymorphic_map = $module->_polymorphic_map(); >+ >+ foreach my $type_value ( keys %$polymorphic_map ) { >+ my $expected_class = $polymorphic_map->{$type_value}; >+ >+ # Create an object of this type >+ my $object = $builder->build_object( >+ { >+ class => $module, >+ value => { $polymorphic_field => $type_value } >+ } >+ ); >+ >+ is( >+ ref($object), $expected_class, >+ "Testing polymorphic $module with $polymorphic_field=$type_value" >+ ); >+ >+ # Do the storage test >+ if ( !grep { $module eq $_ } qw(Koha::Old::Patrons Koha::Statistics) ) { >+ eval { $object->get_from_storage }; >+ is( >+ $@, '', >+ "Module $module with $polymorphic_field=$type_value should have koha_object[s]_class method if needed" >+ ); >+ } >+ >+ # Test class loading >+ my $object_class = Koha::Object::_get_object_class( $object->_result->result_class ); >+ eval "require $object_class"; >+ is( $@, '', "Module $object_class should be defined" ); >+ >+ my $objects_class = Koha::Objects::_get_objects_class( $object->_result->result_class ); >+ eval "require $objects_class"; >+ is( $@, '', "Module $objects_class should be defined" ); >+ } >+ } else { >+ >+ # Regular class >+ my $object = $builder->build_object( { class => $module } ); >+ is( ref($object), $module->object_class, "Testing $module" ); >+ >+ if ( !grep { $module eq $_ } qw( Koha::Old::Patrons Koha::Statistics ) ) >+ { # FIXME deletedborrowers and statistics do not have a PK >+ eval { $object->get_from_storage }; >+ is( $@, '', "Module $module should have koha_object[s]_class method if needed" ); >+ } >+ >+ # Testing koha_object_class and koha_objects_class >+ my $object_class = Koha::Object::_get_object_class( $object->_result->result_class ); >+ eval "require $object_class"; >+ is( $@, '', "Module $object_class should be defined" ); >+ my $objects_class = Koha::Objects::_get_objects_class( $object->_result->result_class ); >+ eval "require $objects_class"; >+ is( $@, '', "Module $objects_class should be defined" ); > } >- >- # Testing koha_object_class and koha_objects_class >- my $object_class = Koha::Object::_get_object_class( $object->_result->result_class ); >- eval "require $object_class"; >- is( $@, '', "Module $object_class should be defined" ); >- my $objects_class = Koha::Objects::_get_objects_class( $object->_result->result_class ); >- eval "require $objects_class"; >- is( $@, '', "Module $objects_class should be defined" ); > } > }; > >-- >2.48.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39190
:
178555
|
178556
|
178557
|
178558
|
178559
|
178560
|
178561
|
178562
|
178563
|
178564
|
178565
|
178566
|
178567
|
178568
|
178569
|
178570
|
178571
|
179252
|
179253
|
179254
|
179255
|
179256
|
179257
|
179258
|
179259
|
179260
|
179261
|
179262
|
179263
|
179264
|
179265
|
179266
|
179267
|
179268
|
179396
|
179397
|
179398
|
179399
|
179400
|
179401
|
179402
|
179403
|
179404
|
179405
|
179406
|
179407
|
179408
|
179409
|
179410
|
179411
|
179412
|
179413
|
179589
|
179590
|
179591
|
179592
|
179593
|
179594
|
179595
|
179596
|
179597
|
179598
|
179599
|
179600
|
179601
|
179602
|
179603
|
179604
|
179605
|
179606
|
179646
|
179647
|
179648
|
179649
|
179650
|
179651
|
179652
|
179653
|
179654
|
179655
|
179656
|
179657
|
179658
|
179659
|
179660
|
179661
|
179662
|
179663
|
179992
|
179993
|
179994
|
179995
|
179996
|
179997
|
179998
|
179999
|
180000
|
180001
|
180002
|
180003
|
180004
|
180005
|
180006
|
180010
|
180011
|
180012
|
180013
|
180014
|
180015
|
180016
|
180017
|
180018
|
180019
|
180020
|
180021
|
180022
|
180023
|
180024
|
180025