|
11 | 11 |
|
12 | 12 | namespace PHPCR\Tests\NodeTypeManagement;
|
13 | 13 |
|
| 14 | +use PHPCR\NodeType\NodeTypeDefinitionInterface; |
14 | 15 | use PHPCR\PropertyType;
|
15 | 16 |
|
16 | 17 | /**
|
17 | 18 | * Covering jcr-2.8.3 spec $19.
|
18 | 19 | */
|
19 | 20 | class NodeTypeTest extends NodeTypeBaseCase
|
20 | 21 | {
|
| 22 | + public function testRegisterNodeType() |
| 23 | + { |
| 24 | + $ns = $this->workspace->getNamespaceRegistry(); |
| 25 | + $ns->registerNamespace('phpcr', 'http://www.doctrine-project.org/projects/phpcr_odm'); |
| 26 | + |
| 27 | + $ntm = $this->workspace->getNodeTypeManager(); |
| 28 | + |
| 29 | + $apitest = $ntm->createNodeTypeTemplate(); |
| 30 | + $apitest->setName('phpcr:apitest'); |
| 31 | + $apitest->setMixin(true); |
| 32 | + |
| 33 | + $class = $ntm->createPropertyDefinitionTemplate(); |
| 34 | + $class->setName('phpcr:class'); |
| 35 | + $class->setRequiredType(PropertyType::STRING); |
| 36 | + $class->setMultiple(true); |
| 37 | + $apitest->getPropertyDefinitionTemplates()->append($class); |
| 38 | + |
| 39 | + $type = $ntm->registerNodeType($apitest, true); |
| 40 | + |
| 41 | + $this->assertApitestType($type); |
| 42 | + |
| 43 | + $session = $this->renewSession(); |
| 44 | + $ntm = $session->getWorkspace()->getNodeTypeManager(); |
| 45 | + |
| 46 | + $this->assertTrue($ntm->hasNodeType('phpcr:apitest')); |
| 47 | + $this->assertApitestType($ntm->getNodeType('phpcr:apitest')); |
| 48 | + } |
| 49 | + |
| 50 | + private function assertApitestType($type) |
| 51 | + { |
| 52 | + $this->assertInstanceOf(NodeTypeDefinitionInterface::class, $type); |
| 53 | + /* @var $type NodeTypeDefinitionInterface */ |
| 54 | + $this->assertEquals('phpcr:apitest', $type->getName()); |
| 55 | + $props = $type->getDeclaredPropertyDefinitions(); |
| 56 | + $this->assertCount(1, $props, 'Wrong number of properties in phpcr:apitest'); |
| 57 | + $this->assertEquals('phpcr:class', $props[0]->getName()); |
| 58 | + $this->assertTrue($props[0]->isMultiple()); |
| 59 | + } |
| 60 | + |
21 | 61 | protected function registerNodeTypes($allowUpdate)
|
22 | 62 | {
|
23 | 63 | $ns = $this->workspace->getNamespaceRegistry();
|
|
0 commit comments