Skip to content

Commit

Permalink
Make Validator::localizedTime() fit testing framework and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ypnos committed Mar 14, 2016
1 parent 12156f2 commit 778cdc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Validation/Validator.php
Expand Up @@ -829,18 +829,17 @@ public function time($field, $message = null, $when = null)
*
* @param string $field The field you want to apply the rule to.
* @param string $type Parser type, one out of 'date', 'time', and 'datetime'
* @param string|int|null $format any format accepted by IntlDateFormatter
* @param string|null $message The error message when the rule fails.
* @param string|callable|null $when Either 'create' or 'update' or a callable that returns
* true when the validation rule should be applied.
* @see \Cake\Validation\Validation::localizedTime()
* @return $this
*/
public function localizedTime($field, $type = 'datetime', $format = null, $message = null, $when = null)
public function localizedTime($field, $type = 'datetime', $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, $type, $extra + [
'rule' => ['localizedTime', $type, $format]
return $this->add($field, 'localizedTime', $extra + [
'rule' => ['localizedTime', $type]
]);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/Validation/ValidatorTest.php
Expand Up @@ -1241,6 +1241,18 @@ public function testTime()
$this->assertNotEmpty($validator->errors(['username' => 'not a time']));
}

/**
* Tests the localizedTime proxy method
*
* @return void
*/
public function testLocalizedTime()
{
$validator = new Validator();
$this->assertProxyMethod($validator, 'localizedTime', 'date', ['date']);
$this->assertNotEmpty($validator->errors(['username' => 'not a date']));
}

/**
* Tests the boolean proxy method
*
Expand Down

0 comments on commit 778cdc0

Please sign in to comment.