-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up test cases into more classes
- Loading branch information
1 parent
85cd638
commit 7784a52
Showing
9 changed files
with
434 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
<?php | ||
|
||
use yii\helpers\Url; | ||
|
||
class RedirectTest extends TestCase | ||
{ | ||
public function testRedirectsIfDefaultLanguageInUrlAndDefaultLanguageUsesNoSuffix() | ||
{ | ||
$this->expectRedirect('/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
]); | ||
$this->mockRequest('/en/site/page'); | ||
} | ||
|
||
public function testRedirectsToRootIfOnlyDefaultLanguageInUrlAndDefaultLanguageUsesNoSuffix() | ||
{ | ||
$this->expectRedirect('/'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
]); | ||
$this->mockRequest('/en'); | ||
} | ||
|
||
public function testRedirectsRootToDefaultLanguageIfDefaultLanguageUsesSuffix() | ||
{ | ||
$this->expectRedirect('/en'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
'enableDefaultLanguageUrlCode' => true, | ||
]); | ||
$this->mockRequest('/'); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndDefaultLanguageUsesSuffix() | ||
{ | ||
$this->expectRedirect('/en/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
'enableDefaultLanguageUrlCode' => true, | ||
]); | ||
$this->mockRequest('/site/page'); | ||
} | ||
|
||
public function testRedirectsIfDefaultLanguageInUrl() | ||
{ | ||
$this->expectRedirect('/'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en'], | ||
]); | ||
$this->mockRequest('/en'); | ||
} | ||
|
||
public function testRedirectsIfLanguageWithUpperCaseCountryInUrl() | ||
{ | ||
$this->expectRedirect('/es-bo/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'deutsch' => 'de', 'es-BO'], | ||
]); | ||
$this->mockRequest('/es-BO/site/page'); | ||
} | ||
|
||
public function testRedirectsIfLanguageWithUpperCaseWildcardCountryInUrl() | ||
{ | ||
$this->expectRedirect('/es-bo/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'deutsch' => 'de', 'es-*'], | ||
]); | ||
$this->mockRequest('/es-BO/site/page'); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageMatches() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['de'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageMatchesWildcard() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de-*'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['de'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageWithCountryMatches() | ||
{ | ||
$this->expectRedirect('/de-at/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de', 'de-AT'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['de-AT', 'de', 'en'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageWithCountryMatchesWildcard() | ||
{ | ||
$this->expectRedirect('/de-at/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de-*'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['de-AT', 'de', 'en'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageWithCountryMatchesCountryAlias() | ||
{ | ||
$this->expectRedirect('/at/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['de', 'at'=>'de-AT'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['de-at', 'de'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageMatchesLanguageAndCountryAlias() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['de', 'at'=>'de-AT'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['en-US', 'en', 'de'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageWithLowercaseCountryMatches() | ||
{ | ||
$this->expectRedirect('/de-at/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de', 'de-AT'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['de-at', 'de', 'en'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndAcceptedLanguageWithCountryMatchesLanguage() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
]); | ||
$this->mockRequest('/site/page',[ | ||
'acceptableLanguages' => ['de-at'], | ||
]); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndLanguageInSession() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
@session_start(); | ||
$_SESSION['_language'] = 'de'; | ||
$this->mockUrlManager( [ | ||
'languages' => ['en-US', 'en', 'de'], | ||
]); | ||
$this->mockRequest('/site/page'); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndLanguageInSessionMatchesWildcard() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
@session_start(); | ||
$_SESSION['_language'] = 'de'; | ||
$this->mockUrlManager( [ | ||
'languages' => ['en-US', 'en', 'de-*'], | ||
]); | ||
$this->mockRequest('/site/page'); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndLanguageInCookie() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
$_COOKIE['_language'] = 'de'; | ||
$this->mockUrlManager( [ | ||
'languages' => ['en-US', 'en', 'de'], | ||
]); | ||
$this->mockRequest('/site/page'); | ||
} | ||
|
||
public function testRedirectsIfNoLanguageInUrlAndLanguageInCookieMatchesWildcard() | ||
{ | ||
$this->expectRedirect('/de/site/page'); | ||
$_COOKIE['_language'] = 'de'; | ||
$this->mockUrlManager( [ | ||
'languages' => ['en-US', 'en', 'de-*'], | ||
]); | ||
$this->mockRequest('/site/page'); | ||
} | ||
|
||
public function testRedirectsIfUrlDoesNotMatchIgnoresUrls() | ||
{ | ||
$this->expectRedirect('/site/page'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
'ignoreLanguageUrlPatterns' => [ | ||
'#not/used#' => '#^site/other#' | ||
], | ||
]); | ||
$this->mockRequest('/en/site/page'); | ||
} | ||
|
||
public function testRedirectsIfDefaultLanguageInUrlAndDefaultLanguageUsesNoSuffixAndTrailingSlashEnabled() | ||
{ | ||
$this->expectRedirect('/site/page/'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
'suffix' => '/' | ||
]); | ||
$this->mockRequest('/en/site/page/'); | ||
} | ||
|
||
public function testRedirectsToRootIfOnlyDefaultLanguageInUrlAndDefaultLanguageUsesNoSuffixAndTrailingSlashEnabled() | ||
{ | ||
$this->expectRedirect('/'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
'suffix' => '/', | ||
]); | ||
$this->mockRequest('/en'); | ||
} | ||
|
||
public function testRedirectsRootToDefaultLanguageIfDefaultLanguageUsesSuffixAndTrailingSlashEnabled() | ||
{ | ||
$this->expectRedirect('/en/'); | ||
$this->mockUrlManager([ | ||
'languages' => ['en-US', 'en', 'de'], | ||
'enableDefaultLanguageUrlCode' => true, | ||
'suffix' => '/', | ||
]); | ||
$this->mockRequest('/'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use yii\helpers\Url; | ||
|
||
class RedirectWithBaseUrlAndScriptName extends RedirectTest | ||
{ | ||
protected $baseUrl = '/base'; | ||
protected $showScriptName = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
use yii\helpers\Url; | ||
|
||
class RedirectWithBaseUrlTest extends RedirectTest | ||
{ | ||
protected $baseUrl = '/base'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
use yii\helpers\Url; | ||
|
||
class RedirectWithScriptNameTest extends RedirectTest | ||
{ | ||
protected $showScriptName = true; | ||
} |
Oops, something went wrong.