Skip to content

Commit d245f24

Browse files
committed
Add collection tests
1 parent bb6bbc7 commit d245f24

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
namespace LdapRecord\Tests\Unit\Models;
4+
5+
use LdapRecord\Models\ActiveDirectory\User;
6+
use LdapRecord\Models\Collection;
7+
use LdapRecord\Models\Model;
8+
use LdapRecord\Tests\TestCase;
9+
10+
class CollectionTest extends TestCase
11+
{
12+
public function test_contains_with_closure()
13+
{
14+
$user = new User(['cn' => 'John Doe']);
15+
16+
$collection = new Collection([$user]);
17+
18+
$this->assertTrue(
19+
$collection->contains(function (Model $model) {
20+
return $model->getFirstAttribute('cn') === 'John Doe';
21+
})
22+
);
23+
24+
$this->assertFalse(
25+
$collection->contains(function (Model $model) {
26+
return $model->getFirstAttribute('cn') === 'Jane Doe';
27+
})
28+
);
29+
}
30+
31+
public function test_contains_with_key_operator_and_value()
32+
{
33+
$user = new User(['cn' => 'John Doe']);
34+
35+
$collection = new Collection([$user]);
36+
37+
$this->assertTrue(
38+
$collection->contains('cn', '=', ['John Doe'])
39+
);
40+
41+
$this->assertFalse(
42+
$collection->contains('cn', '=', ['Jane Doe'])
43+
);
44+
}
45+
46+
public function test_contains_with_model()
47+
{
48+
$user = new User(['dn' => 'cn=John Doe']);
49+
50+
$otherUser = new User(['dn' => 'cn=Jane Doe']);
51+
52+
$collection = new Collection([$user]);
53+
54+
$this->assertTrue(
55+
$collection->contains($user)
56+
);
57+
58+
$this->assertFalse(
59+
$collection->contains($otherUser)
60+
);
61+
}
62+
63+
public function test_contains_with_model_without_dn()
64+
{
65+
$user = new User(['cn' => 'John Doe']);
66+
67+
$collection = new Collection([$user]);
68+
69+
$this->assertFalse(
70+
$collection->contains(new User)
71+
);
72+
}
73+
74+
public function test_contains_with_multiple_models()
75+
{
76+
$user = new User(['dn' => 'cn=John Doe']);
77+
78+
$otherUser = new User(['dn' => 'cn=Jane Doe']);
79+
80+
$collection = new Collection([$user, $otherUser]);
81+
82+
$this->assertTrue(
83+
$collection->contains([
84+
$user,
85+
$otherUser,
86+
])
87+
);
88+
89+
$this->assertFalse(
90+
$collection->contains([
91+
new User(['dn' => 'cn=Foo Bar']),
92+
new User(['dn' => 'cn=Bar Baz']),
93+
])
94+
);
95+
}
96+
97+
public function test_contains_with_model_collection()
98+
{
99+
$user = new User(['dn' => 'cn=John Doe']);
100+
101+
$otherUser = new User(['dn' => 'cn=Jane Doe']);
102+
103+
$collection = new Collection([$user, $otherUser]);
104+
105+
$this->assertTrue(
106+
$collection->contains(new Collection([$user]))
107+
);
108+
109+
$this->assertFalse(
110+
$collection->contains(new Collection([
111+
new User(['dn' => 'cn=Foo Bar']),
112+
new User(['dn' => 'cn=Bar Baz']),
113+
]))
114+
);
115+
}
116+
}

0 commit comments

Comments
 (0)