Merge pull request #107 from vandarin/checkAndSetLabel

Check and set label
This commit is contained in:
Vance Lucas 2014-09-19 09:06:20 -05:00
commit f7c11ca0ab
2 changed files with 27 additions and 1 deletions

View File

@ -992,7 +992,7 @@ class Validator
$i = 1; $i = 1;
foreach ($params as $k => $v) { foreach ($params as $k => $v) {
$tag = '{field'. $i .'}'; $tag = '{field'. $i .'}';
$label = isset($params[$k]) && !is_array($params[$k]) && isset($this->_labels[$params[$k]]) ? $this->_labels[$params[$k]] : $tag; $label = isset($params[$k]) && (is_numeric($params[$k]) || is_string($params[$k])) && isset($this->_labels[$params[$k]]) ? $this->_labels[$params[$k]] : $tag;
$msg = str_replace($tag, $label, $msg); $msg = str_replace($tag, $label, $msg);
$i++; $i++;
} }

View File

@ -578,6 +578,32 @@ class ValidateTest extends BaseTestCase
$this->assertTrue($v->validate()); $this->assertTrue($v->validate());
} }
public function testDateWarningsWithObjectParams()
{
$v = new Validator(array('startDate' => '2013-01-27', 'endDate' => '2013-05-08'));
$v->rule(
'date',
array(
'startDate',
'endDate'
)
);
$v->rule(
'dateBefore',
'endDate',
new DateTime('2013-04-08')
)->label('End date')->message('{field} must be before the end of the fiscal year, %s.');
$v->rule(
'dateAfter',
'startDate',
new DateTime('2013-02-17')
)->label('Start date')->message('{field} must be after the beginning of the fiscal year, %s.');
$this->assertFalse($v->validate());
}
public function testDateBeforeInvalid() public function testDateBeforeInvalid()
{ {
$v = new Validator(array('date' => '2013-01-27')); $v = new Validator(array('date' => '2013-01-27'));