Skip to content

Commit 7003ffb

Browse files
committed
adding some missing nodehelper tests
1 parent c32786b commit 7003ffb

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

tests/PHPCR/Tests/Util/NodeHelperTest.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use PHPCR\Util\NodeHelper;
66

7+
require_once(__DIR__.'/../Stubs/MockNode.php');
8+
79
class NodeHelperTest extends \PHPUnit_Framework_TestCase
810
{
911
private $namespaces = array('a' => 'http://phpcr', 'b' => 'http://jcr');
@@ -27,7 +29,10 @@ public static function invalidHints() {
2729
array('a'), // no colon
2830
array('a:foo:'),
2931
array('{foo'),
30-
array('x'), // not an existing namespace
32+
array('x:'), // not an existing namespace prefix
33+
array('{http://xy}'), // not an existing namespace uri
34+
array('x:a'), // not an existing namespace prefix with a local name prefix
35+
array('{http://xy}a'), // not an existing namespace uri with a local name prefix
3136
);
3237
}
3338

@@ -59,6 +64,49 @@ public function testGenerateAutoNodeNameInvalid($hint)
5964
NodeHelper::generateAutoNodeName($this->usedNames, $this->namespaces, 'a', $hint);
6065
}
6166

67+
public function testIsSystemItem()
68+
{
69+
$sys = $this->getMock('PHPCR\Tests\Stubs\MockNode');
70+
$sys->expects($this->once())
71+
->method('getDepth')
72+
->will($this->returnValue(0))
73+
;
74+
$sys->expects($this->once())
75+
->method('getName')
76+
->will($this->returnValue('jcr:root'))
77+
;
78+
$this->assertTrue(NodeHelper::isSystemItem($sys));
79+
80+
$sys = $this->getMock('PHPCR\Tests\Stubs\MockNode');
81+
$sys->expects($this->once())
82+
->method('getDepth')
83+
->will($this->returnValue(1))
84+
;
85+
$sys->expects($this->once())
86+
->method('getName')
87+
->will($this->returnValue('jcr:system'))
88+
;
89+
$this->assertTrue(NodeHelper::isSystemItem($sys));
90+
91+
$top = $this->getMock('PHPCR\Tests\Stubs\MockNode');
92+
$top->expects($this->once())
93+
->method('getDepth')
94+
->will($this->returnValue(1))
95+
;
96+
$top->expects($this->once())
97+
->method('getName')
98+
->will($this->returnValue('jcrname')) // this is NOT in the jcr namespace
99+
;
100+
$this->assertFalse(NodeHelper::isSystemItem($top));
101+
102+
$deep = $this->getMock('PHPCR\Tests\Stubs\MockNode');
103+
$deep->expects($this->once())
104+
->method('getDepth')
105+
->will($this->returnValue(2))
106+
;
107+
$this->assertFalse(NodeHelper::isSystemItem($deep));
108+
}
109+
62110
public function testCalculateOrderBeforeSwapLast()
63111
{
64112
$old = array('one', 'two', 'three', 'four');
@@ -102,6 +150,21 @@ public function testCalculateOrderBeforeReverse()
102150
$this->assertEquals($expected, $reorders);
103151
}
104152

153+
public function testCalculateOrderBeforeDeleted()
154+
{
155+
$old = array('one', 'two', 'three', 'four');
156+
$new = array('one', 'three', 'two');
157+
158+
$reorders = NodeHelper::calculateOrderBefore($old, $new);
159+
160+
$expected = array(
161+
'two' => null,
162+
'one' => 'three', // TODO: this is an unnecessary but harmless NOOP. we should try to eliminate
163+
);
164+
$this->assertEquals($expected, $reorders);
165+
}
166+
167+
105168
/**
106169
* @group benchmark
107170
*/

tests/PHPCR/Tests/Util/ValueConverterTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use PHPCR\PropertyType;
55
use PHPCR\Util\ValueConverter;
66

7+
require_once(__DIR__.'/../Stubs/MockNode.php');
8+
79
/**
810
* a test for the PHPCR\PropertyType class
911
*/
@@ -42,7 +44,7 @@ public function dataConversionMatrix()
4244
$datetimeLong = new \DateTime();
4345
$datetimeLong->setTimestamp(123);
4446

45-
$nodemock = $this->getMock('PHPCR\\Tests\\Util\\NodeMock');
47+
$nodemock = $this->getMock('PHPCR\Tests\Stubs\MockNode');
4648
$nodemock
4749
->expects($this->any())
4850
->method('getIdentifier')
@@ -383,7 +385,7 @@ public function testConvertInvalidDate()
383385
*/
384386
public function testConvertNewNode()
385387
{
386-
$nodemock = $this->getMock('PHPCR\\Tests\\Util\\NodeMock');
388+
$nodemock = $this->getMock('PHPCR\Tests\Stubs\MockNode');
387389
$nodemock
388390
->expects($this->once())
389391
->method('isNew')
@@ -396,7 +398,7 @@ public function testConvertNewNode()
396398
*/
397399
public function testConvertNonrefNode()
398400
{
399-
$nodemock = $this->getMock('PHPCR\\Tests\\Util\\NodeMock');
401+
$nodemock = $this->getMock('PHPCR\Tests\Stubs\MockNode');
400402
$nodemock
401403
->expects($this->once())
402404
->method('isNew')
@@ -438,6 +440,3 @@ public function testConvertTypeInvalidTarget()
438440
$this->valueConverter->convertType('test', PropertyType::UNDEFINED);
439441
}
440442
}
441-
442-
interface NodeMock extends \Iterator, \PHPCR\NodeInterface
443-
{}

0 commit comments

Comments
 (0)