Skip to content

Commit

Permalink
Added some test for the LocaleSelectorFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Aug 3, 2014
1 parent b5a3e01 commit 76affbb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/TestCase/Routing/Filter/LocaleSelectorFilterTest.php
@@ -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());
}

}

0 comments on commit 76affbb

Please sign in to comment.