mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
commit
e011ab81c4
@ -49,7 +49,8 @@ class Validator
|
|||||||
// Load language file in directory
|
// Load language file in directory
|
||||||
$langFile = rtrim($langDir, '/') . '/' . $lang . '.php';
|
$langFile = rtrim($langDir, '/') . '/' . $lang . '.php';
|
||||||
if ( stream_resolve_include_path($langFile) ) {
|
if ( stream_resolve_include_path($langFile) ) {
|
||||||
static::$_ruleMessages = include $langFile;
|
$langMessages = include $langFile;
|
||||||
|
static::$_ruleMessages = array_merge(static::$_ruleMessages, $langMessages);
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException("fail to load language file '$langFile'");
|
throw new InvalidArgumentException("fail to load language file '$langFile'");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class BaseTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$this->resetProperty('_lang');
|
$this->resetProperty('_lang');
|
||||||
$this->resetProperty('_langDir');
|
$this->resetProperty('_langDir');
|
||||||
|
$this->resetProperty('_rules', array());
|
||||||
$this->resetProperty('_ruleMessages', array());
|
$this->resetProperty('_ruleMessages', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,4 +10,21 @@ class StaticVsInstanceTest extends BaseTestCase
|
|||||||
$this->assertEquals('ar', Validator::lang(),
|
$this->assertEquals('ar', Validator::lang(),
|
||||||
'instance defined lang should not replace static global lang');
|
'instance defined lang should not replace static global lang');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix bug where rules messages added with Validator::addRule were replaced after creating validator instance
|
||||||
|
*/
|
||||||
|
public function testRuleMessagesReplacedAfterConstructor()
|
||||||
|
{
|
||||||
|
$customMessage = 'custom message';
|
||||||
|
$ruleName = 'customRule';
|
||||||
|
$fieldName = 'fieldName';
|
||||||
|
Validator::addRule($ruleName, function() {}, $customMessage);
|
||||||
|
$v = new Validator(array($fieldName => $fieldName));
|
||||||
|
$v->rule($ruleName, $fieldName);
|
||||||
|
$v->validate();
|
||||||
|
$messages = $v->errors();
|
||||||
|
$this->assertArrayHasKey($fieldName, $messages);
|
||||||
|
$this->assertEquals(ucfirst("$fieldName $customMessage"), $messages[$fieldName][0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user