Skip to content
Permalink
Browse files

another batch of revese changes

  • Loading branch information...
Graziel committed May 11, 2016
1 parent 9e96ecc commit 27f52f2dbe6f39b4c20a8ea46354f2d272088263
Showing with 45 additions and 64 deletions.
  1. +3 −6 src/Validation/Validator.php
  2. +42 −58 tests/TestCase/Validation/ValidatorTest.php
@@ -158,7 +158,6 @@ public function field($name, ValidationSet $set = null)
$set = $set ?: new ValidationSet;
$this->_fields[$name] = $set;
}
return $this->_fields[$name];
}
@@ -318,6 +317,7 @@ public function add($field, $name, $rule = [])
foreach ($rules as $name => $rule) {
$field->add($name, $rule);
}
return $this;
}
@@ -349,7 +349,6 @@ public function addNested($field, Validator $validator)
$validator->provider($provider, $this->provider($provider));
}
$errors = $validator->errors($value, $context['newRecord']);
return empty($errors) ? true : $errors;
}]);
return $this;
@@ -392,7 +391,6 @@ public function addNestedMany($field, Validator $validator)
$errors[$i] = $check;
}
}
return empty($errors) ? true : $errors;
}]);
return $this;
@@ -1444,7 +1442,6 @@ public function multipleOptions($field, array $options = [], $message = null, $w
public function hasAtLeast($field, $count, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'hasAtLeast', $extra + [
'rule' => function ($value) use ($count) {
if (is_array($value) && isset($value['_ids'])) {
@@ -1470,7 +1467,6 @@ public function hasAtLeast($field, $count, $message = null, $when = null)
public function hasAtMost($field, $count, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'hasAtMost', $extra + [
'rule' => function ($value) use ($count) {
if (is_array($value) && isset($value['_ids'])) {
@@ -1536,6 +1532,7 @@ protected function _checkPresence($field, $context)
($required === 'update' && $newRecord)
);
}
return !$required;
}
@@ -1561,6 +1558,7 @@ protected function _canBeEmpty($field, $context)
($allowed === 'update' && !$newRecord)
);
}
return $allowed;
}
@@ -1578,7 +1576,6 @@ protected function _fieldIsEmpty($data)
$isArray = is_array($data);
if ($isArray && (isset($data['year']) || isset($data['hour']))) {
$value = implode('', $data);
return strlen($value) === 0;
}
if ($isArray && isset($data['name'], $data['type'], $data['tmp_name'], $data['error'])) {
@@ -203,18 +203,15 @@ public function testRequirePresenceAsArray()
$this->assertTrue($validator->field('title')->isPresenceRequired());
$this->assertTrue($validator->field('created')->isPresenceRequired());
$validator->requirePresence(
[
'title' => [
'mode' => false
],
'content' => [
'mode' => 'update'
],
'subject'
$validator->requirePresence([
'title' => [
'mode' => false
],
true
);
'content' => [
'mode' => 'update'
],
'subject'
], true);
$this->assertFalse($validator->field('title')->isPresenceRequired());
$this->assertEquals('update', $validator->field('content')->isPresenceRequired());
$this->assertTrue($validator->field('subject')->isPresenceRequired());
@@ -561,22 +558,19 @@ public function testAllowEmptyAsArray()
{
$validator = new Validator;
$validator->allowEmpty(
[
'title',
'subject',
'posted_at' => [
'when' => false
],
'updated_at' => [
'when' => true
],
'show_at' => [
'when' => 'update'
]
$validator->allowEmpty([
'title',
'subject',
'posted_at' => [
'when' => false
],
'create'
);
'updated_at' => [
'when' => true
],
'show_at' => [
'when' => 'update'
]
], 'create');
$this->assertEquals('create', $validator->field('title')->isEmptyAllowed());
$this->assertEquals('create', $validator->field('subject')->isEmptyAllowed());
$this->assertFalse($validator->field('posted_at')->isEmptyAllowed());
@@ -623,26 +617,22 @@ public function testNotEmptyAsArray()
$this->assertFalse($validator->field('title')->isEmptyAllowed());
$this->assertFalse($validator->field('created')->isEmptyAllowed());
$validator->notEmpty(
[
'title' => [
'when' => false
],
'content' => [
'when' => 'update'
],
'posted_at' => [
'when' => 'create'
],
'show_at' => [
'message' => 'Show date cannot be empty',
'when' => false
],
'subject'
$validator->notEmpty([
'title' => [
'when' => false
],
'Not empty',
true
);
'content' => [
'when' => 'update'
],
'posted_at' => [
'when' => 'create'
],
'show_at' => [
'message' => 'Show date cannot be empty',
'when' => false
],
'subject'
], 'Not empty', true);
$this->assertFalse($validator->field('title')->isEmptyAllowed());
$this->assertTrue($validator->isEmptyAllowed('content', true));
@@ -651,16 +641,13 @@ public function testNotEmptyAsArray()
$this->assertTrue($validator->isEmptyAllowed('posted_at', false));
$this->assertTrue($validator->field('subject')->isEmptyAllowed());
$errors = $validator->errors(
[
'title' => '',
'content' => '',
'posted_at' => null,
'show_at' => null,
'subject' => ''
],
false
);
$errors = $validator->errors([
'title' => '',
'content' => '',
'posted_at' => null,
'show_at' => null,
'subject' => ''
], false);
$expected = [
'title' => ['_empty' => 'Not empty'],
@@ -948,7 +935,6 @@ public function testErrorsFromCustomProvider()
'field' => 'title'
];
$this->assertEquals($expected, $context);
return "That ain't cool, yo";
}));
@@ -994,7 +980,6 @@ public function testMethodsWithExtraArguments()
'field' => 'title'
];
$this->assertEquals($expected, $context);
return "That ain't cool, yo";
}));
$validator->provider('thing', $thing);
@@ -1016,7 +1001,6 @@ public function testUsingClosureAsRule()
$validator->add('name', 'myRule', [
'rule' => function ($data, $provider) {
$this->assertEquals('foo', $data);
return 'You fail';
}
]);

0 comments on commit 27f52f2

Please sign in to comment.
You can’t perform that action at this time.