mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
// +----------------------------------------------------------------------
|
|
// | Author: liu21st <liu21st@gmail.com>
|
|
// +----------------------------------------------------------------------
|
|
|
|
/**
|
|
* Lang测试
|
|
* @author liu21st <liu21st@gmail.com>
|
|
*/
|
|
|
|
namespace tests\thinkphp\library\think;
|
|
|
|
use think\Lang;
|
|
use think\Config;
|
|
|
|
class langTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
public function testSetAndGet(){
|
|
Lang::set('hello,%s','欢迎,%s');
|
|
$this->assertEquals('欢迎,ThinkPHP',Lang::get('hello,%s',['ThinkPHP']) );
|
|
Lang::set('hello,%s','歡迎,%s','zh-tw');
|
|
$this->assertEquals('歡迎,ThinkPHP',Lang::get('hello,%s',['ThinkPHP'],'zh-tw') );
|
|
Lang::set(['hello'=>'欢迎','use'=>'使用']);
|
|
$this->assertEquals('欢迎',Lang::get('hello') );
|
|
$this->assertEquals('欢迎',Lang::get('HELLO') );
|
|
$this->assertEquals('使用',Lang::get('use') );
|
|
}
|
|
|
|
public function testLoad(){
|
|
Lang::load(__DIR__.DS.'lang'.DS.'lang.php');
|
|
$this->assertEquals('加载',Lang::get('load') );
|
|
Lang::load(__DIR__.DS.'lang'.DS.'lang.php','test');
|
|
$this->assertEquals('加载',Lang::get('load',[],'test') );
|
|
}
|
|
|
|
public function testDetect(){
|
|
|
|
Config::set('lang_list',['zh-cn','zh-tw']);
|
|
Lang::set('hello','欢迎','zh-cn');
|
|
Lang::set('hello','歡迎','zh-tw');
|
|
/*
|
|
$_GET['lang'] = 'zh-tw';
|
|
Lang::detect();
|
|
$this->assertEquals('歡迎',Lang::get('hello') );*/
|
|
|
|
$_GET['lang'] = 'zh-cn';
|
|
Lang::detect();
|
|
$this->assertEquals('欢迎',Lang::get('hello') );
|
|
|
|
}
|
|
|
|
public function testRange(){
|
|
Lang::set('hello','欢迎','test');
|
|
Lang::range('test');
|
|
$this->assertEquals('欢迎',Lang::get('hello') );
|
|
}
|
|
}
|