mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
添加lang类单元测试
This commit is contained in:
@@ -153,8 +153,7 @@ class App
|
|||||||
{
|
{
|
||||||
$args = [];
|
$args = [];
|
||||||
// 判断数组类型 数字数组时按顺序绑定参数
|
// 判断数组类型 数字数组时按顺序绑定参数
|
||||||
$keys = array_keys($vars);
|
$type = key($vars) === 0 ? 1 : 0;
|
||||||
$type = array_keys($keys) === $keys ? 1 : 0;
|
|
||||||
if ($reflect->getNumberOfParameters() > 0) {
|
if ($reflect->getNumberOfParameters() > 0) {
|
||||||
$params = $reflect->getParameters();
|
$params = $reflect->getParameters();
|
||||||
foreach ($params as $param) {
|
foreach ($params as $param) {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class Lang
|
|||||||
*/
|
*/
|
||||||
if (key($vars) === 0) {
|
if (key($vars) === 0) {
|
||||||
// 数字索引解析
|
// 数字索引解析
|
||||||
array_unshift($vars, $name);
|
array_unshift($vars, $value);
|
||||||
$value = call_user_func_array('sprintf', $vars);
|
$value = call_user_func_array('sprintf', $vars);
|
||||||
} else {
|
} else {
|
||||||
// 关联索引解析
|
// 关联索引解析
|
||||||
@@ -115,7 +115,6 @@ class Lang
|
|||||||
$value = str_replace($replace, $vars, $value);
|
$value = str_replace($replace, $vars, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -536,8 +536,7 @@ class Model
|
|||||||
// 根据主键查询
|
// 根据主键查询
|
||||||
if (is_array($options)) {
|
if (is_array($options)) {
|
||||||
// 判断是否索引数组
|
// 判断是否索引数组
|
||||||
$keys = array_keys($options);
|
if (key($options) === 0) {
|
||||||
if (array_keys($keys) === $keys) {
|
|
||||||
$where[$pk] = ['in', $options];
|
$where[$pk] = ['in', $options];
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
|||||||
4
tests/thinkphp/library/think/lang/lang.php
Normal file
4
tests/thinkphp/library/think/lang/lang.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'load'=>'加载',
|
||||||
|
];
|
||||||
64
tests/thinkphp/library/think/langTest.php
Normal file
64
tests/thinkphp/library/think/langTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?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') );
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user