44
55use PHPCR \Util \NodeHelper ;
66
7+ require_once (__DIR__ .'/../Stubs/MockNode.php ' );
8+
79class 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 */
0 commit comments