11<?php
22namespace PHPCR \Tests \Writing ;
33
4+ use PHPCR \PropertyInterface ;
5+ use PHPCR \PropertyType ;
6+ use PHPCR \SessionInterface ;
7+
48require_once (__DIR__ . '/../../inc/BaseCase.php ' );
59
610/**
1418 */
1519class SetPropertyTypesTest extends \PHPCR \Test \BaseCase
1620{
21+ /** @var PropertyInterface */
22+ private $ property ;
23+
1724 public function setUp ()
1825 {
1926 parent ::setUp ();
2027
2128 $ this ->renewSession ();
22- $ this ->node = $ this ->sharedFixture [ ' session ' ] ->getNode ('/tests_general_base/numberPropertyNode/jcr:content ' );
23- $ this ->property = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/longNumber ' );
29+ $ this ->node = $ this ->session ->getNode ('/tests_general_base/numberPropertyNode/jcr:content ' );
30+ $ this ->property = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/longNumber ' );
2431 }
2532
2633 //TODO: have this for all types in PropertyType and each with and without the explicit type parameter. also test node->getPropertyValue for correct type
@@ -34,7 +41,7 @@ public function testCreateString()
3441 $ this ->assertEquals (\PHPCR \PropertyType::STRING , $ value ->getType ());
3542
3643 $ this ->saveAndRenewSession ();
37- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propString ' );
44+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propString ' );
3845 $ this ->assertSame ('10.6 test ' , $ value ->getString ());
3946 $ this ->assertSame (10 , $ value ->getLong ());
4047 $ this ->assertEquals (\PHPCR \PropertyType::STRING , $ value ->getType ());
@@ -48,7 +55,7 @@ public function testCreateValueBinary()
4855 $ this ->assertEquals ('foobar ' , stream_get_contents ($ bin ->getBinary ()));
4956
5057 $ this ->saveAndRenewSession ();
51- $ bin = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/newBinary ' );
58+ $ bin = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/newBinary ' );
5259 $ this ->assertEquals (\PHPCR \PropertyType::BINARY , $ bin ->getType ());
5360 $ this ->assertEquals ('foobar ' , stream_get_contents ($ bin ->getBinary ()));
5461 }
@@ -62,12 +69,12 @@ public function testCreateValueBinaryFromStream()
6269 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ bin );
6370 $ this ->assertEquals (\PHPCR \PropertyType::BINARY , $ bin ->getType ());
6471
65- $ session = $ this ->sharedFixture [ ' session ' ] ;
72+ $ session = $ this ->session ;
6673 $ this ->saveAndRenewSession (); // either this
6774 $ session ->logout (); // or this should close the stream
6875 $ this ->assertFalse (is_resource ($ stream ), 'The responsibility for the stream goes into phpcr who must close it ' );
6976
70- $ bin = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/newBinaryStream ' );
77+ $ bin = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/newBinaryStream ' );
7178 $ this ->assertEquals (\PHPCR \PropertyType::BINARY , $ bin ->getType ());
7279 $ this ->assertEquals ('foo bar ' , stream_get_contents ($ bin ->getBinary ()));
7380 }
@@ -82,12 +89,12 @@ public function testCreateValueBinaryFromStreamAndRead()
8289 $ this ->assertEquals (\PHPCR \PropertyType::BINARY , $ bin ->getType ());
8390 $ this ->assertEquals ('foo bar ' , stream_get_contents ($ bin ->getBinary ()));
8491
85- $ session = $ this ->sharedFixture [ ' session ' ] ;
92+ $ session = $ this ->session ;
8693 $ this ->saveAndRenewSession (); // either this
8794 $ session ->logout (); // or this should close the stream
8895 $ this ->assertFalse (is_resource ($ stream ), 'The responsibility for the stream goes into phpcr who must close it ' );
8996
90- $ bin = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/newBinaryStream ' );
97+ $ bin = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/newBinaryStream ' );
9198 $ this ->assertEquals (\PHPCR \PropertyType::BINARY , $ bin ->getType ());
9299 $ this ->assertEquals ('foo bar ' , stream_get_contents ($ bin ->getBinary ()));
93100 }
@@ -101,7 +108,7 @@ public function testCreateValueInt()
101108 $ this ->assertEquals (\PHPCR \PropertyType::LONG , $ value ->getType ());
102109
103110 $ this ->saveAndRenewSession ();
104- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propInt ' );
111+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propInt ' );
105112 $ this ->assertSame ('100 ' , $ value ->getString ());
106113 $ this ->assertSame (100 , $ value ->getLong ());
107114 $ this ->assertEquals (\PHPCR \PropertyType::LONG , $ value ->getType ());
@@ -117,7 +124,7 @@ public function testCreateValueDouble()
117124 $ this ->assertEquals (\PHPCR \PropertyType::DOUBLE , $ value ->getType ());
118125
119126 $ this ->saveAndRenewSession ();
120- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propDouble ' );
127+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propDouble ' );
121128 $ this ->assertSame ('10.6 ' , $ value ->getString ());
122129 $ this ->assertSame (10.6 , $ value ->getDouble ());
123130 $ this ->assertSame (10 , $ value ->getLong ());
@@ -133,15 +140,15 @@ public function testCreateValueBoolean()
133140 $ this ->assertTrue ($ value ->getString () == true , 'wrong string value ' ); //boolean converted to string must be true
134141
135142 $ this ->saveAndRenewSession ();
136- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propBoolean ' );
143+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propBoolean ' );
137144 $ this ->assertEquals (\PHPCR \PropertyType::BOOLEAN , $ value ->getType (), 'wrong type ' );
138145 $ this ->assertTrue ($ value ->getBoolean (), 'boolean not true ' );
139146 $ this ->assertTrue ($ value ->getString () == true , 'wrong string value ' ); //boolean converted to string must be true
140147 }
141148
142149 public function testCreateValueNode ()
143150 {
144- $ node = $ this ->sharedFixture [ ' session ' ] ->getNode ('/tests_general_base/multiValueProperty ' );
151+ $ node = $ this ->session ->getNode ('/tests_general_base/multiValueProperty ' );
145152 $ identifier = $ node ->getIdentifier ();
146153 $ value = $ this ->node ->setProperty ('propNode ' , $ node );
147154 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ value );
@@ -150,14 +157,14 @@ public function testCreateValueNode()
150157 $ this ->assertSame ($ node , $ value ->getValue ());
151158
152159 $ this ->saveAndRenewSession ();
153- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propNode ' );
160+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propNode ' );
154161 $ this ->assertEquals (\PHPCR \PropertyType::REFERENCE , $ value ->getType (), 'wrong type ' );
155162 $ this ->assertEquals ($ identifier , $ value ->getString (), 'different uuid ' );
156163 }
157164
158165 public function testCreateValueNodeWeak ()
159166 {
160- $ node = $ this ->sharedFixture [ ' session ' ] ->getRootNode ()->getNode ('tests_general_base/multiValueProperty ' );
167+ $ node = $ this ->session ->getRootNode ()->getNode ('tests_general_base/multiValueProperty ' );
161168
162169 $ identifier = $ node ->getIdentifier ();
163170 $ value = $ this ->node ->setProperty ('propNodeWeak ' , $ node , \PHPCR \PropertyType::WEAKREFERENCE );
@@ -167,14 +174,14 @@ public function testCreateValueNodeWeak()
167174 $ this ->assertEquals ($ node ->getIdentifier (), $ value ->getString ());
168175 $ this ->assertSame ($ node , $ value ->getValue ());
169176
170- $ this ->sharedFixture [ ' session ' ] ->save ();
177+ $ this ->session ->save ();
171178 $ this ->assertEquals (\PHPCR \PropertyType::WEAKREFERENCE , $ value ->getType ());
172179 $ this ->assertEquals ($ identifier , $ value ->getString ());
173180 $ node = $ value ->getValue ();
174181 $ this ->assertInstanceOf ('PHPCR \\NodeInterface ' , $ node );
175182
176183 $ this ->renewSession ();
177- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propNodeWeak ' );
184+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propNodeWeak ' );
178185 $ this ->assertEquals (\PHPCR \PropertyType::WEAKREFERENCE , $ value ->getType ());
179186 $ this ->assertEquals ($ identifier , $ value ->getString ());
180187 $ node = $ value ->getValue ();
@@ -186,7 +193,7 @@ public function testCreateValueNodeWeak()
186193 */
187194 public function testCreateValueNodeNonReferenceable ()
188195 {
189- $ node = $ this ->sharedFixture [ ' session ' ] ->getRootNode ()->getNode ('tests_general_base/numberPropertyNode/jcr:content ' );
196+ $ node = $ this ->session ->getRootNode ()->getNode ('tests_general_base/numberPropertyNode/jcr:content ' );
190197 $ value = $ this ->node ->setProperty ('x ' , $ node );
191198 }
192199
@@ -195,7 +202,7 @@ public function testCreateValueNodeNonReferenceable()
195202 */
196203 public function testCreateValueNodeNonReferenceableWeak ()
197204 {
198- $ node = $ this ->sharedFixture [ ' session ' ] ->getRootNode ()->getNode ('tests_general_base/numberPropertyNode/jcr:content ' );
205+ $ node = $ this ->session ->getRootNode ()->getNode ('tests_general_base/numberPropertyNode/jcr:content ' );
199206 $ value = $ this ->node ->setProperty ('x ' , $ node , \PHPCR \PropertyType::WEAKREFERENCE );
200207 }
201208
@@ -206,7 +213,7 @@ public function testCreateValueStringType()
206213 $ this ->assertEquals (\PHPCR \PropertyType::STRING , $ value ->getType ());
207214
208215 $ this ->saveAndRenewSession ();
209- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propString ' );
216+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propString ' );
210217 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ value );
211218 $ this ->assertEquals (\PHPCR \PropertyType::STRING , $ value ->getType ());
212219 }
@@ -220,7 +227,7 @@ public function testCreateValueDateType()
220227 $ this ->assertEquals (date ('Y-m-d\TH:i:s.000P ' , $ time ), $ value ->getString ());
221228
222229 $ this ->saveAndRenewSession ();
223- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propDate ' );
230+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propDate ' );
224231 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ value );
225232 $ this ->assertEquals (\PHPCR \PropertyType::DATE , $ value ->getType ());
226233 $ this ->assertEquals (date ('Y-m-d\TH:i:s.000P ' , $ time ), $ value ->getString ());
@@ -233,7 +240,7 @@ public function testCreateValueUndefined()
233240 $ this ->assertNotEquals (\PHPCR \PropertyType::UNDEFINED , $ value ->getType (), 'getType should never return UNDEFINED ' );
234241
235242 $ this ->saveAndRenewSession ();
236- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propUndefined ' );
243+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propUndefined ' );
237244 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ value );
238245 $ this ->assertNotEquals (\PHPCR \PropertyType::UNDEFINED , $ value ->getType (), 'getType should never return UNDEFINED ' );
239246 }
@@ -246,7 +253,7 @@ public function testCreateValueName()
246253 $ this ->assertEquals ('jcr:name ' , $ value ->getString ());
247254
248255 $ this ->saveAndRenewSession ();
249- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propName ' );
256+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propName ' );
250257 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ value );
251258 $ this ->assertEquals (\PHPCR \PropertyType::NAME , $ value ->getType ());
252259 $ this ->assertEquals ('jcr:name ' , $ value ->getString ());
@@ -270,7 +277,7 @@ public function testCreateValuePath()
270277 $ this ->assertEquals ('/some/path ' , $ value ->getString ());
271278
272279 $ this ->saveAndRenewSession ();
273- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propPath ' );
280+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propPath ' );
274281 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ value );
275282 $ this ->assertEquals (\PHPCR \PropertyType::PATH , $ value ->getType ());
276283 $ this ->assertEquals ('/some/path ' , $ value ->getString ());
@@ -294,7 +301,7 @@ public function testCreateValueUri()
294301 $ this ->assertEquals ('http://some/uri ' , $ value ->getString ());
295302
296303 $ this ->saveAndRenewSession ();
297- $ value = $ this ->sharedFixture [ ' session ' ] ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propUri ' );
304+ $ value = $ this ->session ->getProperty ('/tests_general_base/numberPropertyNode/jcr:content/propUri ' );
298305 $ this ->assertInstanceOf ('PHPCR\PropertyInterface ' , $ value );
299306 $ this ->assertEquals (\PHPCR \PropertyType::URI , $ value ->getType ());
300307 $ this ->assertEquals ('http://some/uri ' , $ value ->getString ());
@@ -305,7 +312,35 @@ public function testCreateValueUri()
305312 */
306313 public function testCreateValueUriInvalidUri ()
307314 {
308- $ value = $ this ->node ->setProperty ('propUri ' , '\\This/is\invalid ' , \PHPCR \PropertyType::URI );
315+ $ this ->node ->setProperty ('propUri ' , '\\This/is\invalid ' , \PHPCR \PropertyType::URI );
316+ $ this ->saveAndRenewSession ();
317+ }
318+
319+ public function testCopyPropertyString ()
320+ {
321+ $ path = $ this ->node ->getPath ();
322+ $ this ->node ->setProperty ('copyPropString ' , $ this ->property , PropertyType::STRING );
323+ $ this ->saveAndRenewSession ();
324+ $ this ->assertTrue ($ this ->session ->getNode ($ path )->hasProperty ('copyPropString ' ));
325+ $ prop = $ this ->session ->getNode ($ path )->getProperty ('copyPropString ' );
326+ $ this ->assertEquals (PropertyType::STRING , $ prop ->getType ());
327+ $ this ->assertSame ('999 ' , $ prop ->getValue ());
328+ }
329+
330+ public function testCopyPropertyBinary ()
331+ {
332+ $ path = $ this ->node ->getPath ();
333+ $ prop = $ this ->session ->getProperty ('/tests_general_base/index.txt/jcr:content/jcr:data ' );
334+ $ this ->assertEquals (\PHPCR \PropertyType::BINARY , $ prop ->getType (), 'Expected binary type ' );
335+ $ data = $ prop ->getString ();
336+ $ length = $ prop ->getLength ();
337+
338+ $ this ->node ->setProperty ('copyPropBinary ' , $ prop );
309339 $ this ->saveAndRenewSession ();
340+ $ this ->assertTrue ($ this ->session ->getNode ($ path )->hasProperty ('copyPropBinary ' ));
341+ $ newProp = $ this ->session ->getNode ($ path )->getProperty ('copyPropBinary ' );
342+ $ this ->assertEquals (PropertyType::BINARY , $ newProp ->getType ());
343+ $ this ->assertEquals ($ length , $ newProp ->getLength ());
344+ $ this ->assertEquals ($ data , $ newProp ->getString ());
310345 }
311346}
0 commit comments