Skip to content

Commit f225159

Browse files
committed
Merge pull request #92 from phpcr/test-set-property-property
test setting a property to the value of another property
2 parents 5edee44 + 400d940 commit f225159

File tree

3 files changed

+77
-29
lines changed

3 files changed

+77
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PHPCR API tests
22

3-
Test suite to test implemenations against the PHPCR API interfaces.
3+
Test suite to test implementations against the PHPCR API interfaces.
44

55
The tests are organised by feature, with the numbers referencing the chapter
66
numbers in the JCR v2.0 specification, JSR 283.

inc/BaseCase.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace PHPCR\Test;
33

4+
use PHPCR\SessionInterface;
45
use PHPCR\NodeInterface;
56

67
// PHPUnit 3.4 compat
@@ -13,7 +14,18 @@
1314
*/
1415
abstract class BaseCase extends \PHPUnit_Framework_TestCase
1516
{
16-
protected $path = ''; // Describes the path to the test
17+
/**
18+
* Describes the path to the node for this test, used with writing tests
19+
*
20+
* @var string
21+
*/
22+
protected $path = '';
23+
24+
/**
25+
*
26+
* @var SessionInterface
27+
*/
28+
protected $session;
1729

1830
/**
1931
* The root node of the fixture, initialized for each test
@@ -158,7 +170,7 @@ protected function renewSession()
158170
*/
159171
protected function saveAndRenewSession()
160172
{
161-
$this->sharedFixture['session']->save();
173+
$this->session->save();
162174
$this->renewSession();
163175
return $this->sharedFixture['session'];
164176
}
@@ -172,9 +184,10 @@ protected function saveAndRenewSession()
172184
*/
173185
protected function initProperties()
174186
{
187+
$this->session = $this->sharedFixture['session'];
175188
$this->node = null;
176189

177-
$this->rootNode = $this->sharedFixture['session']->getRootNode();
190+
$this->rootNode = $this->session->getRootNode();
178191

179192
$children = $this->rootNode->getNodes("tests_*");
180193
$child = current($children);

tests/10_Writing/SetPropertyTypesTest.php

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
namespace PHPCR\Tests\Writing;
33

4+
use PHPCR\PropertyInterface;
5+
use PHPCR\PropertyType;
6+
use PHPCR\SessionInterface;
7+
48
require_once(__DIR__ . '/../../inc/BaseCase.php');
59

610
/**
@@ -14,13 +18,16 @@
1418
*/
1519
class 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

Comments
 (0)