2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
App::import('Core', 'l10n');
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-10-08 14:01:50 +00:00
|
|
|
* L10nTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class L10nTest extends CakeTestCase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-08 14:01:50 +00:00
|
|
|
* testGet method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testGet() {
|
|
|
|
$l10n =& new L10n();
|
|
|
|
|
|
|
|
// Catalog Entry
|
|
|
|
$l10n->get('en');
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'English';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('eng', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'eng';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
// Map Entry
|
|
|
|
$l10n->get('eng');
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'English';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('eng', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'eng';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
// Catalog Entry
|
|
|
|
$l10n->get('en-ca');
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'English (Canadian)';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('en_ca', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'en_ca';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
// Default Entry
|
|
|
|
define('DEFAULT_LANGUAGE', 'en-us');
|
|
|
|
|
|
|
|
$l10n->get('use_default');
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'English (United States)';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('en_us', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'en_us';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
// Using $this->default
|
|
|
|
$l10n = new L10n();
|
|
|
|
$l10n->get('use_default');
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'English (United States)';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('en_us', 'eng', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'en_us';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testGetAutoLanguage method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testGetAutoLanguage() {
|
|
|
|
$__SERVER = $_SERVER;
|
|
|
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'inexistent,en-ca';
|
|
|
|
|
|
|
|
$l10n =& new L10n();
|
|
|
|
$l10n->get();
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'English (Canadian)';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('en_ca', 'eng', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'en_ca';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es_mx';
|
|
|
|
$l10n->get();
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'Spanish (Mexican)';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('es_mx', 'spa', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'es_mx';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-10-30 03:10:40 +00:00
|
|
|
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_xy,en_ca';
|
|
|
|
$l10n->get();
|
|
|
|
$result = $l10n->language;
|
|
|
|
$expected = 'English';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->languagePath;
|
|
|
|
$expected = array('eng', 'eng', 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $l10n->locale;
|
|
|
|
$expected = 'eng';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-10-08 14:01:50 +00:00
|
|
|
$_SERVER = $__SERVER;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testMap method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMap() {
|
|
|
|
$l10n =& new L10n();
|
|
|
|
|
|
|
|
$result = $l10n->map(array('eng', 'en', 'en-us'));
|
|
|
|
$expected = array('eng' => 'en', 'en' => 'eng');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* testCatalog method
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-10-08 14:01:50 +00:00
|
|
|
function testCatalog() {
|
|
|
|
$l10n =& new L10n();
|
|
|
|
|
|
|
|
$result = $l10n->catalog(array('eng', 'en', 'en-us'));
|
|
|
|
$expected = array(
|
|
|
|
'en' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
|
|
|
|
'en-us' => array('language' => 'English (United States)', 'locale' => 'en_us', 'localeFallback' => 'eng', 'charset' => 'utf-8')
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|