Skip to content

Commit 431c29b

Browse files
committed
Merge pull request #126 from phpcr/test-overwrite-systemtypes
add tests trying to overwrite a built-in node type
2 parents c381af4 + 529f4bf commit 431c29b

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

tests/19_NodeTypeManagement/CndTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ protected function registerNodeTypePrimaryItem()
2323
return $ntm->registerNodeTypesCnd($this->primary_item_cnd, true);
2424
}
2525

26+
protected function registerBuiltinNodeType()
27+
{
28+
$ntm = $this->workspace->getNodeTypeManager();
29+
30+
return $ntm->registerNodeTypesCnd($this->system_cnd, true);
31+
}
32+
2633
private $cnd = "
2734
<'phpcr'='http://www.doctrine-project.org/projects/phpcr_odm'>
2835
[phpcr:apitest]
@@ -39,4 +46,10 @@ protected function registerNodeTypePrimaryItem()
3946
- phpcr:content (string)
4047
primary
4148
";
49+
50+
private $system_cnd = "
51+
<'nt'='http://www.jcp.org/jcr/nt/1.0'>
52+
[nt:file]
53+
- x (string)
54+
";
4255
}

tests/19_NodeTypeManagement/NodeTypeBaseCase.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected function setUp()
2929
$this->renewSession(); // reset session
3030
parent::setUp();
3131

32-
$this->session = $this->session;
3332
$this->workspace = $this->session->getWorkspace();
3433
}
3534

@@ -53,6 +52,14 @@ abstract protected function registerNodeTypes($allowUpdate);
5352
*/
5453
abstract protected function registerNodeTypePrimaryItem();
5554

55+
/**
56+
* Try to register a node type with an object or cnd that would overwrite
57+
* a build-in node type, e.g. nt:file
58+
*
59+
* Have allowUpdate true, should still fail.
60+
*/
61+
abstract protected function registerBuiltinNodeType();
62+
5663
public function testRegisterNodeTypes()
5764
{
5865
$types = $this->registerNodeTypes(true);
@@ -159,4 +166,12 @@ public function testPrimaryItem()
159166
$this->assertInstanceOf('PHPCR\ItemInterface', $node);
160167
$this->assertEquals('phpcr:content', $primary->getName());
161168
}
169+
170+
/**
171+
* @expectedException \PHPCR\RepositoryException
172+
*/
173+
public function testOverwriteBuiltinNodeType()
174+
{
175+
$this->registerBuiltinNodeType();
176+
}
162177
}

tests/19_NodeTypeManagement/NodeTypeTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,21 @@ protected function registerNodeTypePrimaryItem()
6060

6161
return $ntm->registerNodeTypes($nodeTypes, true);
6262
}
63+
64+
protected function registerBuiltinNodeType()
65+
{
66+
$ntm = $this->workspace->getNodeTypeManager();
67+
68+
$test = $ntm->createNodeTypeTemplate();
69+
$test->setName('nt:file');
70+
71+
$prop = $ntm->createPropertyDefinitionTemplate();
72+
$prop->setName('x');
73+
$prop->setRequiredType(PropertyType::STRING);
74+
$test->getPropertyDefinitionTemplates()->append($prop);
75+
76+
$nodeTypes[] = $test;
77+
78+
return $ntm->registerNodeTypes($nodeTypes, true);
79+
}
6380
}

0 commit comments

Comments
 (0)