|
|
@ -1,12 +1,14 @@ |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
namespace yiiunit\framework\web; |
|
|
|
namespace yiiunit\framework\web; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use yii\web\Application; |
|
|
|
use yii\web\UrlManager; |
|
|
|
use yii\web\UrlManager; |
|
|
|
|
|
|
|
|
|
|
|
class UrlManagerTest extends \yiiunit\TestCase |
|
|
|
class UrlManagerTest extends \yiiunit\TestCase |
|
|
|
{ |
|
|
|
{ |
|
|
|
public function testCreateUrl() |
|
|
|
public function testCreateUrl() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
new Application('test', __DIR__ . '/../..'); |
|
|
|
// default setting with '/' as base url |
|
|
|
// default setting with '/' as base url |
|
|
|
$manager = new UrlManager(array( |
|
|
|
$manager = new UrlManager(array( |
|
|
|
'baseUrl' => '/', |
|
|
|
'baseUrl' => '/', |
|
|
@ -14,14 +16,14 @@ class UrlManagerTest extends \yiiunit\TestCase |
|
|
|
$url = $manager->createUrl('post/view'); |
|
|
|
$url = $manager->createUrl('post/view'); |
|
|
|
$this->assertEquals('/?r=post/view', $url); |
|
|
|
$this->assertEquals('/?r=post/view', $url); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$this->assertEquals('/?r=post/view&id=1&title=sample%20post', $url); |
|
|
|
$this->assertEquals('/?r=post/view&id=1&title=sample+post', $url); |
|
|
|
|
|
|
|
|
|
|
|
// default setting with '/test/' as base url |
|
|
|
// default setting with '/test/' as base url |
|
|
|
$manager = new UrlManager(array( |
|
|
|
$manager = new UrlManager(array( |
|
|
|
'baseUrl' => '/test/', |
|
|
|
'baseUrl' => '/test/', |
|
|
|
)); |
|
|
|
)); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$this->assertEquals('/test/?r=post/view&id=1&title=sample%20post', $url); |
|
|
|
$this->assertEquals('/test/?r=post/view&id=1&title=sample+post', $url); |
|
|
|
|
|
|
|
|
|
|
|
// pretty URL without rules |
|
|
|
// pretty URL without rules |
|
|
|
$manager = new UrlManager(array( |
|
|
|
$manager = new UrlManager(array( |
|
|
@ -29,19 +31,19 @@ class UrlManagerTest extends \yiiunit\TestCase |
|
|
|
'baseUrl' => '/', |
|
|
|
'baseUrl' => '/', |
|
|
|
)); |
|
|
|
)); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$this->assertEquals('/post/view?r=post/view&id=1&title=sample%20post', $url); |
|
|
|
$this->assertEquals('/post/view?id=1&title=sample+post', $url); |
|
|
|
$manager = new UrlManager(array( |
|
|
|
$manager = new UrlManager(array( |
|
|
|
'enablePrettyUrl' => true, |
|
|
|
'enablePrettyUrl' => true, |
|
|
|
'baseUrl' => '/test/', |
|
|
|
'baseUrl' => '/test/', |
|
|
|
)); |
|
|
|
)); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$this->assertEquals('/test/post/view?r=post/view&id=1&title=sample%20post', $url); |
|
|
|
$this->assertEquals('/test/post/view?id=1&title=sample+post', $url); |
|
|
|
$manager = new UrlManager(array( |
|
|
|
$manager = new UrlManager(array( |
|
|
|
'enablePrettyUrl' => true, |
|
|
|
'enablePrettyUrl' => true, |
|
|
|
'baseUrl' => '/test/index.php', |
|
|
|
'baseUrl' => '/test/index.php', |
|
|
|
)); |
|
|
|
)); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$this->assertEquals('/test/index.php/post/view?r=post/view&id=1&title=sample%20post', $url); |
|
|
|
$this->assertEquals('/test/index.php/post/view?id=1&title=sample+post', $url); |
|
|
|
|
|
|
|
|
|
|
|
// todo: test showScriptName |
|
|
|
// todo: test showScriptName |
|
|
|
|
|
|
|
|
|
|
@ -51,12 +53,13 @@ class UrlManagerTest extends \yiiunit\TestCase |
|
|
|
'rules' => array( |
|
|
|
'rules' => array( |
|
|
|
array( |
|
|
|
array( |
|
|
|
'pattern' => 'post/<id>/<title>', |
|
|
|
'pattern' => 'post/<id>/<title>', |
|
|
|
|
|
|
|
'route' => 'post/view', |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
'baseUrl' => '/', |
|
|
|
'baseUrl' => '/', |
|
|
|
)); |
|
|
|
)); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$this->assertEquals('/post/view/1/sample%20test', $url); |
|
|
|
$this->assertEquals('/post/1/sample+post', $url); |
|
|
|
$url = $manager->createUrl('post/index', array('page' => 1)); |
|
|
|
$url = $manager->createUrl('post/index', array('page' => 1)); |
|
|
|
$this->assertEquals('/post/index?page=1', $url); |
|
|
|
$this->assertEquals('/post/index?page=1', $url); |
|
|
|
|
|
|
|
|
|
|
@ -66,13 +69,14 @@ class UrlManagerTest extends \yiiunit\TestCase |
|
|
|
'rules' => array( |
|
|
|
'rules' => array( |
|
|
|
array( |
|
|
|
array( |
|
|
|
'pattern' => 'post/<id>/<title>', |
|
|
|
'pattern' => 'post/<id>/<title>', |
|
|
|
|
|
|
|
'route' => 'post/view', |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
'baseUrl' => '/', |
|
|
|
'baseUrl' => '/', |
|
|
|
'suffix' => '.html', |
|
|
|
'suffix' => '.html', |
|
|
|
)); |
|
|
|
)); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$url = $manager->createUrl('post/view', array('id' => 1, 'title' => 'sample post')); |
|
|
|
$this->assertEquals('/post/view/1/sample%20test.html', $url); |
|
|
|
$this->assertEquals('/post/1/sample+post.html', $url); |
|
|
|
$url = $manager->createUrl('post/index', array('page' => 1)); |
|
|
|
$url = $manager->createUrl('post/index', array('page' => 1)); |
|
|
|
$this->assertEquals('/post/index.html?page=1', $url); |
|
|
|
$this->assertEquals('/post/index.html?page=1', $url); |
|
|
|
} |
|
|
|
} |
|
|
|