Bugzilla – Attachment 42784 Details for
Bug 10337
Add a script to insert all sample data automatically
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10337: Unit tests is based on an existing database
Bug-10337-Unit-tests-is-based-on-an-existing-datab.patch (text/plain), 4.92 KB, created by
Jonathan Druart
on 2015-09-22 13:21:36 UTC
(
hide
)
Description:
Bug 10337: Unit tests is based on an existing database
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-09-22 13:21:36 UTC
Size:
4.92 KB
patch
obsolete
>From 78d870bb6c25d28e4e199d0a7698d4c3026bbd91 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Fri, 24 May 2013 16:46:24 +0200 >Subject: [PATCH] Bug 10337: Unit tests is based on an existing database > >This patchs adds a new unit tests file which will launched before all >others db_dependent tests. >It will drop and recreate the database with sample data. > >Prerequisite: >The database 'koha_ut' have to be created with > CREATE DATABASE $dbname CHARACTER SET utf8 COLLATE utf8_bin >--- > t/db_dependent/000-init_db.t | 115 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 115 insertions(+) > create mode 100644 t/db_dependent/000-init_db.t > >diff --git a/t/db_dependent/000-init_db.t b/t/db_dependent/000-init_db.t >new file mode 100644 >index 0000000..8916dd6 >--- /dev/null >+++ b/t/db_dependent/000-init_db.t >@@ -0,0 +1,115 @@ >+use Modern::Perl; >+use Test::More tests => 37; >+ >+use C4::Context; >+use t::lib::Mocks; >+ >+t::lib::Mocks::mock_config('database', 'koha_ut'); >+ >+ >+my $koha_structure_file = C4::Context->config('intranetdir') . '/installer/data/mysql/kohastructure.sql'; >+my $sample_files_optional = C4::Context->config('intranetdir') . '/installer/data/mysql/en/optional/*.sql'; >+my $sample_files_mandatory = C4::Context->config('intranetdir') . '/installer/data/mysql/en/mandatory/*.sql'; >+my $marc21_sample_files_mandatory = C4::Context->config('intranetdir') . '/installer/data/mysql/en/marcflavour/marc21/*/*.sql'; >+my $unimarc_sample_files_mandatory = C4::Context->config('intranetdir') . '/installer/data/mysql/en/marcflavour/unimarc/mandatory/*.sql'; >+my $sample_only_param_tables = C4::Context->config('intranetdir') . '/installer/data/mysql/sample_only_param_tables.sql'; >+my $sysprefs = C4::Context->config('intranetdir') . '/installer/data/mysql/sysprefs.sql'; >+my $subtag_registry = C4::Context->config('intranetdir') . '/installer/data/mysql/mandatory/subtag_registry.sql'; >+ >+my $version = get_version(); >+ >+our $dbh = C4::Context->dbh; >+our $user = C4::Context->config('user'); >+our $pass = C4::Context->config('pass'); >+our $dbname = C4::Context->config("database"); >+ >+# TODO All unit tests launch after this one should use the same database name >+# instead of the dbname defined in the $KOHA_CONF file >+# We have to mock C4::Context->config('database') with koha_ut everywhere >+die q{The SQL database name should be 'koha_ut'} >+ if $dbname ne 'koha_ut'; >+ >+recreate_db( $dbname ); >+# Force C4::Context to recreate a new db handler >+$dbh->disconnect; >+$dbh = C4::Context->dbh; >+initialize_data(); >+update_database(); >+ >+ >+# We can't insert unimarc AND marc21 files >+#for my $f ( glob $unimarc_sample_files_mandatory ) { >+# execute_sqlfile( $f, "inserting $f"); >+#} >+ >+ >+# FIXME This file crashes >+#execute_sqlfile( $sample_only_param_tables, "inserting $sample_only_param_tables" ); >+ >+sub recreate_db { >+ my $dbname = shift; >+ ok( $dbh->do(qq{ >+ DROP DATABASE $dbname >+ }), "drop database $dbname" ); >+ >+ is( $dbh->do(qq{ >+ CREATE DATABASE $dbname CHARACTER SET utf8 COLLATE utf8_bin >+ }), 1, "create database $dbname" ); >+} >+ >+sub initialize_data { >+ execute_sqlfile( $koha_structure_file, "inserting koha db structure" ); >+ >+ for my $f ( glob $sample_files_mandatory ) { >+ execute_sqlfile( $f, "inserting $f"); >+ } >+ >+ >+ for my $f ( glob $sample_files_optional ) { >+ execute_sqlfile( $f, "inserting $f"); >+ } >+ >+ for my $f ( glob $marc21_sample_files_mandatory ) { >+ execute_sqlfile( $f, "inserting $f"); >+ } >+ execute_sqlfile( $sysprefs, "inserting $sysprefs"); >+ execute_sqlfile( $subtag_registry, "inserting $subtag_registry"); >+ >+ # set marcflavour (MARC21) >+ $dbh->do( q{ >+ INSERT INTO `systempreferences` (variable,value,explanation,options,type) >+ VALUES ('marcflavour','MARC21','Define global MARC flavor (MARC21 or UNIMARC) used for character encoding','MARC21|UNIMARC','Choice') >+ } ); >+ >+ # set version >+ $dbh->do( qq{ >+ INSERT INTO systempreferences(variable, value, options, explanation, type) >+ VALUES ('Version', '$version', NULL, 'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller', NULL) >+ } ); >+} >+ >+sub execute_sqlfile { >+ my ( $filepath, $msg ) = @_; >+ is( system( qq{/usr/bin/mysql -u $user -p'$pass' -D $dbname < $filepath} ), 0, $msg ); >+} >+ >+sub get_version { >+ do C4::Context->config('intranetdir') . '/kohaversion.pl'; >+ my $version = kohaversion(); >+ $version =~ s/(\d)\.(\d{2})\.(\d{2})\.(\d{3})/$1.$2$3$4/; >+ return $version; >+} >+ >+sub update_database { >+ my $src_path = C4::Context->config('intranetdir'); >+ my $update_db_path = $src_path . '/installer/data/mysql/updatedatabase.pl'; >+ >+ my $file = `cat $update_db_path`; >+ $file =~ s/exit;//; >+ eval $file; >+ if ($@) { >+ fail("updatedatabase.pl process failed: $@"); >+ } else { >+ pass("updatedatabase.pl process succeeded."); >+ } >+} >-- >2.1.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 10337
:
18389
|
18390
|
42784
|
56607
|
56614
|
56621
|
56622
|
56625