@@ -, +, @@ into the C4/Context.pm in two new subroutines. --- C4/Context.pm | 25 +++++++++++++++++++++++++ admin/env_tz_test.pl | 5 +++-- t/db_dependent/Context.t | 25 ++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 3 deletions(-) --- a/C4/Context.pm +++ a/C4/Context.pm @@ -821,6 +821,31 @@ sub _new_queryparser { return; } + +=head2 get_env_variables +my $tz_sth = C4::Context->get_env_variables(); + +This subroutine retrieves and returns all variable records where variable=time_zone +=cut + +sub get_env_variables { + my $dbh = C4::Context->dbh; + my $tz_sth = $dbh->prepare("SHOW VARIABLES LIKE 'time_zone'"); + return $tz_sth; +} + +=head2 get_current_time +my $now_sth = C4::Context->get_current_time(); + +This subroutine retrieves and returns the current time +=cut + +sub get_current_time { + my $dbh = C4::Context->dbh; + my $current_time = $dbh->prepare("SELECT now()"); + return $current_time; +} + =head2 userenv C4::Context->userenv; --- a/admin/env_tz_test.pl +++ a/admin/env_tz_test.pl @@ -21,9 +21,10 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user( ); my $dbh = C4::Context->dbh; -my $tz_sth = $dbh->prepare("SHOW VARIABLES LIKE 'time_zone'"); +my $tz_sth = C4::Context->get_env_variables(); $tz_sth->execute(); -my $now_sth = $dbh->prepare("SELECT now()"); + +my $now_sth = C4::Context->get_current_time(); $now_sth->execute(); print $q->header(), --- a/t/db_dependent/Context.t +++ a/t/db_dependent/Context.t @@ -7,8 +7,9 @@ use Test::More; use Test::MockModule; use vars qw($debug $koha $dbh $config $ret); use t::lib::Mocks; - +use Test::More tests => 41; use Koha::Database; +use DateTime; BEGIN { $debug = $ENV{DEBUG} || 0; @@ -135,6 +136,28 @@ C4::Context->set_preference('AutoEmailOpacUser', ''); my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser'); is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' ); + +sub get_env_variables { + my $sth = $dbh->prepare("SHOW VARIABLES LIKE 'time_zone'"); + $sth->execute(); + return $sth->rows; +} +my $env_var = get_env_variables(); +is($env_var, 1, "correct number of variables like time_zone"); + +sub get_current_time { + my $sth = $dbh->prepare("SELECT now()"); + $sth->execute(); + return $sth->fetchrow_array;# Return a time value rather than hash value +} +my $datetime = DateTime->now; +my $date = $datetime->ymd; +my $time = $datetime->hms; +my $compardt = "$date $time"; + +my $current_time = get_current_time(); +is($current_time, $compardt, "Correct time"); + done_testing(); sub TransformVersionToNum { --