diff --git a/LedgerSMB/Database.pm b/LedgerSMB/Database.pm index 245cf907db..e6be85ca22 100644 --- a/LedgerSMB/Database.pm +++ b/LedgerSMB/Database.pm @@ -58,13 +58,6 @@ sub new { if ($self->{source_dir}){ $self->{source_dir} =~ s/\/*$/\//; } - if (isa($args, 'LedgerSMB')){ - for (keys %$args){ - if ($_ =~ /^_/){ - $self->{$_} = $args->{$_}; - } - } - } bless $self, $class; return $self; } @@ -90,16 +83,16 @@ sub create { for my $contrib (@contrib_scripts){ my $rc2; - $rc2=system("psql -f $ENV{PG_CONTRIB_DIR}/$contrib.sql >>$temp/dblog"); + $rc2=system("psql -f $ENV{PG_CONTRIB_DIR}/$contrib.sql 2>>$temp/dblog"); $rc ||= $rc2 } - if (!system("psql -f $self->{source_dir}sql/Pg-database.sql >> $temp/dblog" + if (!system("psql -f $self->{source_dir}sql/Pg-database.sql 2>>$temp/dblog" )){ $rc = 1; } # TODO Add logging of errors/notices - return !$rc; + return $rc; } =item $db->load_modules($loadorder) @@ -184,7 +177,7 @@ sub process_roles { close ROLES; close TROLES; - $self->exec_script({script => "sql/modules/$rolefile", + $self->exec_script({script => "$temp/lsmb_roles.sql", log => "$temp/dblog"}); } diff --git a/README.tests b/README.tests index e05624eb93..af878b5865 100644 --- a/README.tests +++ b/README.tests @@ -13,10 +13,10 @@ Environment variables can be used as flags to disable/enable tests >= 40 LSMB_TEST_DB must be set to a defined value if databases are going to be tested. -if LSMB_NEW_DB is set, test 40 (when it is complete) will create a database with -the name from this environment variable, and subsequent database tests will run -against that database. If this is not set, and PGDATABASE is set, tests will -run on that database. If neither are set, the tests will bail out. +if LSMB_NEW_DB is set, test 40 will create a database with the name from this +environment variable, and subsequent database tests will run against that +database. If this is not set, and PGDATABASE is set, tests will run on that +database. If neither are set, the tests will bail out. Special notes on specific test cases: @@ -75,7 +75,7 @@ LSMB_ADMIN_PASSWORD password for admin user Chart of accounts loading ------------------------- - LSMB_LOAD_COA name of the Chart of Accounts file (minus the extension) - LSMB_LOAD_GIFI name of the GIFI file (minus the extension) + LSMB_LOAD_COA name of the Chart of Accounts file, not including extension + LSMB_LOAD_GIFI name of the GIFI file, not including extension LSMB_COUNTRY_CODE Country code for administrator and for loading chart of accounts diff --git a/t/40-dbsetup.t b/t/40-dbsetup.t index 0b4ddef5be..28fa1020fe 100644 --- a/t/40-dbsetup.t +++ b/t/40-dbsetup.t @@ -23,7 +23,7 @@ for my $evar (qw(LSMB_NEW_DB LSMB_TEST_DB PG_CONTRIB_DIR)){ } if ($run_tests){ - plan tests => 35; + plan tests => 10; $ENV{PGDATABASE} = $ENV{LSMB_NEW_DB}; } @@ -49,13 +49,13 @@ if (!$ENV{LSMB_INSTALL_DB}){ close (DBLOCK); } -ok($db->process_roles('Roles.sql'), 'Roles processed'); +is($db->process_roles('Roles.sql'), 0, 'Roles processed'); #Changed the COA and GIFI loading to use this, and move admin user to #Database.pm --CT SKIP: { - skip 'No admin info', 4 + skip 'No admin info', 5 if (!defined $ENV{LSMB_ADMIN_USERNAME} or !defined $ENV{LSMB_ADMIN_PASSWORD} or !defined $ENV{LSMB_COUNTRY_CODE} @@ -78,9 +78,8 @@ SKIP: { last_name => $ENV{LSMB_ADMIN_LNAME}, country_id => $ref->{id}, }); - my ($var) = $sth->fetchrow_array(); - cmp_ok($var, '>', 0, 'User id retrieved'); - $sth->finish; + my $user = LedgerSMB::DBObject::Admin->new({base => $lsmb}); + ok($user->save); $sth = $dbh->prepare("SELECT admin__add_user_to_role(?, ?)"); my $rolename = "lsmb_" . $ENV{PGDATABASE} . "__users_manage"; ok($sth->execute($ENV{LSMB_ADMIN_USERNAME}, $rolename), @@ -90,18 +89,20 @@ SKIP: { }; SKIP: { - skip 'No COA specified', 2 if !defined $ENV{LSMB_LOAD_COA}; - ok($db->exec_script('sql/coa/' - . lc($ENV{LSMB_COUNTRY_CODE}) - ."/chart/$ENV{LSMB_LOAD_COA}.sql"), + skip 'No COA specified', 1 if !defined $ENV{LSMB_LOAD_COA}; + is($db->exec_script({script => 'sql/coa/' + . lc($ENV{LSMB_COUNTRY_CODE}) + ."/chart/$ENV{LSMB_LOAD_COA}.sql" + }), 0, 'Ran Chart of Accounts Script'); } SKIP: { - skip 'No GIFI specified', 2 if !defined $ENV{LSMB_LOAD_GIFI}; - ok($db->exec_script('sql/coa/' - . lc($ENV{LSMB_COUNTRY_CODE}) - ."/chart/$ENV{LSMB_LOAD_GIFI}.sql"), + skip 'No GIFI specified', 1 if !defined $ENV{LSMB_LOAD_GIFI}; + is($db->exec_script({script => 'sql/coa/' + . lc($ENV{LSMB_COUNTRY_CODE}) + ."/gifi/$ENV{LSMB_LOAD_GIFI}.sql" + }), 0, 'Ran GIFI Script'); }