Created
October 3, 2011 03:15
-
-
Save yuya-matsushima/1258357 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Nice_date_test extends CI_Controller { | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->load->library('unit_test'); | |
$this->load->helper('date'); | |
} | |
//Do test onetime | |
public function index() | |
{ | |
foreach(get_class_methods($this) as $method) | |
{ | |
if( ! preg_match('/^_|set_up|tear_down|index/u', $method)) | |
{ | |
call_user_func(array($this, $method)); | |
} | |
} | |
echo $this->unit->report(); | |
} | |
//sample code in date_helper.html | |
public function sample_199605() | |
{ | |
$test = nice_date('199605', 'Y-m-d'); | |
$expected = '1996-05-01'; | |
$this->unit->run($test, $expected, '199605', 'return 1996-05-01. Result:' . $test); | |
//1996-05-01 => Passed | |
} | |
//sample code in date_helper.html | |
public function sample_9_11_2001() | |
{ | |
$test = nice_date('9-11-2001', 'Y-m-d'); | |
$expected = '2001-09-11'; | |
$this->unit->run($test, $expected, '9-11-2001', 'return 2001-09-11. Result:' . $test); | |
//2011-09-11 => Passed | |
} | |
// Something wrong | |
public function MMDDYYYY() | |
{ | |
$test = nice_date('09112001', 'Y-m-d'); | |
$expected = '2001-09-11'; | |
$this->unit->run($test, $expected, 'MMDDYYYY', 'return 2001-09-11. Result:' . $test); | |
//2011-09-01 => Failed | |
} | |
//default (when 2nd parameter is not set). | |
public function unix_199605() | |
{ | |
$test = nice_date('199605'); | |
$expected = 830876400; | |
$this->unit->run($test, $expected, 'unix_199605', 'return 830876400. Result:' . $test); | |
//'' => Failed | |
} | |
//YYYYMMDD is not used? | |
public function YYYYMMDD() | |
{ | |
$test = nice_date('20010911', 'Y-m-d'); | |
$expected = '2001-09-11'; | |
$this->unit->run($test, $expected, 'YYYYMMDD', 'return 2001-09-11. Result:' . $test); | |
//1970-01-01 => Failed | |
} | |
} | |
/* End of file nice_date.php */ | |
/* Location: ./application/controllers/nice_date.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment