cakephp2-php8/cake/tests/cases/libs/view/helpers/time.test.php

128 lines
4.7 KiB
PHP
Raw Normal View History

<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined. Closes #2213, Support multiple plugin paths. Closes #2234, filepaths to behavior classes should be cached in class.paths.php also Closes #2345, ability to group components into subfolders Closes #2645, Improvement to basic.php for class loading. Fixes #3526, Cache::write, when using just the config name, it fails. Fixes #3559, loading plugin model as assoc don't work. Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique) Fixes #3579, email.php component: Parse error with php 4. Adding new class and file importer. Updated most of the core to use the importer. Added ClassRegsitry::init() that will create and instance of an object and store it in the registry. Deprecated most of the load functions in basics.php Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model. var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set: var $uses = array('SomeModel'); will look for some_model.php in the app/models var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php All of the above will work between plugins and main app These changes also allow placing model and controllers is sub directories Removed old class.paths.php file generation git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'time');
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.view.helpers
*/
class TimeTest extends UnitTestCase {
function setUp() {
$this->Time = new TimeHelper();
}
function testToQuarter() {
$result = $this->Time->toQuarter('2007-12-25');
$this->assertEqual($result, 4);
$result = $this->Time->toQuarter('2007-9-25');
$this->assertEqual($result, 3);
$result = $this->Time->toQuarter('2007-3-25');
$this->assertEqual($result, 1);
$result = $this->Time->toQuarter('2007-3-25', true);
$this->assertEqual($result, array('2007-01-01', '2007-03-31'));
}
function testTimeAgoInWords() {
$result = $this->Time->timeAgoInWords('2007-9-25');
$this->assertEqual($result, 'on 25/9/07');
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
$this->assertEqual($result, 'on 2007-09-25');
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d', true);
$this->assertEqual($result, 'on 2007-09-25');
$result = $this->Time->timeAgoInWords(strtotime('-2 weeks, -2 days'), 'Y-m-d', false);
$this->assertEqual($result, '2 weeks, 2 days ago');
$result = $this->Time->timeAgoInWords(strtotime('2 weeks, 2 days'), 'Y-m-d', true);
$this->assertPattern('/^2 weeks, [1|2] day(s)?$/', $result);
$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '1 month'));
$this->assertEqual($result, 'on ' . date('j/n/y', strtotime('2 months, 2 days')));
$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '3 month'));
$this->assertPattern('/2 months/', $result);
$result = $this->Time->timeAgoInWords(strtotime('2 months, 12 days'), array('end' => '3 month'));
$this->assertPattern('/2 months, 1 week/', $result);
if (date('n') == '2') {
$result = $this->Time->timeAgoInWords(strtotime('3 months, 5 days'), array('end' => '4 month'));
$this->assertEqual($result, '3 months, 3 days');
$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month'));
$this->assertEqual($result, '2 months, 2 days ago');
$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month'));
$this->assertEqual($result, '2 months, 2 days ago');
} else {
// These tests fail in the month of February
$result = $this->Time->timeAgoInWords(strtotime('3 months, 5 days'), array('end' => '4 month'));
$this->assertEqual($result, '3 months, 4 days');
$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month'));
$this->assertEqual($result, '2 months, 1 day ago');
$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '3 month'));
$this->assertEqual($result, '2 months, 1 day ago');
}
$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '3 month'));
$this->assertPattern('/2 months/', $result);
$result = $this->Time->timeAgoInWords(strtotime('2 months, 2 days'), array('end' => '1 month', 'format' => 'Y-m-d'));
$this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('2 months, 2 days')));
$result = $this->Time->timeAgoInWords(strtotime('-2 months, -2 days'), array('end' => '1 month', 'format' => 'Y-m-d'));
$this->assertEqual($result, 'on ' . date('Y-m-d', strtotime('-2 months, -2 days')));
}
function testRelative() {
$result = $this->Time->relativeTime('-1 week');
$this->assertEqual($result, '1 week ago');
$result = $this->Time->relativeTime('+1 week');
$this->assertEqual($result, '1 week');
}
function tearDown() {
unset($this->Time);
}
}
?>