Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Jun 29, 2020
1 parent 91afbe0 commit 92cf9d9
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions tests/Validation/ValidationValidatorTest.php
Expand Up @@ -3880,6 +3880,32 @@ public function testPassingSlashVulnerability()
$this->assertTrue($v->fails());
}

public function testPlaceholdersAreReplaced()
{
$trans = $this->getIlluminateArrayTranslator();

$v = new Validator($trans, [
'matrix' => ['\\' => ['invalid'], '1\\' => ['invalid']],
], [
'matrix.*.*' => 'integer',
]);
$this->assertTrue($v->fails());

$v = new Validator($trans, [
'matrix' => ['\\' => [1], '1\\' => [1]],
], [
'matrix.*.*' => 'integer',
]);
$this->assertTrue($v->passes());

$v = new Validator($trans, [
'foo' => ['bar' => 'valid'], 'foo.bar' => 'invalid', 'foo->bar' => 'valid',
], [
'foo\.bar' => 'required|in:valid',
]);
$this->assertTrue($v->fails());
}

public function testCoveringEmptyKeys()
{
$trans = $this->getIlluminateArrayTranslator();
Expand All @@ -3891,35 +3917,8 @@ public function testImplicitEachWithAsterisksWithArrayValues()
{
$trans = $this->getIlluminateArrayTranslator();

$v = new Validator($trans, ['foo' => [1, 2, 3]], ['foo' => 'size:4']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => [1, 2, 3, 4]], ['foo' => 'size:4']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => [1, 2, 3, 4]], ['foo.*' => 'integer', 'foo.0' => 'required']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => [['bar' => [1, 2, 3]], ['bar' => [1, 2, 3]]]], ['foo.*.bar' => 'size:4']);
$this->assertFalse($v->passes());

$v = new Validator($trans,
['foo' => [['bar' => [1, 2, 3]], ['bar' => [1, 2, 3]]]], ['foo.*.bar' => 'min:3']);
$this->assertTrue($v->passes());

$v = new Validator($trans,
['foo' => [['bar' => [1, 2, 3]], ['bar' => [1, 2, 3]]]], ['foo.*.bar' => 'between:3,6']);
$this->assertTrue($v->passes());

$v = new Validator($trans,
['foo' => [['name' => 'first', 'votes' => [1, 2]], ['name' => 'second', 'votes' => ['something', 2]]]],
['foo.*.votes' => ['Required', 'Size:2']]);
$this->assertTrue($v->passes());

$v = new Validator($trans,
['foo' => [['name' => 'first', 'votes' => [1, 2, 3]], ['name' => 'second', 'votes' => ['something', 2]]]],
['foo.*.votes' => ['Required', 'Size:2']]);
$this->assertFalse($v->passes());
$v = new Validator($trans, ['foo' => ['bar.baz' => '']], ['foo' => 'required']);
$this->assertEquals(['foo' => ['bar.baz' => '']], $v->validated());
}

public function testValidateNestedArrayWithCommonParentChildKey()
Expand Down

0 comments on commit 92cf9d9

Please sign in to comment.