Skip to content

Commit 1744759

Browse files
add array values test for exists validation (#41611)
1 parent 0564fb5 commit 1744759

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/Validation/ValidationExistsRuleTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public function testItChoosesValidRecordsUsingWhereInRule()
9494
$this->assertFalse($v->passes());
9595
$v->setData(['id' => 4]);
9696
$this->assertFalse($v->passes());
97+
98+
// array values
99+
$v->setData(['id' => [1, 2]]);
100+
$this->assertTrue($v->passes());
101+
$v->setData(['id' => [3, 4]]);
102+
$this->assertFalse($v->passes());
97103
}
98104

99105
public function testItChoosesValidRecordsUsingWhereNotInRule()
@@ -118,6 +124,12 @@ public function testItChoosesValidRecordsUsingWhereNotInRule()
118124
$this->assertTrue($v->passes());
119125
$v->setData(['id' => 4]);
120126
$this->assertTrue($v->passes());
127+
128+
// array values
129+
$v->setData(['id' => [1, 2]]);
130+
$this->assertFalse($v->passes());
131+
$v->setData(['id' => [3, 4]]);
132+
$this->assertTrue($v->passes());
121133
}
122134

123135
public function testItChoosesValidRecordsUsingConditionalModifiers()
@@ -147,6 +159,12 @@ public function testItChoosesValidRecordsUsingConditionalModifiers()
147159
$this->assertTrue($v->passes());
148160
$v->setData(['id' => 4]);
149161
$this->assertTrue($v->passes());
162+
163+
// array values
164+
$v->setData(['id' => [1, 2]]);
165+
$this->assertFalse($v->passes());
166+
$v->setData(['id' => [3, 4]]);
167+
$this->assertTrue($v->passes());
150168
}
151169

152170
public function testItChoosesValidRecordsUsingWhereNotInAndWhereNotInRulesTogether()
@@ -158,6 +176,7 @@ public function testItChoosesValidRecordsUsingWhereNotInAndWhereNotInRulesTogeth
158176
User::create(['id' => '2', 'type' => 'bar']);
159177
User::create(['id' => '3', 'type' => 'baz']);
160178
User::create(['id' => '4', 'type' => 'other']);
179+
User::create(['id' => '5', 'type' => 'baz']);
161180

162181
$trans = $this->getIlluminateArrayTranslator();
163182
$v = new Validator($trans, [], ['id' => $rule]);
@@ -171,6 +190,14 @@ public function testItChoosesValidRecordsUsingWhereNotInAndWhereNotInRulesTogeth
171190
$this->assertTrue($v->passes());
172191
$v->setData(['id' => 4]);
173192
$this->assertFalse($v->passes());
193+
$v->setData(['id' => 5]);
194+
$this->assertTrue($v->passes());
195+
196+
// array values
197+
$v->setData(['id' => [1, 2, 4]]);
198+
$this->assertFalse($v->passes());
199+
$v->setData(['id' => [3, 5]]);
200+
$this->assertTrue($v->passes());
174201
}
175202

176203
public function testItIgnoresSoftDeletes()

0 commit comments

Comments
 (0)