Skip to content

Commit d8437ef

Browse files
committed
Merge pull request #170 from phpcr/rederrik-copy-children-binary
more tests for multivalue binary operations
2 parents 0a72af5 + 3b3b9c4 commit d8437ef

File tree

4 files changed

+99
-11
lines changed

4 files changed

+99
-11
lines changed

fixtures/10_Writing/copy.xml

+23-2
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,32 @@
493493
<sv:property sv:name="jcr:primaryType" sv:type="Name">
494494
<sv:value>nt:unstructured</sv:value>
495495
</sv:property>
496-
<sv:node sv:name="data.bin">
496+
<sv:node sv:name="single">
497497
<sv:property sv:name="jcr:primaryType" sv:type="Name">
498498
<sv:value>nt:unstructured</sv:value>
499499
</sv:property>
500-
<sv:property sv:name="jcr:data" sv:type="Binary"><sv:value>RnVzY2UgZmVybWVudHVtLiBBbGlxdWFtIGxvYm9ydGlzLiBNYXVyaXMgdHVycGlzIG51bmMsIGJsYW5kaXQgZXQsIHZvbHV0cGF0IG1vbGVzdGllLCBwb3J0YSB1dCwgbGlndWxhLiBQZWxsZW50ZXNxdWUgYXVjdG9yIG5lcXVlIG5lYyB1cm5hLiBQcm9pbiBtYWduYS4gQ3VyYWJpdHVyIHVsbGFtY29ycGVyIHVsdHJpY2llcyBuaXNpLiBQcmFlc2VudCBjb25ndWUgZXJhdCBhdCBtYXNzYS4gTmFtIGFkaXBpc2NpbmcuIE51bGxhIHBvcnRhIGRvbG9yLiBGdXNjZSBjb21tb2RvIGFsaXF1YW0gYXJjdS4=</sv:value>
500+
<sv:property sv:name="jcr:data" sv:type="Binary">
501+
<sv:value>RnVzY2UgZmVybWVudHVtLiBBbGlxdWFtIGxvYm9ydGlzLiBNYXVyaXMgdHVycGlzIG51bmMsIGJsYW5kaXQgZXQsIHZvbHV0cGF0IG1vbGVzdGllLCBwb3J0YSB1dCwgbGlndWxhLiBQZWxsZW50ZXNxdWUgYXVjdG9yIG5lcXVlIG5lYyB1cm5hLiBQcm9pbiBtYWduYS4gQ3VyYWJpdHVyIHVsbGFtY29ycGVyIHVsdHJpY2llcyBuaXNpLiBQcmFlc2VudCBjb25ndWUgZXJhdCBhdCBtYXNzYS4gTmFtIGFkaXBpc2NpbmcuIE51bGxhIHBvcnRhIGRvbG9yLiBGdXNjZSBjb21tb2RvIGFsaXF1YW0gYXJjdS4=</sv:value>
502+
</sv:property>
503+
</sv:node>
504+
</sv:node>
505+
</sv:node>
506+
507+
<sv:node sv:name="testCopyChildrenBinaryDataMultivalue">
508+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
509+
<sv:value>nt:unstructured</sv:value>
510+
</sv:property>
511+
<sv:node sv:name="srcNode">
512+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
513+
<sv:value>nt:unstructured</sv:value>
514+
</sv:property>
515+
<sv:node sv:name="multiple">
516+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
517+
<sv:value>nt:unstructured</sv:value>
518+
</sv:property>
519+
<sv:property sv:name="jcr:data" sv:type="Binary" sv:multiple="true">
520+
<sv:value>RnVzY2UgZmVybWVudHVtLiBBbGlxdWFtIGxvYm9ydGlzLiBNYXVyaXMgdHVycGlzIG51bmMsIGJsYW5kaXQgZXQsIHZvbHV0cGF0IG1vbGVzdGllLCBwb3J0YSB1dCwgbGlndWxhLiBQZWxsZW50ZXNxdWUgYXVjdG9yIG5lcXVlIG5lYyB1cm5hLiBQcm9pbiBtYWduYS4gQ3VyYWJpdHVyIHVsbGFtY29ycGVyIHVsdHJpY2llcyBuaXNpLiBQcmFlc2VudCBjb25ndWUgZXJhdCBhdCBtYXNzYS4gTmFtIGFkaXBpc2NpbmcuIE51bGxhIHBvcnRhIGRvbG9yLiBGdXNjZSBjb21tb2RvIGFsaXF1YW0gYXJjdS4=</sv:value>
521+
<sv:value>RnVzY2UgZmVybWVudHVtLiBBbGlxdWFtIGxvYm9ydGlzLiBNYXVyaXMgdHVycGlzIG51bmMsIGJsYW5kaXQgZXQsIHZvbHV0cGF0IG1vbGVzdGllLCBwb3J0YSB1dCwgbGlndWxhLiBQZWxsZW50ZXNxdWUgYXVjdG9yIG5lcXVlIG5lYyB1cm5hLiBQcm9pbiBtYWduYS4gQ3VyYWJpdHVyIHVsbGFtY29ycGVyIHVsdHJpY2llcyBuaXNpLiBQcmFlc2VudCBjb25ndWUgZXJhdCBhdCBtYXNzYS4gTmFtIGFkaXBpc2NpbmcuIE51bGxhIHBvcnRhIGRvbG9yLiBGdXNjZSBjb21tb2RvIGFsaXF1YW0gYXJjdS4=</sv:value>
501522
</sv:property>
502523
</sv:node>
503524
</sv:node>

