forked from doctrine/phpcr-odm
/
DocumentRepositoryTest.php
114 lines (91 loc) · 4.14 KB
/
DocumentRepositoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Doctrine\Tests\ODM\PHPCR\Functional;
/**
* @group functional
*/
class DocumentRepositoryTest extends \Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase
{
public function setUp()
{
$this->type = 'Doctrine\Tests\Models\CMS\CmsUser';
$this->dm = $this->createDocumentManager();
$session = $this->dm->getPhpcrSession();
$root = $session->getNode('/');
if ($root->hasNode('functional')) {
$root->getNode('functional')->remove();
$session->save();
}
$this->node = $root->addNode('functional');
$session->save();
}
public function testLoadMany()
{
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user1->username = "beberlei";
$user1->status = "active";
$user1->name = "Benjamin";
$user1->id = '/functional/user1';
$user2 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user2->username = "lsmith";
$user2->status = "active";
$user2->name = "Lukas";
$user2->id = '/functional/user2';
$this->dm->persist($user1);
$this->dm->persist($user2);
$this->dm->flush();
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id));
$this->assertSame($user1, $users['/functional/user1']);
$this->assertSame($user2, $users['/functional/user2']);
$this->dm->clear();
$users = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findMany(array($user1->id, $user2->id));
$this->assertEquals($user1->username, $users['/functional/user1']->username);
$this->assertEquals($user2->username, $users['/functional/user2']->username);
}
public function testFindBy()
{
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user1->username = "beberlei";
$user1->status = "active";
$user1->name = "Benjamin";
$user1->id = '/functional/user1';
$user2 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user2->username = "lsmith";
$user2->status = "active";
$user2->name = "Lukas";
$user2->id = '/functional/user2';
$this->dm->persist($user1);
$this->dm->persist($user2);
$this->dm->flush();
$users1 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('username' =>'beberlei'));
$this->assertCount(1, $users1);
$this->assertEquals($user1->username, $users1['/functional/user1']->username);
$users2 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' =>'active'));
$this->assertCount(2, $users2);
$users3 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' =>'active'), null, 1);
$this->assertCount(1, $users3);
$users4 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' =>'active'), array('name'), 2, 0);
$this->assertEquals('/functional/user1', $users4->key());
$users5 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findBy(array('status' =>'active'), array('name'), 2, 1);
$this->assertEquals('/functional/user2', $users5->key());
}
public function testFindOneBy()
{
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user1->username = "beberlei";
$user1->status = "active";
$user1->name = "Benjamin";
$user1->id = '/functional/user1';
$user2 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user2->username = "lsmith";
$user2->status = "active";
$user2->name = "Lukas";
$user2->id = '/functional/user2';
$this->dm->persist($user1);
$this->dm->persist($user2);
$this->dm->flush();
$users1 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findOneBy(array('username' =>'beberlei'));
$this->assertEquals($user1->username, $users1->username);
$users2 = $this->dm->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findOneBy(array('username' =>'obama'));
$this->assertEquals(null, $users2);
}
}