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
|
|
|
'options' => [ |
40
|
|
|
'class' => Image::class, |
41
|
|
|
], |
42
|
|
|
], |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
$image = $this->createImage('/path/to/image1', 100, 200, 'image/jpeg'); |
48
|
|
|
$image->id = '/test/image'; |
49
|
|
|
$article = new ArticleWithRestrictedChildren(); |
50
|
|
|
$article->id = '/test/article'; |
51
|
|
|
$article->title = 'Foo'; |
52
|
|
|
$article->date = new \DateTime(); |
|
|
|
|
53
|
|
|
$article->image = $image; |
54
|
|
|
|
55
|
|
|
$this->documentManager->persist($article); |
56
|
|
|
$this->updater->update($this->documentManager, $article); |
57
|
|
|
$this->documentManager->flush(); |
58
|
|
|
$this->documentManager->clear(); |
59
|
|
|
|
60
|
|
|
$this->documentManager->find(null, '/test/article'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* It should automatically allow mapped collection objects as children. |
65
|
|
|
*/ |
66
|
|
|
public function testCollectionAddToValidChildren() |
67
|
|
|
{ |
68
|
|
|
$this->init([ |
69
|
|
|
ArticleWithRestrictedChildren::class => [ |
70
|
|
|
'fields' => [ |
71
|
|
|
'title' => [ |
72
|
|
|
'type' => 'text', |
73
|
|
|
'role' => 'title', |
74
|
|
|
], |
75
|
|
|
'slideshow' => [ |
76
|
|
|
'type' => 'collection', |
77
|
|
|
'options' => [ |
78
|
|
|
'field' => 'image', |
79
|
|
|
], |
80
|
|
|
], |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
$image1 = $this->createImage('/path/to/image1', 100, 200, 'image/jpeg'); |
86
|
|
|
$image2 = $this->createImage('/path/to/image2', 100, 200, 'image/jpeg'); |
87
|
|
|
$image3 = $this->createImage('/path/to/image3', 100, 200, 'image/jpeg'); |
88
|
|
|
|
89
|
|
|
$article = new ArticleWithRestrictedChildren(); |
90
|
|
|
$article->id = '/test/article'; |
91
|
|
|
$article->title = 'Foo'; |
92
|
|
|
$article->date = new \DateTime(); |
|
|
|
|
93
|
|
|
$article->slideshow = [$image1, $image2, $image3]; |
94
|
|
|
|
95
|
|
|
$this->documentManager->persist($article); |
96
|
|
|
$this->updater->update($this->documentManager, $article); |
97
|
|
|
$this->documentManager->flush(); |
98
|
|
|
$this->documentManager->clear(); |
99
|
|
|
|
100
|
|
|
$this->documentManager->find(null, '/test/article'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
View Code Duplication |
private function createArticleSlideshow() |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$article = new Article(); |
106
|
|
|
$article->id = '/test/article'; |
107
|
|
|
|
108
|
|
|
$image1 = $this->createImage('/path/to/image1', 100, 200, 'image/jpeg'); |
109
|
|
|
$image2 = $this->createImage('/path/to/image2', 100, 200, 'image/jpeg'); |
110
|
|
|
$image3 = $this->createImage('/path/to/image3', 100, 200, 'image/jpeg'); |
111
|
|
|
|
112
|
|
|
$article->slideshow = [ |
113
|
|
|
$image1, |
114
|
|
|
$image2, |
115
|
|
|
$image3, |
116
|
|
|
]; |
117
|
|
|
|
118
|
|
|
return $article; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.