Skip to content

Commit c23efab

Browse files
committed
Merge pull request #158 from phpcr/null-in-multivalue
10.4.2.5 Multi-value Properties and Null
2 parents 92e596d + dd302a6 commit c23efab

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

tests/05_Reading/BinaryReadMethodsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testReadBinaryValueAsString()
7575
public function testGetLength()
7676
{
7777
$size = $this->binaryProperty->getLength();
78+
$this->assertInternalType('integer', $size);
7879
$this->assertEquals(strlen($this->decodedstring), $size);
7980
}
8081

@@ -113,6 +114,7 @@ public function testGetLengthMultivalue()
113114
$sizes = $binaryMulti->getLength();
114115
$this->assertInternalType('array', $sizes);
115116
foreach ($sizes as $size) {
117+
$this->assertInternalType('integer', $size);
116118
$this->assertEquals(strlen($this->decodedstring), $size);
117119
}
118120
}

tests/10_Writing/SetPropertyMethodsTest.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testSetPropertyMultivalue()
156156
$prop = $node->getProperty('multivalue');
157157
$this->assertEquals(\PHPCR\PropertyType::LONG, $prop->getType());
158158
$this->assertTrue($prop->isMultiple());
159-
$this->assertEquals(array(1,2,3), $prop->getValue('multivalue'));
159+
$this->assertEquals(array(1,2,3), $prop->getValue());
160160
}
161161

162162
public function testSetPropertyMultivalueOne()
@@ -171,7 +171,47 @@ public function testSetPropertyMultivalueOne()
171171
$prop = $node->getProperty('multivalue2');
172172
$this->assertEquals(\PHPCR\PropertyType::LONG, $prop->getType());
173173
$this->assertTrue($prop->isMultiple());
174-
$this->assertEquals(array(1), $prop->getValue('multivalue2'));
174+
$this->assertEquals(array(1), $prop->getValue());
175+
}
176+
177+
/**
178+
* 10.4.2.5 Multi-value Properties and Null
179+
*
180+
* Null values must be removed from the list of values.
181+
*/
182+
public function testSetPropertyMultivalueNull()
183+
{
184+
$prop = $this->node->setProperty('multivalue_null', array(1, null, 3));
185+
$this->assertEquals(array(1, 3), $this->node->getPropertyValue('multivalue_null'));
186+
$this->assertEquals(\PHPCR\PropertyType::LONG, $prop->getType());
187+
$this->assertTrue($prop->isMultiple());
188+
189+
$this->saveAndRenewSession();
190+
$node = $this->session->getNode($this->nodePath);
191+
$prop = $node->getProperty('multivalue_null');
192+
$this->assertEquals(\PHPCR\PropertyType::LONG, $prop->getType());
193+
$this->assertTrue($prop->isMultiple());
194+
$this->assertEquals(array(1, 3), $prop->getValue());
195+
}
196+
197+
/**
198+
* 10.4.2.5 Multi-value Properties and Null
199+
*
200+
* Null values must be removed from the list of values.
201+
*/
202+
public function testSetPropertyMultivalueAllNull()
203+
{
204+
$prop = $this->node->setProperty('multivalue_allnull', array(null, null, null));
205+
$this->assertEquals(array(), $this->node->getPropertyValue('multivalue_allnull'));
206+
$this->assertEquals(\PHPCR\PropertyType::STRING, $prop->getType());
207+
$this->assertTrue($prop->isMultiple());
208+
209+
$this->saveAndRenewSession();
210+
$node = $this->session->getNode($this->nodePath);
211+
$prop = $node->getProperty('multivalue_allnull');
212+
$this->assertEquals(\PHPCR\PropertyType::STRING, $prop->getType());
213+
$this->assertTrue($prop->isMultiple());
214+
$this->assertEquals(array(), $prop->getValue());
175215
}
176216

177217
public function testSetPropertyMultivalueRef()
@@ -187,7 +227,7 @@ public function testSetPropertyMultivalueRef()
187227
$prop = $node->getProperty('multiref');
188228
$this->assertEquals(\PHPCR\PropertyType::WEAKREFERENCE, $prop->getType());
189229
$this->assertTrue($prop->isMultiple());
190-
$this->assertEquals($ids, $prop->getString('multiref'));
230+
$this->assertEquals($ids, $prop->getString());
191231
$nodes = $prop->getValue();
192232
$this->assertInternalType('array', $nodes);
193233
$this->assertCount(3, $nodes);

0 commit comments

Comments
 (0)