mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-03 22:53:58 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,20 +2,20 @@
|
|||
/**
|
||||
* CakeTimeTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||||
* @package Cake.Test.Case.View.Helper
|
||||
* @since CakePHP(tm) v 1.2.0.4206
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeTime', 'Utility');
|
||||
|
||||
/**
|
||||
|
@ -38,8 +38,10 @@ class CakeTimeTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Time = new CakeTime();
|
||||
$this->_systemTimezoneIdentifier = date_default_timezone_get();
|
||||
Configure::write('Config.language', 'eng');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,6 +50,7 @@ class CakeTimeTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
unset($this->Time);
|
||||
$this->_restoreSystemTimezone();
|
||||
}
|
||||
|
@ -69,13 +72,13 @@ class CakeTimeTest extends CakeTestCase {
|
|||
*/
|
||||
public function testToQuarter() {
|
||||
$result = $this->Time->toQuarter('2007-12-25');
|
||||
$this->assertEquals(4, $result);
|
||||
$this->assertSame(4, $result);
|
||||
|
||||
$result = $this->Time->toQuarter('2007-9-25');
|
||||
$this->assertEquals(3, $result);
|
||||
$this->assertSame(3, $result);
|
||||
|
||||
$result = $this->Time->toQuarter('2007-3-25');
|
||||
$this->assertEquals(1, $result);
|
||||
$this->assertSame(1, $result);
|
||||
|
||||
$result = $this->Time->toQuarter('2007-3-25', true);
|
||||
$this->assertEquals(array('2007-01-01', '2007-03-31'), $result);
|
||||
|
@ -105,9 +108,9 @@ class CakeTimeTest extends CakeTestCase {
|
|||
array('-2 days -3 hours', '2 days, 3 hours ago'),
|
||||
array('-1 week', '1 week ago'),
|
||||
array('-2 weeks -2 days', '2 weeks, 2 days ago'),
|
||||
array('+1 week', '1 week'),
|
||||
array('+1 week 1 day', '1 week, 1 day'),
|
||||
array('+2 weeks 2 day', '2 weeks, 2 days'),
|
||||
array('+1 week', 'in 1 week'),
|
||||
array('+1 week 1 day', 'in 1 week, 1 day'),
|
||||
array('+2 weeks 2 day', 'in 2 weeks, 2 days'),
|
||||
array('2007-9-24', 'on 24/9/07'),
|
||||
array('now', 'just now'),
|
||||
);
|
||||
|
@ -133,37 +136,37 @@ class CakeTimeTest extends CakeTestCase {
|
|||
return array(
|
||||
array(
|
||||
'+4 months +2 weeks +3 days',
|
||||
'4 months, 2 weeks, 3 days',
|
||||
'in 4 months, 2 weeks, 3 days',
|
||||
'8 years'
|
||||
),
|
||||
array(
|
||||
'+4 months +2 weeks +1 day',
|
||||
'4 months, 2 weeks, 1 day',
|
||||
'in 4 months, 2 weeks, 1 day',
|
||||
'8 years'
|
||||
),
|
||||
array(
|
||||
'+3 months +2 weeks',
|
||||
'3 months, 2 weeks',
|
||||
'in 3 months, 2 weeks',
|
||||
'8 years'
|
||||
),
|
||||
array(
|
||||
'+3 months +2 weeks +1 day',
|
||||
'3 months, 2 weeks, 1 day',
|
||||
'in 3 months, 2 weeks, 1 day',
|
||||
'8 years'
|
||||
),
|
||||
array(
|
||||
'+1 months +1 week +1 day',
|
||||
'1 month, 1 week, 1 day',
|
||||
'in 1 month, 1 week, 1 day',
|
||||
'8 years'
|
||||
),
|
||||
array(
|
||||
'+2 months +2 days',
|
||||
'2 months, 2 days',
|
||||
'in 2 months, 2 days',
|
||||
'on ' . date('j/n/y', strtotime('+2 months +2 days'))
|
||||
),
|
||||
array(
|
||||
'+2 months +12 days',
|
||||
'2 months, 1 week, 5 days',
|
||||
'in 2 months, 1 week, 5 days',
|
||||
'3 months'
|
||||
),
|
||||
);
|
||||
|
@ -182,6 +185,34 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the custom string options for timeAgoInWords
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTimeAgoInWordsCustomStrings() {
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('-8 years -4 months -2 weeks -3 days'),
|
||||
array('relativeString' => 'at least %s ago', 'accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
||||
);
|
||||
$expected = 'at least 8 years ago';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+8 years +4 months +2 weeks +3 days'),
|
||||
array('relativeStringFuture' => 'not in the next %s', 'accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
||||
);
|
||||
$expected = 'not in the next 8 years';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+4 months +2 weeks +3 days'),
|
||||
array('absoluteString' => 'exactly on %s', 'accuracy' => array('year' => 'year'), 'end' => '+2 months')
|
||||
);
|
||||
$expected = 'exactly on ' . date('j/n/y', strtotime('+4 months +2 weeks +3 days'));
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the accuracy option for timeAgoInWords()
|
||||
*
|
||||
|
@ -192,40 +223,54 @@ class CakeTimeTest extends CakeTestCase {
|
|||
strtotime('+8 years +4 months +2 weeks +3 days'),
|
||||
array('accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
||||
);
|
||||
$expected = '8 years';
|
||||
$expected = 'in 8 years';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+8 years +4 months +2 weeks +3 days'),
|
||||
array('accuracy' => array('year' => 'month'), 'end' => '+10 years')
|
||||
);
|
||||
$expected = '8 years, 4 months';
|
||||
$expected = 'in 8 years, 4 months';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+8 years +4 months +2 weeks +3 days'),
|
||||
array('accuracy' => array('year' => 'week'), 'end' => '+10 years')
|
||||
);
|
||||
$expected = '8 years, 4 months, 2 weeks';
|
||||
$expected = 'in 8 years, 4 months, 2 weeks';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+8 years +4 months +2 weeks +3 days'),
|
||||
array('accuracy' => array('year' => 'day'), 'end' => '+10 years')
|
||||
);
|
||||
$expected = '8 years, 4 months, 2 weeks, 3 days';
|
||||
$expected = 'in 8 years, 4 months, 2 weeks, 3 days';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+1 years +5 weeks'),
|
||||
array('accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
||||
);
|
||||
$expected = '1 year';
|
||||
$expected = 'in 1 year';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+58 minutes'),
|
||||
array('accuracy' => 'hour')
|
||||
);
|
||||
$expected = 'in about an hour';
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+23 hours'),
|
||||
array('accuracy' => 'day')
|
||||
);
|
||||
$expected = 'in about a day';
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the format option of timeAgoInWords()
|
||||
* Test the format option of timeAgoInWords() with date() and strftime compatible strings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -233,20 +278,32 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
|
||||
$this->assertEquals('on 2007-09-25', $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
|
||||
$this->assertEquals('on 2007-09-25', $result);
|
||||
$result = $this->Time->timeAgoInWords('2007-9-25', '%x');
|
||||
$this->assertEquals('on ' . strftime('%x', strtotime('2007-9-25')), $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+2 weeks +2 days'),
|
||||
'Y-m-d'
|
||||
);
|
||||
$this->assertRegExp('/^2 weeks, [1|2] day(s)?$/', $result);
|
||||
$this->assertRegExp('/^in 2 weeks, [1|2] day(s)?$/', $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+2 weeks +2 days'),
|
||||
'%x'
|
||||
);
|
||||
$this->assertRegExp('/^in 2 weeks, [1|2] day(s)?$/', $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+2 months +2 days'),
|
||||
array('end' => '1 month', 'format' => 'Y-m-d')
|
||||
);
|
||||
$this->assertEquals('on ' . date('Y-m-d', strtotime('+2 months +2 days')), $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('+2 months +2 days'),
|
||||
array('end' => '1 month', 'format' => '%x')
|
||||
);
|
||||
$this->assertEquals('on ' . strftime('%x', strtotime('+2 months +2 days')), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,6 +366,18 @@ class CakeTimeTest extends CakeTestCase {
|
|||
array('end' => '2 years')
|
||||
);
|
||||
$this->assertEquals('1 year, 1 month, 5 days ago', $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('-58 minutes'),
|
||||
array('accuracy' => 'hour')
|
||||
);
|
||||
$this->assertEquals('about an hour ago', $result);
|
||||
|
||||
$result = $this->Time->timeAgoInWords(
|
||||
strtotime('-23 hours'),
|
||||
array('accuracy' => 'day')
|
||||
);
|
||||
$this->assertEquals('about a day ago', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -367,6 +436,12 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$time = time() + DAY;
|
||||
$this->assertEquals('Tomorrow, ' . date('H:i', $time), $this->Time->niceShort($time));
|
||||
|
||||
$time = strtotime('+6 days');
|
||||
$this->assertEquals('On ' . date('l F d, H:i', $time), $this->Time->niceShort($time));
|
||||
|
||||
$time = strtotime('-6 days');
|
||||
$this->assertEquals(date('l F d, H:i', $time), $this->Time->niceShort($time));
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
$result = $this->Time->niceShort('2005-01-15 10:00:00', new DateTimeZone('Europe/Brussels'));
|
||||
$this->assertEquals('Jan 15th 2005, 11:00', $result);
|
||||
|
@ -379,6 +454,19 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$this->_restoreSystemTimezone();
|
||||
}
|
||||
|
||||
/**
|
||||
* testNiceShort translations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNiceShortI18n() {
|
||||
$restore = setlocale(LC_ALL, 0);
|
||||
setlocale(LC_ALL, 'es_ES');
|
||||
$time = strtotime('2015-01-07 03:05:00');
|
||||
$this->assertEquals('ene 7th 2015, 03:05', $this->Time->niceShort($time));
|
||||
setlocale(LC_ALL, $restore);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDaysAsSql method
|
||||
*
|
||||
|
@ -470,7 +558,7 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$expected = date('l jS \of F Y h:i:s A', $time);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$this->assertFalse($this->Time->toServer(time(), new Object()));
|
||||
$this->assertFalse($this->Time->toServer(time(), new CakeObject()));
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
|
@ -541,11 +629,20 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$result = $this->Time->format('Y-m-d', null, 'never');
|
||||
$this->assertEquals('never', $result);
|
||||
|
||||
$result = $this->Time->format('Y-m-d', '');
|
||||
$this->assertSame('', $result);
|
||||
|
||||
$result = $this->Time->format('Y-m-d', false);
|
||||
$this->assertSame('', $result);
|
||||
|
||||
$result = $this->Time->format('2012-01-13', '%d-%m-%Y', 'invalid');
|
||||
$this->assertEquals('13-01-2012', $result);
|
||||
|
||||
$result = $this->Time->format('nonsense', '%d-%m-%Y', 'invalid', 'UTC');
|
||||
$this->assertEquals('invalid', $result);
|
||||
|
||||
$result = $this->Time->format('0000-00-00', '%d-%m-%Y', 'invalid');
|
||||
$this->assertEquals('invalid', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -590,6 +687,40 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsFuture method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsFuture() {
|
||||
$this->assertTrue($this->Time->isFuture('+1 month'));
|
||||
$this->assertTrue($this->Time->isFuture('+1 days'));
|
||||
$this->assertTrue($this->Time->isFuture('+1 minute'));
|
||||
$this->assertTrue($this->Time->isFuture('+1 second'));
|
||||
|
||||
$this->assertFalse($this->Time->isFuture('-1 second'));
|
||||
$this->assertFalse($this->Time->isFuture('-1 day'));
|
||||
$this->assertFalse($this->Time->isFuture('-1 week'));
|
||||
$this->assertFalse($this->Time->isFuture('-1 month'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsPast method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIsPast() {
|
||||
$this->assertFalse($this->Time->isPast('+1 month'));
|
||||
$this->assertFalse($this->Time->isPast('+1 days'));
|
||||
$this->assertFalse($this->Time->isPast('+1 minute'));
|
||||
$this->assertFalse($this->Time->isPast('+1 second'));
|
||||
|
||||
$this->assertTrue($this->Time->isPast('-1 second'));
|
||||
$this->assertTrue($this->Time->isPast('-1 day'));
|
||||
$this->assertTrue($this->Time->isPast('-1 week'));
|
||||
$this->assertTrue($this->Time->isPast('-1 month'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testIsThisWeek method
|
||||
*
|
||||
|
@ -847,6 +978,7 @@ class CakeTimeTest extends CakeTestCase {
|
|||
|
||||
$date = new DateTime('+1 hour', new DateTimeZone('America/New_York'));
|
||||
$result = $this->Time->fromString($date, 'Asia/Kuwait');
|
||||
|
||||
$date->setTimezone(new DateTimeZone('Asia/Kuwait'));
|
||||
$expected = $date->format('U') + $date->getOffset();
|
||||
$this->assertWithinMargin($expected, $result, 1);
|
||||
|
@ -854,6 +986,18 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$this->_restoreSystemTimezone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that datetimes in the default timezone are not modified.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFromStringWithDateTimeNoConversion() {
|
||||
Configure::write('Config.timezone', date_default_timezone_get());
|
||||
$date = new DateTime('2013-04-09');
|
||||
$result = $this->Time->fromString($date);
|
||||
$this->assertEquals($result, $date->format('U'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test converting time specifiers using a time definition localfe file
|
||||
*
|
||||
|
@ -944,12 +1088,12 @@ class CakeTimeTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* test convert %e on windows.
|
||||
* test convert %e on Windows.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConvertPercentE() {
|
||||
$this->skipIf(DIRECTORY_SEPARATOR !== '\\', 'Cannot run windows tests on non-windows OS.');
|
||||
$this->skipIf(DIRECTORY_SEPARATOR !== '\\', 'Cannot run Windows tests on non-Windows OS.');
|
||||
|
||||
$time = strtotime('Thu Jan 14 11:43:39 2010');
|
||||
$result = $this->Time->convertSpecifiers('%e', $time);
|
||||
|
@ -1022,6 +1166,10 @@ class CakeTimeTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testListTimezones() {
|
||||
$this->skipIf(
|
||||
version_compare(PHP_VERSION, '5.4.0', '<='),
|
||||
'This test requires newer libicu which is in php5.4+'
|
||||
);
|
||||
$return = CakeTime::listTimezones();
|
||||
$this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
|
||||
$this->assertEquals('Bangkok', $return['Asia']['Asia/Bangkok']);
|
||||
|
@ -1035,6 +1183,19 @@ class CakeTimeTest extends CakeTestCase {
|
|||
$this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
|
||||
$this->assertFalse(isset($return['Pacific']));
|
||||
|
||||
$return = CakeTime::listTimezones(null, null, array('abbr' => true));
|
||||
$this->assertTrue(isset($return['Asia']['Asia/Jakarta']));
|
||||
$this->assertEquals('Jakarta - WIB', $return['Asia']['Asia/Jakarta']);
|
||||
$this->assertEquals('Regina - CST', $return['America']['America/Regina']);
|
||||
|
||||
$return = CakeTime::listTimezones(null, null, array(
|
||||
'abbr' => true,
|
||||
'before' => ' (',
|
||||
'after' => ')',
|
||||
));
|
||||
$this->assertEquals('Jayapura (WIT)', $return['Asia']['Asia/Jayapura']);
|
||||
$this->assertEquals('Regina (CST)', $return['America']['America/Regina']);
|
||||
|
||||
$return = CakeTime::listTimezones('#^(America|Pacific)/#', null, false);
|
||||
$this->assertTrue(isset($return['America/Argentina/Buenos_Aires']));
|
||||
$this->assertTrue(isset($return['Pacific/Tahiti']));
|
||||
|
@ -1055,7 +1216,7 @@ class CakeTimeTest extends CakeTestCase {
|
|||
* from one timezone to the other correctly
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
*/
|
||||
public function testCorrectTimezoneConversion() {
|
||||
date_default_timezone_set('UTC');
|
||||
$date = '2012-01-01 10:00:00';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue