From 5c0d8923f8ca1b29c87a5c04ea51b0b4431e85a7 Mon Sep 17 00:00:00 2001 From: Guillaume Viguier Date: Sat, 13 Mar 2010 17:01:58 -0500 Subject: [PATCH] Date and time management; tests - Chamilo - CT#696 --- .../inc/lib/internationalization.lib.test.php | 33 ++++++++++++++++++- tests/test_suite.php | 4 +-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/main/inc/lib/internationalization.lib.test.php b/tests/main/inc/lib/internationalization.lib.test.php index 9ed789edeb..183068952b 100755 --- a/tests/main/inc/lib/internationalization.lib.test.php +++ b/tests/main/inc/lib/internationalization.lib.test.php @@ -1384,6 +1384,37 @@ class TestInternationalization extends UnitTestCase { } //var_dump('
'.$res.'
'); } + + public function test_api_get_local_time_with_datetime() { + $datetime_not_converted = '2010-03-13 16:24:02'; + $datetime_gmtplus1 = api_get_local_time($datetime_not_converted, 'Europe/Paris', 'America/Lima'); + $this->assertEqual($datetime_gmtplus1, '2010-03-13 22:24:02'); + } + + public function test_api_get_local_time_with_timestamp() { + $current_timestamp = time(); + $datetime = api_get_local_time($current_timestamp, 'Europe/Paris'); + $system_timezone = date_default_timezone_get(); + date_default_timezone_set('Europe/Paris'); + $this->assertEqual($datetime, date('Y-m-d H:i:s', $current_timestamp)); + date_default_timezone_set($system_timezone); + } + + public function test_api_get_utc_datetime_with_string() { + $timestamp = time(); + $timezone = _api_get_timezone(); + $system_timezone = date_default_timezone_get(); + date_default_timezone_set($timezone); + $datetime = date('Y-m-d H:i:s', $timestamp); + $datetime_utc = api_get_utc_datetime($datetime); + $this->assertEqual($datetime_utc, gmdate('Y-m-d H:i:s', $timestamp)); + date_default_timezone_set($system_timezone); + } + + public function test_api_get_utc_datetime_with_timestamp() { + $timestamp = time(); + $this->assertEqual(api_get_utc_datetime($timestamp), gmdate("Y-m-d H:i:s", $timestamp)); + } /* // Enable the following test when you need to run it. @@ -1485,4 +1516,4 @@ function test_get_language_folder_list() { return $result; } -?> \ No newline at end of file +?> diff --git a/tests/test_suite.php b/tests/test_suite.php index 13778714b7..7213c87e2a 100755 --- a/tests/test_suite.php +++ b/tests/test_suite.php @@ -139,9 +139,9 @@ class TestsSuite extends TestSuite { $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/usermanager.lib.test.php'); $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/groupmanager.lib.test.php'); $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/image.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/import.lib.test.php'); + $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/import.lib.test.php');*/ $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/internationalization.lib.test.php'); - $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/system_announcements.lib.test.php'); + /*$this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/system_announcements.lib.test.php'); $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/fileUpload.lib.test.php'); $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/main_api.lib.test.php');//this file delete the course $this->addFile(api_get_path(SYS_TEST_PATH).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests