|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPCR\Tests\NodeTypeManagement\CND; |
| 4 | + |
| 5 | +// TODO: fix coding style |
| 6 | + |
| 7 | +require_once(__DIR__ . '/../../inc/BaseCase.php'); |
| 8 | + |
| 9 | +use PHPCR\Util\CND\Helper\NodeTypeGenerator, |
| 10 | + PHPCR\Util\CND\Reader\BufferReader, |
| 11 | + PHPCR\Util\CND\Parser\CndParser, |
| 12 | + PHPCR\Util\CND\Scanner\GenericScanner, |
| 13 | + PHPCR\Util\CND\Scanner\Context; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test for PHPCR\Util\QOM\QomToSql2QueryConverter |
| 17 | + */ |
| 18 | +class CndParserTest extends \PHPCR\Test\BaseCase |
| 19 | +{ |
| 20 | + function testGenerator() |
| 21 | + { |
| 22 | + $cnd = <<<EOT |
| 23 | +/* An example node type definition */ |
| 24 | +<ns ='http://namespace.com/ns'> |
| 25 | +[ns:NodeType] > ns:ParentType1, ns:ParentType2 |
| 26 | + orderable mixin |
| 27 | + - ex:property (STRING) |
| 28 | + = 'default1' , 'default2' |
| 29 | + mandatory autocreated protected multiple |
| 30 | + VERSION |
| 31 | + < 'constraint1', 'constraint2' |
| 32 | + + ns:node (ns:reqType1, ns:reqType2) |
| 33 | + = ns:defaultType |
| 34 | + mandatory autocreated protected VERSION |
| 35 | +EOT; |
| 36 | + |
| 37 | + $reader = new BufferReader($cnd); |
| 38 | + $scanner = new GenericScanner(new Context\DefaultScannerContextWithoutSpacesAndComments()); |
| 39 | + $queue = $scanner->scan($reader); |
| 40 | + |
| 41 | + //define('DEBUG', true); |
| 42 | + |
| 43 | + $parser = new CndParser($queue); |
| 44 | + |
| 45 | + $generator = new NodeTypeGenerator( |
| 46 | + $this->sharedFixture['session']->getWorkspace(), |
| 47 | + $parser->parse() |
| 48 | + ); |
| 49 | + |
| 50 | + $res = $generator->generate(); |
| 51 | + $def = reset($res['nodeTypes']); |
| 52 | + |
| 53 | + $this->assertEquals(array('ns' => 'http://namespace.com/ns'), $res['namespaces']); |
| 54 | + |
| 55 | + $this->assertInstanceOf('\PHPCR\NodeType\NodeTypeTemplateInterface', $def); |
| 56 | + $this->assertEquals('ns:NodeType', $def->getName()); |
| 57 | + $this->assertEquals(array('ns:ParentType1', 'ns:ParentType2'), $def->getDeclaredSuperTypeNames()); |
| 58 | + $this->assertTrue($def->hasOrderableChildNodes()); |
| 59 | + $this->assertTrue($def->isMixin()); |
| 60 | + $this->assertFalse($def->isQueryable()); |
| 61 | + $this->assertFalse($def->isAbstract()); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments