From 69055ca068b547dc55921400d8f8cb312643b0d8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 28 Feb 2016 15:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/langTest.php | 58 +++++++++++++--------- tests/thinkphp/library/think/routeTest.php | 8 +++ 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/tests/thinkphp/library/think/langTest.php b/tests/thinkphp/library/think/langTest.php index e9985c15..72c01d6d 100644 --- a/tests/thinkphp/library/think/langTest.php +++ b/tests/thinkphp/library/think/langTest.php @@ -16,35 +16,42 @@ namespace tests\thinkphp\library\think; -use think\Lang; use think\Config; +use think\Lang; class langTest extends \PHPUnit_Framework_TestCase { - public function testSetAndGet(){ - Lang::set('hello,%s','欢迎,%s'); - $this->assertEquals('欢迎,ThinkPHP',Lang::get('hello,%s',['ThinkPHP']) ); - Lang::set('hello,%s','歡迎,%s','zh-tw'); - $this->assertEquals('歡迎,ThinkPHP',Lang::get('hello,%s',['ThinkPHP'],'zh-tw') ); - Lang::set(['hello'=>'欢迎','use'=>'使用']); - $this->assertEquals('欢迎',Lang::get('hello') ); - $this->assertEquals('欢迎',Lang::get('HELLO') ); - $this->assertEquals('使用',Lang::get('use') ); + public function testSetAndGet() + { + Lang::set('hello,%s', '欢迎,%s'); + $this->assertEquals('欢迎,ThinkPHP', Lang::get('hello,%s', ['ThinkPHP'])); + Lang::set('hello,%s', '歡迎,%s', 'zh-tw'); + $this->assertEquals('歡迎,ThinkPHP', Lang::get('hello,%s', ['ThinkPHP'], 'zh-tw')); + Lang::set(['hello' => '欢迎', 'use' => '使用']); + $this->assertEquals('欢迎', Lang::get('hello')); + $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(){ - Lang::load(__DIR__.DS.'lang'.DS.'lang.php'); - $this->assertEquals('加载',Lang::get('load') ); - Lang::load(__DIR__.DS.'lang'.DS.'lang.php','test'); - $this->assertEquals('加载',Lang::get('load',[],'test') ); + public function testLoad() + { + Lang::load(__DIR__ . DS . 'lang' . DS . 'lang.php'); + $this->assertEquals('加载', Lang::get('load')); + Lang::load(__DIR__ . DS . 'lang' . DS . 'lang.php', 'test'); + $this->assertEquals('加载', Lang::get('load', [], 'test')); } - public function testDetect(){ - - Config::set('lang_list',['zh-cn','zh-tw']); - Lang::set('hello','欢迎','zh-cn'); - Lang::set('hello','歡迎','zh-tw'); + public function testDetect() + { + + Config::set('lang_list', ['zh-cn', 'zh-tw']); + Lang::set('hello', '欢迎', 'zh-cn'); + Lang::set('hello', '歡迎', 'zh-tw'); /* $_GET['lang'] = 'zh-tw'; Lang::detect(); @@ -52,13 +59,16 @@ class langTest extends \PHPUnit_Framework_TestCase $_GET['lang'] = 'zh-cn'; Lang::detect(); - $this->assertEquals('欢迎',Lang::get('hello') ); + $this->assertEquals('欢迎', Lang::get('hello')); } - public function testRange(){ - Lang::set('hello','欢迎','test'); + public function testRange() + { + $this->assertEquals('zh-cn', Lang::range()); + Lang::set('hello', '欢迎', 'test'); Lang::range('test'); - $this->assertEquals('欢迎',Lang::get('hello') ); + $this->assertEquals('test', Lang::range()); + $this->assertEquals('欢迎', Lang::get('hello')); } } diff --git a/tests/thinkphp/library/think/routeTest.php b/tests/thinkphp/library/think/routeTest.php index 76381db1..07b994e7 100644 --- a/tests/thinkphp/library/think/routeTest.php +++ b/tests/thinkphp/library/think/routeTest.php @@ -26,6 +26,14 @@ class routeTest extends \PHPUnit_Framework_TestCase 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(['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()