Skip to content

Commit 1088213

Browse files
committed
Merge pull request #145 from phpcr/test-repeated-reference
test reading multivalue property with the same reference twice
2 parents 73ff499 + a86c8e8 commit 1088213

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

fixtures/general/base.xml

+10
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@
164164
</sv:property>
165165
</sv:node>
166166

167+
<sv:node sv:name="weakreference_repeated">
168+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
169+
<sv:value>nt:unstructured</sv:value>
170+
</sv:property>
171+
<sv:property sv:name="other_ref" sv:type="WeakReference">
172+
<sv:value>13543fc6-1abf-4708-bfcc-e49511754b40</sv:value>
173+
<sv:value>13543fc6-1abf-4708-bfcc-e49511754b40</sv:value>
174+
</sv:property>
175+
</sv:node>
176+
167177
</sv:node>
168178
</sv:node>
169179

tests/05_Reading/NodeReadMethodsTest.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,17 @@ public function testGetPropertiesValuesGlob()
396396
}
397397
}
398398

399+
public function testGetReferencePropertyRepeated()
400+
{
401+
$node = $this->session->getNode('/tests_general_base/idExample/jcr:content/weakreference_repeated');
402+
$refs = $node->getPropertyValue('other_ref');
403+
$this->assertInternalType('array', (array) $refs);
404+
$this->assertCount(2, $refs);
405+
foreach ($refs as $node) {
406+
$this->assertInstanceOf('PHPCR\NodeInterface', $node);
407+
}
408+
}
409+
399410
/**
400411
* @group getPrimaryItem
401412
*/
@@ -526,11 +537,13 @@ public function testGetWeakReferencesAll()
526537
$target = $this->rootNode->getNode('tests_general_base/idExample/jcr:content/weakreference_target');
527538
$source[] = $this->rootNode->getProperty('tests_general_base/idExample/jcr:content/weakreference_source1/ref1');
528539
$source[] = $this->rootNode->getProperty('tests_general_base/idExample/jcr:content/weakreference_source2/ref2');
540+
$source[] = $this->rootNode->getProperty('tests_general_base/idExample/jcr:content/weakreference_repeated/other_ref');
529541

530542
$iterator = $target->getWeakReferences();
531543
$this->assertInstanceOf('Iterator', $iterator);
532544

533-
$this->assertCount(2, $iterator, "Wrong number of weak references to weakreference_target");
545+
// there are 4 different references, but 2 come from the same property so should only count once.
546+
$this->assertCount(3, $iterator, "Wrong number of weak references to weakreference_target");
534547
foreach ($iterator as $prop) {
535548
$this->assertInstanceOf('\PHPCR\PropertyInterface', $prop);
536549
$this->assertTrue(in_array($prop, $source, true));
@@ -608,7 +621,7 @@ public function testHasNodePathTrue()
608621
}
609622

610623
/**
611-
* @expectedException InvalidArgumentException
624+
* @expectedException \InvalidArgumentException
612625
*/
613626
public function testHasNodeAbsolutePathException()
614627
{
@@ -642,7 +655,7 @@ public function testHasPropertyFalse()
642655
}
643656

644657
/**
645-
* @expectedException InvalidArgumentException
658+
* @expectedException \InvalidArgumentException
646659
*/
647660
public function testHasPropertyAbsolutePathException()
648661
{

tests/06_Query/QuerySql2OperationsTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public function testQueryFieldSomeNull()
5757
$vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null);
5858
}
5959
$this->assertContains('bar', $vals);
60-
$this->assertCount(9, $vals);
60+
$this->assertCount(10, $vals);
6161

6262
$vals = array();
6363
foreach ($result->getRows() as $row) {
6464
$vals[] = $row->getValue('foo');
6565
}
6666
$this->assertContains('bar', $vals);
67-
$this->assertCount(9, $vals);
67+
$this->assertCount(10, $vals);
6868
}
6969

7070
public function testQueryFieldSelector()
@@ -182,7 +182,7 @@ public function testQueryLeftJoin()
182182
}
183183

184184
// We get 9 results (idExample comes back multiple times because of the join)
185-
$this->assertCount(9, $result->getRows());
185+
$this->assertCount(10, $result->getRows());
186186
$this->assertEquals(array(
187187
'index.txt' => null,
188188
'idExample' => null,
@@ -212,8 +212,8 @@ public function testQueryRightJoin()
212212
$vals[basename($row->getPath('file'))] = $row->getValue('target.stringToCompare');
213213
}
214214

215-
// We get 9 results (idExample comes back multiple times because of the join)
216-
$this->assertCount(9, $result->getRows());
215+
// We get 10 results (idExample comes back multiple times because of the join)
216+
$this->assertCount(10, $result->getRows());
217217
$this->assertEquals(array(
218218
'index.txt' => null,
219219
'idExample' => null,
@@ -315,7 +315,7 @@ public function testQueryOrderWithMissingProperty()
315315
$vals[] = $row->getValue('data.zeronumber');
316316
}
317317
// rows that do not have that field are empty string. empty is before fields with values
318-
$this->assertEquals(array('', '', '', '', '', '', '', '', 0), $vals);
318+
$this->assertEquals(array('', '', '', '', '', '', '', '', '', 0), $vals);
319319
}
320320

321321
public function testQueryMultiValuedProperty()

tests/06_Query/Sql1/QueryOperationsTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ public function testQueryFieldSomenull()
5353
$vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null);
5454
}
5555
$this->assertContains('bar', $vals);
56-
$this->assertCount(9, $vals);
56+
$this->assertCount(10, $vals);
5757

5858
$vals = array();
5959
foreach ($result->getRows() as $row) {
6060
$vals[] = $row->getValue('foo');
6161
}
6262
$this->assertContains('bar', $vals);
63-
$this->assertCount(9, $vals);
63+
$this->assertCount(10, $vals);
6464
}
6565

6666
public function testQueryOrder()
@@ -82,7 +82,7 @@ public function testQueryOrder()
8282
$vals[] = $row->getValue('zeronumber');
8383
}
8484
// rows that do not have that field are null. empty is before fields with values
85-
$this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals);
85+
$this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals);
8686
}
8787

8888
}

tests/06_Query/XPath/QueryOperationsTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public function testQueryFieldSomenull()
5050
$vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null);
5151
}
5252
$this->assertContains('bar', $vals);
53-
$this->assertCount(9, $vals);
53+
$this->assertCount(10, $vals);
5454

5555
$vals = array();
5656
foreach ($result->getRows() as $row) {
5757
$vals[] = $row->getValue('foo');
5858
}
5959
$this->assertContains('bar', $vals);
60-
$this->assertCount(9, $vals);
60+
$this->assertCount(10, $vals);
6161
}
6262

6363
public function testQueryOrder()
@@ -76,7 +76,7 @@ public function testQueryOrder()
7676
$vals[] = $row->getValue('zeronumber');
7777
}
7878
// rows that do not have that field are null. empty is before fields with values
79-
$this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals);
79+
$this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals);
8080
}
8181

8282
}

0 commit comments

Comments
 (0)