Bugzilla – Attachment 185994 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: Regression tests for polymorphic object creation
Bug-39190-Regression-tests-for-polymorphic-object-.patch (text/plain), 5.51 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-08-30 15:35:44 UTC
(
hide
)
Description:
Bug 39190: Regression tests for polymorphic object creation
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-08-30 15:35:44 UTC
Size:
5.51 KB
patch
obsolete
>From b87d9be073a1be785bf3b8f3d2bb9de702b47218 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Sat, 30 Aug 2025 11:49:15 -0300 >Subject: [PATCH] Bug 39190: Regression tests for polymorphic object creation > >This patch adds comprehensive tests to verify that Koha::File::Transports >correctly returns polymorphic objects based on the transport field value. > >The tests cover: >- build_object() polymorphic creation >- search() with polymorphic resultset iteration >- find() with polymorphic object return > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/Koha/File/Transports.t >=> FAIL: Tests fail - objects return base Koha::File::Transport > instead of polymorphic Koha::File::Transport::SFTP/FTP classes > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/File/Transports.t | 153 ++++++++++++++++++++++++++ > 1 file changed, 153 insertions(+) > create mode 100755 t/db_dependent/Koha/File/Transports.t > >diff --git a/t/db_dependent/Koha/File/Transports.t b/t/db_dependent/Koha/File/Transports.t >new file mode 100755 >index 00000000000..21fb5f9cc08 >--- /dev/null >+++ b/t/db_dependent/Koha/File/Transports.t >@@ -0,0 +1,153 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 4; >+use Test::NoWarnings; >+ >+use Koha::Database; >+use Koha::File::Transports; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'Polymorphic object creation' => sub { >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ # Test SFTP transport polymorphism >+ my $sftp_transport = $builder->build_object( >+ { >+ class => 'Koha::File::Transports', >+ value => { >+ transport => 'sftp', >+ name => 'Test SFTP', >+ host => 'test.example.com', >+ } >+ } >+ ); >+ >+ is( >+ ref($sftp_transport), 'Koha::File::Transport::SFTP', >+ 'SFTP transport should be polymorphic Koha::File::Transport::SFTP object' >+ ); >+ >+ can_ok( $sftp_transport, '_write_key_file' ); >+ >+ # Test FTP transport polymorphism >+ my $ftp_transport = $builder->build_object( >+ { >+ class => 'Koha::File::Transports', >+ value => { >+ transport => 'ftp', >+ name => 'Test FTP', >+ host => 'ftp.example.com', >+ } >+ } >+ ); >+ >+ is( >+ ref($ftp_transport), 'Koha::File::Transport::FTP', >+ 'FTP transport should be polymorphic Koha::File::Transport::FTP object' >+ ); >+ >+ can_ok( $ftp_transport, 'connect' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'search() tests' => sub { >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ # Create test transports >+ my $sftp_transport = $builder->build_object( >+ { >+ class => 'Koha::File::Transports', >+ value => { transport => 'sftp', name => 'Test SFTP' } >+ } >+ ); >+ my $ftp_transport = $builder->build_object( >+ { >+ class => 'Koha::File::Transports', >+ value => { transport => 'ftp', name => 'Test FTP' } >+ } >+ ); >+ >+ # Search for both transports >+ my $transports = Koha::File::Transports->search( { id => { -in => [ $sftp_transport->id, $ftp_transport->id ] } } ); >+ >+ is( >+ ref($transports), 'Koha::File::Transports', >+ 'search() should return Koha::File::Transports object' >+ ); >+ >+ # Check each object type from resultset >+ my @objects = $transports->as_list; >+ my %refs = map { $_->transport => ref($_) } @objects; >+ >+ is( >+ $refs{sftp}, 'Koha::File::Transport::SFTP', >+ 'SFTP object from search should be polymorphic' >+ ); >+ is( >+ $refs{ftp}, 'Koha::File::Transport::FTP', >+ 'FTP object from search should be polymorphic' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'find() tests' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ # Create test transports >+ my $sftp_transport = $builder->build_object( >+ { >+ class => 'Koha::File::Transports', >+ value => { transport => 'sftp', name => 'Test SFTP' } >+ } >+ ); >+ my $ftp_transport = $builder->build_object( >+ { >+ class => 'Koha::File::Transports', >+ value => { transport => 'ftp', name => 'Test FTP' } >+ } >+ ); >+ >+ # Test find() returns correct polymorphic types >+ my $found_sftp = Koha::File::Transports->find( $sftp_transport->id ); >+ my $found_ftp = Koha::File::Transports->find( $ftp_transport->id ); >+ >+ is( >+ ref($found_sftp), 'Koha::File::Transport::SFTP', >+ 'find() should return polymorphic SFTP object' >+ ); >+ is( >+ ref($found_ftp), 'Koha::File::Transport::FTP', >+ 'find() should return polymorphic FTP object' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.51.0
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
|
185014
|
185015
|
185016
|
185017
|
185018
|
185019
|
185020
|
185021
|
185022
|
185023
|
185024
|
185025
|
185026
|
185027
|
185028
|
185029
|
185972
|
185973
|
185974
|
185975
|
185976
|
185977
|
185978
|
185979
|
185980
|
185981
|
185982
|
185983
|
185984
|
185985
|
185986
|
185987
|
185988
|
185989
|
185990
| 185994 |
185995
|
185996
|
185997
|
185998