完善单元测试

This commit is contained in:
thinkphp
2016-02-28 15:25:33 +08:00
parent 4cc8e7d52b
commit 69055ca068
2 changed files with 42 additions and 24 deletions

View File

@@ -16,35 +16,42 @@
namespace tests\thinkphp\library\think; namespace tests\thinkphp\library\think;
use think\Lang;
use think\Config; use think\Config;
use think\Lang;
class langTest extends \PHPUnit_Framework_TestCase class langTest extends \PHPUnit_Framework_TestCase
{ {
public function testSetAndGet(){ public function testSetAndGet()
Lang::set('hello,%s','欢迎,%s'); {
$this->assertEquals('欢迎,ThinkPHP',Lang::get('hello,%s',['ThinkPHP']) ); Lang::set('hello,%s', '欢迎,%s');
Lang::set('hello,%s','歡迎,%s','zh-tw'); $this->assertEquals('欢迎,ThinkPHP', Lang::get('hello,%s', ['ThinkPHP']));
$this->assertEquals('歡迎,ThinkPHP',Lang::get('hello,%s',['ThinkPHP'],'zh-tw') ); Lang::set('hello,%s', '歡迎,%s', 'zh-tw');
Lang::set(['hello'=>'欢迎','use'=>'使用']); $this->assertEquals('歡迎,ThinkPHP', Lang::get('hello,%s', ['ThinkPHP'], 'zh-tw'));
$this->assertEquals('欢迎',Lang::get('hello') ); Lang::set(['hello' => '欢迎', 'use' => '使用']);
$this->assertEquals('欢迎',Lang::get('HELLO') ); $this->assertEquals('欢迎', Lang::get('hello'));
$this->assertEquals('使用',Lang::get('use') ); $this->assertEquals('欢迎', Lang::get('HELLO'));
$this->assertEquals('使用', Lang::get('use'));
$this->assertEquals(['hello' => '欢迎', 'hello,%s' => '欢迎,%s', 'use' => '使用'], Lang::get());
Lang::set('hello,{:name}', '欢迎,{:name}');
$this->assertEquals('欢迎,liu21st', Lang::get('hello,{:name}', ['name' => 'liu21st']));
} }
public function testLoad(){ public function testLoad()
Lang::load(__DIR__.DS.'lang'.DS.'lang.php'); {
$this->assertEquals('加载',Lang::get('load') ); Lang::load(__DIR__ . DS . 'lang' . DS . 'lang.php');
Lang::load(__DIR__.DS.'lang'.DS.'lang.php','test'); $this->assertEquals('加载', Lang::get('load'));
$this->assertEquals('加载',Lang::get('load',[],'test') ); Lang::load(__DIR__ . DS . 'lang' . DS . 'lang.php', 'test');
$this->assertEquals('加载', Lang::get('load', [], 'test'));
} }
public function testDetect(){ public function testDetect()
{
Config::set('lang_list',['zh-cn','zh-tw']); Config::set('lang_list', ['zh-cn', 'zh-tw']);
Lang::set('hello','欢迎','zh-cn'); Lang::set('hello', '欢迎', 'zh-cn');
Lang::set('hello','歡迎','zh-tw'); Lang::set('hello', '歡迎', 'zh-tw');
/* /*
$_GET['lang'] = 'zh-tw'; $_GET['lang'] = 'zh-tw';
Lang::detect(); Lang::detect();
@@ -52,13 +59,16 @@ class langTest extends \PHPUnit_Framework_TestCase
$_GET['lang'] = 'zh-cn'; $_GET['lang'] = 'zh-cn';
Lang::detect(); Lang::detect();
$this->assertEquals('欢迎',Lang::get('hello') ); $this->assertEquals('欢迎', Lang::get('hello'));
} }
public function testRange(){ public function testRange()
Lang::set('hello','欢迎','test'); {
$this->assertEquals('zh-cn', Lang::range());
Lang::set('hello', '欢迎', 'test');
Lang::range('test'); Lang::range('test');
$this->assertEquals('欢迎',Lang::get('hello') ); $this->assertEquals('test', Lang::range());
$this->assertEquals('欢迎', Lang::get('hello'));
} }
} }

View File

@@ -26,6 +26,14 @@ class routeTest extends \PHPUnit_Framework_TestCase
Route::get('hello/:name', 'index/hello'); Route::get('hello/:name', 'index/hello');
Route::get(['hello/:name' => 'index/hello']); Route::get(['hello/:name' => 'index/hello']);
$this->assertEquals(['type' => 'module', 'module' => [null, 'index', 'hello']], Route::check('hello/thinkphp')); $this->assertEquals(['type' => 'module', 'module' => [null, 'index', 'hello']], Route::check('hello/thinkphp'));
$this->assertEquals(['hello/:name' => ['route' => 'index/hello', 'option' => [], 'pattern' => []]], Route::getRules('GET'));
}
public function testRouteMap()
{
Route::map('hello', 'index/hello');
//$this->assertEquals('index/hello',Route::map('hello'));
$this->assertEquals(['type' => 'module', 'module' => ['index', 'hello', null]], Route::check('hello'));
} }
public function testParseUrl() public function testParseUrl()