summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-11-24 16:37:04 +0100
committerJoas Schilling <nickvergessen@gmx.de>2014-12-10 11:58:56 +0100
commit4d232e536eb03895863c0d7d7fe703c41d433f70 (patch)
tree2adb86d986c986f4c34fac9fedb287f9a51191d5 /tests
parent681caf882a5f28b0b6f7cb9a1f16b3dea26ff5f2 (diff)
downloadnextcloud-server-4d232e536eb03895863c0d7d7fe703c41d433f70.tar.gz
nextcloud-server-4d232e536eb03895863c0d7d7fe703c41d433f70.zip
Deprecate Util::formatDate()
Make DateTimeFormatter a service and adjust tests that have been inaccurate
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/template.php20
-rw-r--r--tests/lib/util.php16
2 files changed, 24 insertions, 12 deletions
diff --git a/tests/lib/template.php b/tests/lib/template.php
index d77284a5bf2..db58238eae8 100644
--- a/tests/lib/template.php
+++ b/tests/lib/template.php
@@ -117,15 +117,15 @@ class Test_TemplateFunctions extends \Test\TestCase {
public function testRelativeDateMonthsAgo(){
$currentTime = 1380703592;
- $elementTime = $currentTime - 86400 * 60;
+ $elementTime = $currentTime - 86400 * 65;
$result = (string)relative_modified_date($elementTime, $currentTime, true);
$this->assertEquals('2 months ago', $result);
- $elementTime = $currentTime - 86400 * 65;
+ $elementTime = $currentTime - 86400 * 130;
$result = (string)relative_modified_date($elementTime, $currentTime, true);
- $this->assertEquals('2 months ago', $result);
+ $this->assertEquals('4 months ago', $result);
}
public function testRelativeDateLastYear(){
@@ -146,12 +146,12 @@ class Test_TemplateFunctions extends \Test\TestCase {
$elementTime = $currentTime - 86400 * 365.25 * 2;
$result = (string)relative_modified_date($elementTime, $currentTime, true);
- $this->assertEquals('years ago', $result);
+ $this->assertEquals('2 years ago', $result);
$elementTime = $currentTime - 86400 * 365.25 * 3;
$result = (string)relative_modified_date($elementTime, $currentTime, true);
- $this->assertEquals('years ago', $result);
+ $this->assertEquals('3 years ago', $result);
}
// ---------------------------------------------------------------------------
@@ -211,15 +211,15 @@ class Test_TemplateFunctions extends \Test\TestCase {
public function testRelativeTimeMonthsAgo(){
$currentTime = 1380703592;
- $elementTime = $currentTime - 86400 * 60;
+ $elementTime = $currentTime - 86400 * 65;
$result = (string)relative_modified_date($elementTime, $currentTime, false);
$this->assertEquals('2 months ago', $result);
- $elementTime = $currentTime - 86400 * 65;
+ $elementTime = $currentTime - 86400 * 130;
$result = (string)relative_modified_date($elementTime, $currentTime, false);
- $this->assertEquals('2 months ago', $result);
+ $this->assertEquals('4 months ago', $result);
}
public function testRelativeTimeLastYear(){
@@ -240,11 +240,11 @@ class Test_TemplateFunctions extends \Test\TestCase {
$elementTime = $currentTime - 86400 * 365.25 * 2;
$result = (string)relative_modified_date($elementTime, $currentTime, false);
- $this->assertEquals('years ago', $result);
+ $this->assertEquals('2 years ago', $result);
$elementTime = $currentTime - 86400 * 365.25 * 3;
$result = (string)relative_modified_date($elementTime, $currentTime, false);
- $this->assertEquals('years ago', $result);
+ $this->assertEquals('3 years ago', $result);
}
}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 3bb4b47c09c..1a2cb09f38d 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -41,7 +41,7 @@ class Test_Util extends \Test\TestCase {
date_default_timezone_set("UTC");
$result = OC_Util::formatDate(1350129205, false, 'Europe/Berlin');
- $expected = 'October 13, 2012 at 1:53:25 PM GMT+0';
+ $expected = 'October 13, 2012 at 1:53:25 PM GMT+2';
$this->assertEquals($expected, $result);
}
@@ -55,10 +55,22 @@ class Test_Util extends \Test\TestCase {
function testFormatDateWithTZFromSession() {
date_default_timezone_set("UTC");
+ $oldDateTimeFormatter = \OC::$server->query('DateTimeFormatter');
\OC::$server->getSession()->set('timezone', 3);
+ $newDateTimeFormatter = new \OC\DateTimeFormatter(\OC::$server->getTimeZone(), new \OC_L10N('lib', 'en'));
+ $this->setDateFormatter($newDateTimeFormatter);
+
$result = OC_Util::formatDate(1350129205, false);
- $expected = 'October 13, 2012 at 2:53:25 PM GMT+0';
+ $expected = 'October 13, 2012 at 2:53:25 PM GMT+3';
$this->assertEquals($expected, $result);
+
+ $this->setDateFormatter($oldDateTimeFormatter);
+ }
+
+ protected function setDateFormatter($formatter) {
+ \OC::$server->registerService('DateTimeFormatter', function ($c) use ($formatter) {
+ return $formatter;
+ });
}
function testCallRegister() {