|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Psi\Bridge\ContentType\Doctrine\PhpcrOdm\Tests\Functional; |
|
4
|
|
|
|
|
5
|
|
|
use Psi\Bridge\ContentType\Doctrine\PhpcrOdm\Tests\Functional\Example\Article; |
|
6
|
|
|
use Psi\Bridge\ContentType\Doctrine\PhpcrOdm\Tests\Functional\Example\ArticleWithRestrictedChildren; |
|
7
|
|
|
use Psi\Bridge\ContentType\Doctrine\PhpcrOdm\Tests\Functional\Example\Image; |
|
8
|
|
|
|
|
9
|
|
|
class ObjectUnrestrictTest extends PhpcrOdmTestCase |
|
10
|
|
|
{ |
|
11
|
|
|
private $documentManager; |
|
12
|
|
|
private $updater; |
|
13
|
|
|
|
|
14
|
|
|
public function init(array $mapping) |
|
15
|
|
|
{ |
|
16
|
|
|
$container = $this->getContainer([ |
|
17
|
|
|
'mapping' => $mapping, |
|
18
|
|
|
]); |
|
19
|
|
|
$this->documentManager = $container->get('doctrine_phpcr.document_manager'); |
|
20
|
|
|
$this->initPhpcr($this->documentManager); |
|
21
|
|
|
$this->updater = $container->get('psi_content_type.storage.doctrine.phpcr_odm.collection_updater'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* It should automatically allow mapped content objects as children. |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testChildAddToValidChildren() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->init([ |
|
30
|
|
|
ArticleWithRestrictedChildren::class => [ |
|
31
|
|
|
'fields' => [ |
|
32
|
|
|
'title' => [ |
|
33
|
|
|
'type' => 'text', |
|
34
|
|
|
'role' => 'title', |
|
35
|
|
|
], |
|
36
|
|
|
'image' => [ |
|
37
|
|
|
'type' => 'image', |
|
38
|
|
|
'role' => 'image', |
|
39
|
|
|
], |
|
40
|
|
|
], |
|
41
|
|
|
], |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
$image = $this->createImage('/path/to/image1', 100, 200, 'image/jpeg'); |
|
45
|
|
|
$image->id = '/test/image'; |
|
46
|
|
|
$article = new ArticleWithRestrictedChildren(); |
|
47
|
|
|
$article->id = '/test/article'; |
|
48
|
|
|
$article->title = 'Foo'; |
|
49
|
|
|
$article->image = $image; |
|
50
|
|
|
|
|
51
|
|
|
$this->documentManager->persist($article); |
|
52
|
|
|
$this->updater->update($this->documentManager, $article); |
|
53
|
|
|
$this->documentManager->flush(); |
|
54
|
|
|
$this->documentManager->clear(); |
|
55
|
|
|
|
|
56
|
|
|
$this->documentManager->find(null, '/test/article'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* It should automatically allow mapped collection objects as children. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testCollectionAddToValidChildren() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->init([ |
|
65
|
|
|
ArticleWithRestrictedChildren::class => [ |
|
66
|
|
|
'fields' => [ |
|
67
|
|
|
'title' => [ |
|
68
|
|
|
'type' => 'text', |
|
69
|
|
|
'role' => 'title', |
|
70
|
|
|
], |
|
71
|
|
|
'slideshow' => [ |
|
72
|
|
|
'type' => 'collection', |
|
73
|
|
|
'options' => [ |
|
74
|
|
|
'field_type' => 'image', |
|
75
|
|
|
], |
|
76
|
|
|
], |
|
77
|
|
|
], |
|
78
|
|
|
], |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$image1 = $this->createImage('/path/to/image1', 100, 200, 'image/jpeg'); |
|
82
|
|
|
$image2 = $this->createImage('/path/to/image2', 100, 200, 'image/jpeg'); |
|
83
|
|
|
$image3 = $this->createImage('/path/to/image3', 100, 200, 'image/jpeg'); |
|
84
|
|
|
|
|
85
|
|
|
$article = new ArticleWithRestrictedChildren(); |
|
86
|
|
|
$article->id = '/test/article'; |
|
87
|
|
|
$article->title = 'Foo'; |
|
88
|
|
|
$article->slideshow = [$image1, $image2, $image3]; |
|
89
|
|
|
|
|
90
|
|
|
$this->documentManager->persist($article); |
|
91
|
|
|
$this->updater->update($this->documentManager, $article); |
|
92
|
|
|
$this->documentManager->flush(); |
|
93
|
|
|
$this->documentManager->clear(); |
|
94
|
|
|
|
|
95
|
|
|
$this->documentManager->find(null, '/test/article'); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|