Skip to content

Commit

Permalink
Issue #63 Add test cases for creating absolute URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaertl committed Mar 21, 2016
1 parent ff3cfcc commit f9a1c4d
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions tests/UrlCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ public function testCreateUrlWithLanguageFromUrl()
$this->assertEquals($this->prepareUrl('/de/foo/baz/bar?x=y'), Url::to(['/slug/action', 'x' => 'y', 'term' => 'baz']));
}

public function testCreateAbsoluteUrlWithLanguageFromUrl()
{
$this->mockUrlManager([
'languages' => ['en-US', 'en', 'de'],
'rules' => [
'/foo/<term:.+>/bar' => 'slug/action',
],
]);
$this->mockRequest('/de/site/page');
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/demo/action'), Url::to(['/demo/action'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/demo/action?x=y'), Url::to(['/demo/action', 'x' => 'y'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/foo/baz/bar'), Url::to(['/slug/action', 'term' => 'baz'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/foo/baz/bar?x=y'), Url::to(['/slug/action', 'x' => 'y', 'term' => 'baz'], 'http'));
}

public function testCreateUrlWithLanguageFromUrlIfUppercaseEnabled()
{
$this->mockUrlManager([
Expand Down Expand Up @@ -91,6 +106,20 @@ public function testCreateHomeUrlWithLanguageFromUrl()
$this->assertEquals($this->prepareUrl('/de?x=y'), Url::to(['/site/index', 'x' => 'y']));
}

public function testCreateAbsoluteHomeUrlWithLanguageFromUrl()
{
$this->mockUrlManager([
'languages' => ['en-US', 'en', 'de'],
'rules' => [
'' => 'site/index',
'/foo/<term:.+>/bar' => 'slug/action',
],
]);
$this->mockRequest('/de/site/page');
$this->assertEquals('http://localhost'.$this->prepareUrl('/de'), Url::to(['/site/index'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/de?x=y'), Url::to(['/site/index', 'x' => 'y'], 'http'));
}

public function testCreateUrlWithSpecificLanguage()
{
$this->mockUrlManager([
Expand All @@ -107,6 +136,22 @@ public function testCreateUrlWithSpecificLanguage()
$this->assertEquals($this->prepareUrl('/en-us/foo/baz/bar?x=y'), Url::to(['/slug/action', 'language' => 'en-US', 'x' => 'y', 'term' => 'baz']));
}

public function testCreateAbsoluteUrlWithSpecificLanguage()
{
$this->mockUrlManager([
'languages' => ['en-US', 'en', 'de'],
'rules' => [
'/foo/<term:.+>/bar' => 'slug/action',
],
]);
$this->mockRequest('/de/site/page');
$this->assertEquals('http://localhost'.$this->prepareUrl('/en-us'), Url::to(['/', 'language' => 'en-US'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/en-us/demo/action'), Url::to(['/demo/action', 'language' => 'en-US'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/en-us/demo/action?x=y'), Url::to(['/demo/action', 'language' => 'en-US', 'x'=>'y'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/en-us/foo/baz/bar'), Url::to(['/slug/action', 'language' => 'en-US', 'term' => 'baz'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/en-us/foo/baz/bar?x=y'), Url::to(['/slug/action', 'language' => 'en-US', 'x' => 'y', 'term' => 'baz'], 'http'));
}

public function testCreateUrlWithSpecificAliasedLanguage()
{
$this->mockUrlManager([
Expand Down Expand Up @@ -157,7 +202,7 @@ public function testCreateUrlWithLanguageFromUrlIfIgnoreRouteDoesNotMatch()
$this->assertEquals($this->prepareUrl('/de/foo/baz/bar?x=y'), Url::to(['/slug/action', 'x' => 'y', 'term' => 'baz']));
}

public function testCreateUrlWithLanguageAndTrailingSlashFromUrl()
public function testCreateUrlWithTralingSlashWithLanguageFromUrl()
{
$this->mockUrlManager([
'languages' => ['en-US', 'en', 'de'],
Expand All @@ -173,6 +218,22 @@ public function testCreateUrlWithLanguageAndTrailingSlashFromUrl()
$this->assertEquals($this->prepareUrl('/de/foo/baz/bar/?x=y'), Url::to(['/slug/action', 'x' => 'y', 'term' => 'baz']));
}

public function testCreateAbsoluteUrlWithTralingSlashWithLanguageFromUrl()
{
$this->mockUrlManager([
'languages' => ['en-US', 'en', 'de'],
'suffix' => '/',
'rules' => [
'/foo/<term:.+>/bar' => 'slug/action',
],
]);
$this->mockRequest('/de/site/page/');
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/demo/action/'), Url::to(['/demo/action'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/demo/action/?x=y'), Url::to(['/demo/action', 'x'=>'y'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/foo/baz/bar/'), Url::to(['/slug/action', 'term' => 'baz'], 'http'));
$this->assertEquals('http://localhost'.$this->prepareUrl('/de/foo/baz/bar/?x=y'), Url::to(['/slug/action', 'x' => 'y', 'term' => 'baz'], 'http'));
}

public function testCreateHomeUrlWithTrailingSlashWithLanguageFromUrl()
{
$this->mockUrlManager([
Expand Down Expand Up @@ -204,7 +265,7 @@ public function testCreateUrlWithSpecificLanguageWithTrailingSlash()
$this->assertEquals($this->prepareUrl('/en-us/foo/baz/bar/?x=y'), Url::to(['/slug/action', 'language' => 'en-US', 'x' => 'y', 'term' => 'baz']));
}

public function testCreateUrlUppercaseLanguageIfEnabled()
public function testCreateUrlWithUppercaseLanguageIfEnabled()
{
$this->mockUrlManager([
'languages' => ['en-US', 'en', 'de'],
Expand Down

0 comments on commit f9a1c4d

Please sign in to comment.