fixtures/general/base.xml

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
<sv:value>aDEuIENoYXB0ZXIgMSBUaXRsZQoKKiBmb28KKiBiYXIKKiogZm9vMgoqKiBmb28zCiogZm9vMAoKfHwgaGVhZGVyIHx8IGJhciB8fAp8IGggfCBqIHwKCntjb2RlfQpoZWxsbyB3b3JsZAp7Y29kZX0KCiMgZm9vCg==</sv:value>
5454
<sv:value>aDEuIENoYXB0ZXIgMSBUaXRsZQoKKiBmb28KKiBiYXIKKiogZm9vMgoqKiBmb28zCiogZm9vMAoKfHwgaGVhZGVyIHx8IGJhciB8fAp8IGggfCBqIHwKCntjb2RlfQpoZWxsbyB3b3JsZAp7Y29kZX0KCiMgZm9vCg==</sv:value>
5555
</sv:property>
56+
<sv:property sv:name="single_multidata" sv:type="Binary" sv:multiple="true">
57+
<sv:value>aDEuIENoYXB0ZXIgMSBUaXRsZQoKKiBmb28KKiBiYXIKKiogZm9vMgoqKiBmb28zCiogZm9vMAoKfHwgaGVhZGVyIHx8IGJhciB8fAp8IGggfCBqIHwKCntjb2RlfQpoZWxsbyB3b3JsZAp7Y29kZX0KCiMgZm9vCg==</sv:value>
58+
</sv:property>
59+
<sv:property sv:name="empty_multidata" sv:type="Binary" sv:multiple="true">
60+
</sv:property>
5661
<sv:property sv:name="jcr:lastModified" sv:type="Date">
5762
<sv:value>2009-04-27T13:01:07.472+02:00</sv:value>
5863
</sv:property>

tests/Reading/BinaryReadMethodsTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,33 @@ public function testReadBinaryPathTrailingQuestionmark()
146146
$this->assertInternalType('string', $value);
147147
$this->assertEquals($this->decodedstring, $value);
148148
}
149+
150+
/**
151+
* Verifies that we still can read empty data from multivalue binary properties
152+
* @group multitest
153+
*/
154+
public function testReadEmptyBinaryMultivalue()
155+
{
156+
$node = $this->session->getRootNode()->getNode('tests_general_base/index.txt/jcr:content');
157+
$empty = $node->getProperty('empty_multidata');
158+
$this->assertEquals(\PHPCR\PropertyType::BINARY, $empty->getType());
159+
$emptyValue = $empty->getBinary();
160+
$this->assertTrue(is_array($emptyValue));
161+
$this->assertTrue(count($emptyValue) === 0);
162+
}
163+
164+
/**
165+
* Verifies that we still can read empty data from multivalue binary properties
166+
*/
167+
public function testReadSingleBinaryMultivalue()
168+
{
169+
$node = $this->session->getRootNode()->getNode('tests_general_base/index.txt/jcr:content');
170+
$single = $node->getProperty('single_multidata');
171+
$this->assertEquals(\PHPCR\PropertyType::BINARY, $single->getType());
172+
$singleValue = $single->getBinary();
173+
$this->assertTrue(is_array($singleValue));
174+
$this->assertTrue(is_resource($singleValue[0]));
175+
$contents = stream_get_contents($singleValue[0]);
176+
$this->assertEquals($this->decodedstring, $contents);
177+
}
149178
}

