1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psi\Bridge\ObjectAgent\Doctrine\PhpcrOdm\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Psi\Bridge\ObjectAgent\Doctrine\PhpcrOdm\Tests\Functional\Model\Page; |
6
|
|
|
use Psi\Bridge\ObjectAgent\Doctrine\PhpcrOdm\Tests\Functional\Model\PageNoUuid; |
7
|
|
|
use Psi\Bridge\ObjectAgent\Doctrine\PhpcrOdm\Tests\Functional\Model\Article; |
8
|
|
|
|
9
|
|
|
class PhpcrOdmAgentTest extends PhpcrOdmTestCase |
10
|
|
|
{ |
11
|
|
|
private $agent; |
12
|
|
|
private $documentManager; |
|
|
|
|
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
$container = $this->getContainer(); |
17
|
|
|
$this->agent = $container->get('psi_object_agent.phpcr_odm'); |
18
|
|
|
$this->documentManager = $container->get('phpcr_odm'); |
19
|
|
|
$this->initPhpcr($this->documentManager); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* It should find a document. |
24
|
|
|
*/ |
25
|
|
|
public function testFind() |
26
|
|
|
{ |
27
|
|
|
$page = $this->createPage(); |
28
|
|
|
|
29
|
|
|
$document = $this->agent->find('/test/foobar'); |
30
|
|
|
$this->assertSame($page, $document); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* It should throw an exception if the document was not found. |
35
|
|
|
* |
36
|
|
|
* @expectedException Psi\Component\ObjectAgent\Exception\ObjectNotFoundException |
37
|
|
|
* @expectedExceptionMessage Could not find document with identifier "/test/foobar" (class "<null>") |
38
|
|
|
*/ |
39
|
|
|
public function testFindNotFound() |
40
|
|
|
{ |
41
|
|
|
$this->agent->find('/test/foobar'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* It should save. |
46
|
|
|
*/ |
47
|
|
|
public function testSave() |
48
|
|
|
{ |
49
|
|
|
$page = new Page(); |
50
|
|
|
$page->path = '/test/new'; |
51
|
|
|
$this->agent->save($page); |
52
|
|
|
|
53
|
|
|
$document = $this->documentManager->find(null, '/test/new'); |
54
|
|
|
$this->assertNotNull($document); |
55
|
|
|
$this->assertSame($page, $document); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* It should delete. |
60
|
|
|
*/ |
61
|
|
|
public function testDelete() |
62
|
|
|
{ |
63
|
|
|
$page = $this->createPage(); |
64
|
|
|
$this->agent->delete($page); |
65
|
|
|
|
66
|
|
|
$document = $this->documentManager->find(null, '/test/foobar'); |
67
|
|
|
$this->assertNull($document); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* It should return a document's identifier (a UUID) |
72
|
|
|
*/ |
73
|
|
|
public function testGetIdentifier() |
74
|
|
|
{ |
75
|
|
|
$page = $this->createPage(); |
76
|
|
|
$identifier = $this->agent->getIdentifier($page); |
77
|
|
|
$this->assertNotNull($identifier); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* It should throw an exception if the document does not have a mapped UUID field. |
82
|
|
|
* |
83
|
|
|
* @expectedException \RuntimeException |
84
|
|
|
* @expectedExceptionMessage does not have a UUID-mapped property |
85
|
|
|
*/ |
86
|
|
|
public function testGetIdentifierNoMappedUuid() |
87
|
|
|
{ |
88
|
|
|
$page = new PageNoUuid(); |
89
|
|
|
$page->path = '/test/foobar'; |
90
|
|
|
|
91
|
|
|
$identifier = $this->agent->getIdentifier($page); |
92
|
|
|
$this->assertNotNull($identifier); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* It should set the parent document on a given document. |
97
|
|
|
*/ |
98
|
|
|
public function testSetParent() |
99
|
|
|
{ |
100
|
|
|
$parent = $this->createPage(); |
101
|
|
|
$article = new Article(); |
102
|
|
|
$article->name = 'article'; |
103
|
|
|
$this->agent->setParent($article, $parent); |
104
|
|
|
|
105
|
|
|
$this->documentManager->persist($article); |
106
|
|
|
$this->documentManager->flush(); |
107
|
|
|
|
108
|
|
|
$document = $this->documentManager->find(null, '/test/foobar/article'); |
109
|
|
|
$this->assertNotNull($document); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* It should throw an exception if attempting to set parent on a document with no parent mapping. |
114
|
|
|
* |
115
|
|
|
* @expectedException \RuntimeException |
116
|
|
|
* @expectedExceptionMessage does not have a ParentDocument mapping |
117
|
|
|
*/ |
118
|
|
|
public function testSetParentNoParentMapping() |
119
|
|
|
{ |
120
|
|
|
$parent = $this->createPage(); |
121
|
|
|
$page = new Page(); |
122
|
|
|
$page->name = 'page'; |
|
|
|
|
123
|
|
|
$this->agent->setParent($page, $parent); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* It should say if it supports a given object. |
128
|
|
|
*/ |
129
|
|
|
public function testSupports() |
130
|
|
|
{ |
131
|
|
|
$this->assertTrue($this->agent->supports(Article::class)); |
132
|
|
|
$this->assertFalse($this->agent->supports(\stdClass::class)); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
private function createPage() |
136
|
|
|
{ |
137
|
|
|
$page = new Page(); |
138
|
|
|
$page->path = '/test/foobar'; |
139
|
|
|
$this->documentManager->persist($page); |
140
|
|
|
$this->documentManager->flush(); |
141
|
|
|
|
142
|
|
|
return $page; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|