From 227d5604db6cc830bf644c7e5d65c43befbd85d5 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 28 Jun 2023 12:07:46 +0000 Subject: [PATCH] Bug 33537: Add better named table_exists alias in Installer module Content-Type: text/plain; charset=utf-8 Test plan: Run dbrev later. It is using table_exists. Run t/db_dependent/Installer.t Signed-off-by: Marcel de Rooy --- C4/Installer.pm | 8 ++++++-- t/db_dependent/Installer.t | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index 7e248a17aa..1a2d93e82c 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -34,7 +34,7 @@ use vars qw(@ISA @EXPORT); BEGIN { require Exporter; @ISA = qw( Exporter ); - push @EXPORT, qw( primary_key_exists unique_key_exists foreign_key_exists index_exists column_exists TableExists marc_framework_sql_list TransformToNum CheckVersion NewVersion SetVersion sanitize_zero_date update get_db_entries get_atomic_updates run_atomic_updates has_non_dynamic_row_format ); + push @EXPORT, qw( primary_key_exists unique_key_exists foreign_key_exists index_exists column_exists TableExists table_exists marc_framework_sql_list TransformToNum CheckVersion NewVersion SetVersion sanitize_zero_date update get_db_entries get_atomic_updates run_atomic_updates has_non_dynamic_row_format ); }; =head1 NAME @@ -686,7 +686,7 @@ sub column_exists { return $exists; } -sub TableExists { # Could be renamed table_exists for consistency +sub TableExists { # Legacy name my $table = shift; eval { my $dbh = C4::Context->dbh; @@ -698,6 +698,10 @@ sub TableExists { # Could be renamed table_exists for consistency return 0; } +sub table_exists { # More consistently named alias for TableExists + return TableExists(@_); +} + sub version_from_file { my $file = shift; return unless $file =~ m|(^\|/)(\d{2})(\d{2})(\d{2})(\d{3}).pl$|; diff --git a/t/db_dependent/Installer.t b/t/db_dependent/Installer.t index 2e9c0e26c8..5f21b10822 100755 --- a/t/db_dependent/Installer.t +++ b/t/db_dependent/Installer.t @@ -18,18 +18,18 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -# This Koha test module is still a stub! -# Add more tests here!!! - use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 23; use File::Temp qw(tempfile); use utf8; use Koha::Database; BEGIN { - use_ok('C4::Installer', qw( column_exists index_exists unique_key_exists foreign_key_exists primary_key_exists marc_framework_sql_list )); + use_ok( + 'C4::Installer', + qw( column_exists index_exists unique_key_exists foreign_key_exists primary_key_exists marc_framework_sql_list table_exists ) + ); } ok( my $installer = C4::Installer->new(), 'Testing NewInstaller' ); @@ -77,6 +77,12 @@ ok( primary_key_exists( 'borrowers' ), 'Borrowers does have a primary key on som ok( primary_key_exists( 'borrowers', 'borrowernumber'), 'Borrowers has primary key on borrowernumber'); ok( ! primary_key_exists( 'borrowers', 'email'), 'Borrowers does not have a primary key on email'); +subtest 'table_exists' => sub { + plan tests => 2; + is( table_exists( 'borrowers' ), 1, 'Table borrowers still exists ;)' ); + is( table_exists( 'this_table_will_never_exist' ), 0, 'This table does not exist, not likely to be created too' ); +}; + subtest 'marc_framework_sql_list' => sub { plan tests => 1; -- 2.30.2