From c24a67a28d5cd10b5dc10e17f20ea575f15339fc Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 24 Aug 2022 12:42:33 +0000 Subject: [PATCH] Bug 30571: Z3950Servers.t - Create subtest for existing tests No real changes, just moving code and indentation. Ground work for following patch. Test plan: To let the test pass, disable strict_mode in koha-conf. Run perl t/db_dependent/Koha/Z3950Servers.t. Should pass now. However, in strict mode or with prove, it should fail. Run prove t/db_dependent/Koha/Z3950Servers.t. Failed? Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Z3950Servers.t | 71 +++++++++++++++--------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/t/db_dependent/Koha/Z3950Servers.t b/t/db_dependent/Koha/Z3950Servers.t index 9714cb4599..282f982db8 100755 --- a/t/db_dependent/Koha/Z3950Servers.t +++ b/t/db_dependent/Koha/Z3950Servers.t @@ -18,44 +18,45 @@ # along with Koha; if not, see . use Modern::Perl; +use Test::More tests => 1; -use Test::More tests => 4; - +use t::lib::TestBuilder; +use Koha::Database; use Koha::Z3950Server; use Koha::Z3950Servers; -use Koha::Database; - -use t::lib::TestBuilder; my $schema = Koha::Database->new->schema; -$schema->storage->txn_begin; - my $builder = t::lib::TestBuilder->new; -my $nb_of_z39s = Koha::Z3950Servers->search->count; -my $new_z39_1 = Koha::Z3950Server->new({ - host => 'my_host1.org', - port => '32', - db => 'db1', - servername => 'my_test_1', - servertype => 'zed', - recordtype => 'biblio', -})->store; -my $new_z39_2 = Koha::Z3950Server->new({ - host => 'my_host2.org', - port => '64', - db => 'db2', - servername => 'my_test_2', - servertype => 'zed', - recordtype => 'authority', -})->store; - -like( $new_z39_1->id, qr|^\d+$|, 'Adding a new z39 server should have set the id'); -is( Koha::Z3950Servers->search->count, $nb_of_z39s + 2, 'The 2 z39 servers should have been added' ); - -my $retrieved_z39_1 = Koha::Z3950Servers->find( $new_z39_1->id ); -is( $retrieved_z39_1->servername, $new_z39_1->servername, 'Find a z39 server by id should return the correct z39 server' ); - -$retrieved_z39_1->delete; -is( Koha::Z3950Servers->search->count, $nb_of_z39s + 1, 'Delete should have deleted the z39 server' ); - -$schema->storage->txn_rollback; + +subtest 'new, find and delete tests' => sub { + plan tests => 4; + $schema->storage->txn_begin; + my $nb_of_z39s = Koha::Z3950Servers->search->count; + my $new_z39_1 = Koha::Z3950Server->new({ + host => 'my_host1.org', + port => '32', + db => 'db1', + servername => 'my_test_1', + servertype => 'zed', + recordtype => 'biblio', + })->store; + my $new_z39_2 = Koha::Z3950Server->new({ + host => 'my_host2.org', + port => '64', + db => 'db2', + servername => 'my_test_2', + servertype => 'zed', + recordtype => 'authority', + })->store; + + like( $new_z39_1->id, qr|^\d+$|, 'Adding a new z39 server should have set the id'); + is( Koha::Z3950Servers->search->count, $nb_of_z39s + 2, 'The 2 z39 servers should have been added' ); + + my $retrieved_z39_1 = Koha::Z3950Servers->find( $new_z39_1->id ); + is( $retrieved_z39_1->servername, $new_z39_1->servername, 'Find a z39 server by id should return the correct z39 server' ); + + $retrieved_z39_1->delete; + is( Koha::Z3950Servers->search->count, $nb_of_z39s + 1, 'Delete should have deleted the z39 server' ); + + $schema->storage->txn_rollback; +}; -- 2.39.5