From a86c8e8c1f7c85e32eaa354fa6f7ee7de1269032 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 11 Dec 2014 17:38:53 +0100 Subject: [PATCH] test reading multivalue property with the same reference twice --- fixtures/general/base.xml | 10 ++++++++++ tests/05_Reading/NodeReadMethodsTest.php | 19 ++++++++++++++++--- tests/06_Query/QuerySql2OperationsTest.php | 12 ++++++------ tests/06_Query/Sql1/QueryOperationsTest.php | 6 +++--- tests/06_Query/XPath/QueryOperationsTest.php | 6 +++--- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/fixtures/general/base.xml b/fixtures/general/base.xml index 9da9e31e..5e594bf4 100644 --- a/fixtures/general/base.xml +++ b/fixtures/general/base.xml @@ -158,6 +158,16 @@ + + + nt:unstructured + + + 13543fc6-1abf-4708-bfcc-e49511754b40 + 13543fc6-1abf-4708-bfcc-e49511754b40 + + + diff --git a/tests/05_Reading/NodeReadMethodsTest.php b/tests/05_Reading/NodeReadMethodsTest.php index 23de23a1..5342ae6f 100644 --- a/tests/05_Reading/NodeReadMethodsTest.php +++ b/tests/05_Reading/NodeReadMethodsTest.php @@ -396,6 +396,17 @@ public function testGetPropertiesValuesGlob() } } + public function testGetReferencePropertyRepeated() + { + $node = $this->session->getNode('/tests_general_base/idExample/jcr:content/weakreference_repeated'); + $refs = $node->getPropertyValue('other_ref'); + $this->assertInternalType('array', (array) $refs); + $this->assertCount(2, $refs); + foreach ($refs as $node) { + $this->assertInstanceOf('PHPCR\NodeInterface', $node); + } + } + /** * @group getPrimaryItem */ @@ -526,11 +537,13 @@ public function testGetWeakReferencesAll() $target = $this->rootNode->getNode('tests_general_base/idExample/jcr:content/weakreference_target'); $source[] = $this->rootNode->getProperty('tests_general_base/idExample/jcr:content/weakreference_source1/ref1'); $source[] = $this->rootNode->getProperty('tests_general_base/idExample/jcr:content/weakreference_source2/ref2'); + $source[] = $this->rootNode->getProperty('tests_general_base/idExample/jcr:content/weakreference_repeated/other_ref'); $iterator = $target->getWeakReferences(); $this->assertInstanceOf('Iterator', $iterator); - $this->assertCount(2, $iterator, "Wrong number of weak references to weakreference_target"); + // there are 4 different references, but 2 come from the same property so should only count once. + $this->assertCount(3, $iterator, "Wrong number of weak references to weakreference_target"); foreach ($iterator as $prop) { $this->assertInstanceOf('\PHPCR\PropertyInterface', $prop); $this->assertTrue(in_array($prop, $source, true)); @@ -608,7 +621,7 @@ public function testHasNodePathTrue() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testHasNodeAbsolutePathException() { @@ -642,7 +655,7 @@ public function testHasPropertyFalse() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testHasPropertyAbsolutePathException() { diff --git a/tests/06_Query/QuerySql2OperationsTest.php b/tests/06_Query/QuerySql2OperationsTest.php index 3e9ea969..c15bef49 100644 --- a/tests/06_Query/QuerySql2OperationsTest.php +++ b/tests/06_Query/QuerySql2OperationsTest.php @@ -57,14 +57,14 @@ public function testQueryFieldSomeNull() $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null); } $this->assertContains('bar', $vals); - $this->assertCount(9, $vals); + $this->assertCount(10, $vals); $vals = array(); foreach ($result->getRows() as $row) { $vals[] = $row->getValue('foo'); } $this->assertContains('bar', $vals); - $this->assertCount(9, $vals); + $this->assertCount(10, $vals); } public function testQueryFieldSelector() @@ -182,7 +182,7 @@ public function testQueryLeftJoin() } // We get 9 results (idExample comes back multiple times because of the join) - $this->assertCount(9, $result->getRows()); + $this->assertCount(10, $result->getRows()); $this->assertEquals(array( 'index.txt' => null, 'idExample' => null, @@ -212,8 +212,8 @@ public function testQueryRightJoin() $vals[basename($row->getPath('file'))] = $row->getValue('target.stringToCompare'); } - // We get 9 results (idExample comes back multiple times because of the join) - $this->assertCount(9, $result->getRows()); + // We get 10 results (idExample comes back multiple times because of the join) + $this->assertCount(10, $result->getRows()); $this->assertEquals(array( 'index.txt' => null, 'idExample' => null, @@ -315,7 +315,7 @@ public function testQueryOrderWithMissingProperty() $vals[] = $row->getValue('data.zeronumber'); } // rows that do not have that field are empty string. empty is before fields with values - $this->assertEquals(array('', '', '', '', '', '', '', '', 0), $vals); + $this->assertEquals(array('', '', '', '', '', '', '', '', '', 0), $vals); } public function testQueryMultiValuedProperty() diff --git a/tests/06_Query/Sql1/QueryOperationsTest.php b/tests/06_Query/Sql1/QueryOperationsTest.php index 7b134b61..e7f95b34 100644 --- a/tests/06_Query/Sql1/QueryOperationsTest.php +++ b/tests/06_Query/Sql1/QueryOperationsTest.php @@ -53,14 +53,14 @@ public function testQueryFieldSomenull() $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null); } $this->assertContains('bar', $vals); - $this->assertCount(9, $vals); + $this->assertCount(10, $vals); $vals = array(); foreach ($result->getRows() as $row) { $vals[] = $row->getValue('foo'); } $this->assertContains('bar', $vals); - $this->assertCount(9, $vals); + $this->assertCount(10, $vals); } public function testQueryOrder() @@ -82,7 +82,7 @@ public function testQueryOrder() $vals[] = $row->getValue('zeronumber'); } // rows that do not have that field are null. empty is before fields with values - $this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals); + $this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals); } } diff --git a/tests/06_Query/XPath/QueryOperationsTest.php b/tests/06_Query/XPath/QueryOperationsTest.php index 9108f134..1b9d0082 100644 --- a/tests/06_Query/XPath/QueryOperationsTest.php +++ b/tests/06_Query/XPath/QueryOperationsTest.php @@ -50,14 +50,14 @@ public function testQueryFieldSomenull() $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null); } $this->assertContains('bar', $vals); - $this->assertCount(9, $vals); + $this->assertCount(10, $vals); $vals = array(); foreach ($result->getRows() as $row) { $vals[] = $row->getValue('foo'); } $this->assertContains('bar', $vals); - $this->assertCount(9, $vals); + $this->assertCount(10, $vals); } public function testQueryOrder() @@ -76,7 +76,7 @@ public function testQueryOrder() $vals[] = $row->getValue('zeronumber'); } // rows that do not have that field are null. empty is before fields with values - $this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals); + $this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals); } }