tests/Writing/CopyMethodsTest.php

+42-9
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,54 @@ public function testCopyChildrenBinaryData()
250250

251251
$this->ws->copy($src, $dst);
252252
$this->session->refresh(true);
253-
$srcChild = $this->session->getNode($src.'/data.bin');
254-
$dstChild = $this->session->getNode($dst.'/data.bin');
255253

256-
$srcProp = $srcChild->getProperty('jcr:data');
257-
$dstProp = $dstChild->getProperty('jcr:data');
254+
//Single value
255+
$srcProp = $this->session->getNode($src . '/single')->getProperty('jcr:data');
256+
$dstProp = $this->session->getNode($dst . '/single')->getProperty('jcr:data');
258257

259258
$this->assertEquals(\PHPCR\PropertyType::BINARY, $srcProp->getType());
260259
$this->assertEquals(\PHPCR\PropertyType::BINARY, $dstProp->getType());
261260

262-
$srcBin = $srcProp->getBinary();
263-
$dstBin = $dstProp->getBinary();
261+
$srcVal = $srcProp->getBinary();
262+
$dstVal = $dstProp->getBinary();
264263

265-
$this->assertTrue(is_resource($srcBin), 'Failed to get src binary stream');
266-
$this->assertTrue(is_resource($dstBin), 'Failed to get dst binary stream');
264+
$this->assertTrue(is_resource($srcVal), 'Failed to get src binary stream');
265+
$this->assertTrue(is_resource($dstVal), 'Failed to get dst binary stream');
267266

268-
$this->assertEquals(stream_get_contents($srcBin), stream_get_contents($dstBin));
267+
$this->assertEquals(stream_get_contents($srcVal), stream_get_contents($dstVal));
268+
}
269+
270+
/**
271+
* Verifies that transport::copy actually copies binary data of children nodes
272+
* Multivalue test
273+
*/
274+
public function testCopyChildrenBinaryDataMultivalue()
275+
{
276+
$src = '/tests_write_manipulation_copy/testCopyChildrenBinaryDataMultivalue/srcNode';
277+
$dst = '/tests_write_manipulation_copy/testCopyChildrenBinaryDataMultivalue/dstNode';
278+
279+
$this->ws->copy($src, $dst);
280+
$this->session->refresh(true);
281+
282+
//Multivalue
283+
$srcProp = $this->session->getNode($src.'/multiple')->getProperty('jcr:data');
284+
$dstProp = $this->session->getNode($dst.'/multiple')->getProperty('jcr:data');
285+
286+
$this->assertEquals(\PHPCR\PropertyType::BINARY, $srcProp->getType());
287+
$this->assertEquals(\PHPCR\PropertyType::BINARY, $dstProp->getType());
288+
289+
$srcVal = $srcProp->getValue();
290+
$dstVal = $dstProp->getValue();
291+
292+
$this->assertTrue(is_array($srcVal), 'Failed to get src value');
293+
$this->assertTrue(is_array($dstVal), 'Failed to get dst value');
294+
295+
$this->assertTrue(is_resource($srcVal[0]));
296+
$this->assertTrue(is_resource($srcVal[1]));
297+
$this->assertTrue(is_resource($dstVal[0]));
298+
$this->assertTrue(is_resource($dstVal[1]));
299+
300+
$this->assertEquals(stream_get_contents($srcVal[0]), stream_get_contents($dstVal[0]));
301+
$this->assertEquals(stream_get_contents($srcVal[1]), stream_get_contents($dstVal[1]));
269302
}
270303
}

0 commit comments

Comments
 (0)