From 5691284f2fbd4e84872bea86578bdf14297b17c8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 28 Feb 2016 22:13:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Url=E7=B1=BB=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/urlTest.php | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/thinkphp/library/think/urlTest.php diff --git a/tests/thinkphp/library/think/urlTest.php b/tests/thinkphp/library/think/urlTest.php new file mode 100644 index 00000000..43b83ac2 --- /dev/null +++ b/tests/thinkphp/library/think/urlTest.php @@ -0,0 +1,59 @@ + +// +---------------------------------------------------------------------- + +/** + * Route测试 + * @author liu21st + */ + +namespace tests\thinkphp\library\think; + +use think\Url; +use think\Route; +use think\Config; + +class urlTest extends \PHPUnit_Framework_TestCase +{ + + public function testBuildModule(){ + + Route::get('hello/:name','index/hello'); + Route::get('hello/:id','index/hello'); + Config::set('pathinfo_depr','/'); + $this->assertEquals('/hello/thinkphp',Url::build('index/hello?name=thinkphp')); + $this->assertEquals('/hello/thinkphp.html',Url::build('index/hello','name=thinkphp','html')); + $this->assertEquals('/hello/10',Url::build('index/hello?id=10')); + $this->assertEquals('/hello/10.html',Url::build('index/hello','id=10','html')); + } + + public function testBuildController(){ + Route::get('blog/:id','@index/blog/read'); + $this->assertEquals('/blog/10.html',Url::build('@index/blog/read','id=10','html')); + } + + public function testBuildMethod(){ + Route::get('blog/:id', ['\app\index\controller\blog','read']); + $this->assertEquals('/blog/10.html',Url::build('\app\index\controller\blog\read','id=10','html')); + } + + public function testBuildRoute(){ + Route::get('blog/:id', 'index/blog'); + Config::set('url_html_suffix','shtml'); + $this->assertNotEquals('/blog/10.html',Url::build('/blog/10')); + $this->assertEquals('/blog/10.shtml',Url::build('/blog/10')); + } + + public function testBuildAnchor(){ + Route::get('blog/:id', 'index/blog'); + Config::set('url_html_suffix','shtml'); + $this->assertEquals('/blog/10.shtml#detail',Url::build('/blog/10#detail')); + } +}