Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some test for the LocaleSelectorFilter
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
tests/TestCase/Routing/Filter/LocaleSelectorFilterTest.php
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,54 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since 3.0.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\Test\TestCase\Routing\Filter; | ||
|
||
use Cake\Event\Event; | ||
use Cake\Network\Request; | ||
use Cake\Routing\Filter\LocaleSelectorFilter; | ||
use Cake\TestSuite\TestCase; | ||
use Locale; | ||
|
||
/** | ||
* Locale selector filter test. | ||
*/ | ||
class LocaleSelectorFilterTest extends TestCase { | ||
|
||
public function tearDown() { | ||
parent::tearDown(); | ||
Locale::setDefault(''); | ||
} | ||
|
||
public function testSimpleSelection() { | ||
$filter = new LocaleSelectorFilter(); | ||
$request = new Request([ | ||
'environment' => ['HTTP_ACCEPT_LANGUAGE' => 'en-GB,en;q=0.8,es;q=0.6,da;q=0.4'] | ||
]); | ||
$filter->beforeDispatch(new Event('name', null, ['request' => $request])); | ||
$this->assertEquals('en_GB', Locale::getDefault()); | ||
|
||
$request = new Request([ | ||
'environment' => ['HTTP_ACCEPT_LANGUAGE' => 'es_VE,en;q=0.8,es;q=0.6,da;q=0.4'] | ||
]); | ||
$filter->beforeDispatch(new Event('name', null, ['request' => $request])); | ||
$this->assertEquals('es_VE', Locale::getDefault()); | ||
|
||
$request = new Request([ | ||
'environment' => ['HTTP_ACCEPT_LANGUAGE' => 'en;q=0.4,es;q=0.6,da;q=0.8'] | ||
]); | ||
$filter->beforeDispatch(new Event('name', null, ['request' => $request])); | ||
$this->assertEquals('da', Locale::getDefault()); | ||
} | ||
|
||
} |