-
Notifications
You must be signed in to change notification settings - Fork 21
[WIP] Cnd parser test #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a36ac14
Added a test for the CND parser
c992ab0
Completed the test for the CND parser
666696d
Merge branch 'master' into cnd-parser
dbu a431df5
updating the cnd tests, run with the jackrabbit default node types (h…
dbu ba30e9f
Merge branch 'master' into cnd-parser
dbu 79084c3
more comprehensive tests of cnd parser
dbu 23a1981
make no assumptions on implementation specific defaults
dbu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| <?php | ||
|
|
||
| namespace PHPCR\Tests\PhpcrUtils; | ||
|
|
||
| require_once(__DIR__ . '/../../inc/BaseCase.php'); | ||
|
|
||
| use PHPCR\NodeType\NodeTypeDefinitionInterface; | ||
| use PHPCR\NodeType\NodeTypeManagerInterface; | ||
| use PHPCR\PropertyType; | ||
| use PHPCR\NodeType\PropertyDefinitionTemplateInterface; | ||
| use PHPCR\Version\OnParentVersionAction; | ||
|
|
||
| use PHPCR\Util\CND\Parser\CndParser; | ||
|
|
||
|
|
||
| class CndParserTest extends \PHPCR\Test\BaseCase | ||
| { | ||
| /** @var CndParser */ | ||
| private $cndParser; | ||
|
|
||
| public function setUp() | ||
| { | ||
| parent::setUp(); | ||
| $this->cndParser = new CndParser($this->sharedFixture['session']->getWorkspace()->getNodeTypeManager()); | ||
| } | ||
|
|
||
| public function testParseNormal() | ||
| { | ||
| $res = $this->cndParser->parseFile(__DIR__ . '/resources/cnd/example.cnd'); | ||
| $this->assertExampleCnd($res); | ||
| } | ||
|
|
||
| public function testParseCompact() | ||
| { | ||
| $res = $this->cndParser->parseFile(__DIR__ . '/resources/cnd/example.compact.cnd'); | ||
| $this->assertExampleCnd($res); | ||
|
|
||
| } | ||
|
|
||
| public function testParseVerbose() | ||
| { | ||
| $res = $this->cndParser->parseFile(__DIR__ . '/resources/cnd/example.verbose.cnd'); | ||
| $this->assertExampleCnd($res); | ||
| } | ||
|
|
||
|
|
||
| public function testParseString() | ||
| { | ||
| // the "worst case" example from http://jackrabbit.apache.org/node-type-notation.html | ||
| $cnd = <<<EOT | ||
| /** An example node type definition */ | ||
| <ns ='http://namespace.com/ns'> | ||
| [ns:NodeType] > ns:ParentType1, ns:ParentType2 | ||
| orderable mixin | ||
| - ex:property (STRING) | ||
| = 'default1' , 'default2' | ||
| mandatory autocreated protected multiple | ||
| VERSION | ||
| < 'constraint1', 'constraint2' | ||
| + ns:node (ns:reqType1, ns:reqType2) | ||
| = ns:defaultType | ||
| mandatory autocreated protected VERSION | ||
| EOT; | ||
|
|
||
|
|
||
| $res = $this->cndParser->parseString($cnd); | ||
| $this->assertExampleCnd($res); | ||
| } | ||
|
|
||
| /** | ||
| * @expectedException \PHPCR\Util\CND\Exception\ParserException | ||
| */ | ||
| public function testParseError() | ||
| { | ||
| $cnd = <<<EOT | ||
| /** An example node type definition */ | ||
| <ns ='http://namespace.com/ns'> | ||
| [ns:NodeType] > ns:ParentType1, ns:ParentType2 | ||
| orderable mixin | ||
| - ex:property (STRING) | ||
| = 'default1' , 'default2' | ||
| mandatory invalid-string protected multiple | ||
| VERSION | ||
| < 'constraint1', 'constraint2' | ||
| + ns:node (ns:reqType1, ns:reqType2) | ||
| = ns:defaultType | ||
| mandatory autocreated protected VERSION | ||
| EOT; | ||
|
|
||
| $this->cndParser->parseString($cnd); | ||
| } | ||
|
|
||
| /** | ||
| * @expectedException \InvalidArgumentException | ||
| */ | ||
| public function testErrorNoFile() | ||
| { | ||
| $this->cndParser->parseFile('/not/found'); | ||
| } | ||
|
|
||
| /** | ||
| * @expectedException \PHPCR\Util\CND\Exception\ScannerException | ||
| */ | ||
| public function testScannerErrorComment() | ||
| { | ||
| $cnd = <<<EOT | ||
| la /* | ||
| EOT; | ||
|
|
||
| $this->cndParser->parseString($cnd); | ||
| } | ||
|
|
||
| /** | ||
| * @expectedException \PHPCR\Util\CND\Exception\ScannerException | ||
| */ | ||
| public function testScannerErrorNewline() | ||
| { | ||
| $cnd = <<<EOT | ||
| /** An example node type definition */ | ||
| <ns ='http://namespace.com/ns | ||
| '> | ||
| [ns:NodeType] > ns:ParentType1, ns:ParentType2 | ||
| orderable mixin | ||
| - ex:property (STRING) | ||
| EOT; | ||
|
|
||
| $this->cndParser->parseString($cnd); | ||
| } | ||
|
|
||
| /** | ||
| * Test the case where the parser did not parse correctly | ||
| * the default values at the end of the parsed file. | ||
| * | ||
| * Assert no exception is thrown | ||
| */ | ||
| public function testNoStopAtEofError() | ||
| { | ||
| $res = $this->cndParser->parseFile(__DIR__ . '/resources/cnd/no-stop-at-eof.cnd'); | ||
|
|
||
| $this->assertTrue(isset($res['namespaces'])); | ||
| $this->assertEquals(array('phpcr' => 'http://www.doctrine-project.org/projects/phpcr_odm'), $res['namespaces']); | ||
|
|
||
| $this->assertTrue(isset($res['nodeTypes'])); | ||
| } | ||
|
|
||
| public function testBigFile() | ||
| { | ||
| //var_dump($this->sharedFixture['session']->getWorkspace()->getNodeTypeManager()->getNodeType('nt:file')->hasOrderableChildNodes());die; | ||
| $res = $this->cndParser->parseFile(__DIR__ . '/resources/cnd/jackrabbit_nodetypes.cnd'); | ||
|
|
||
| // some random sanity checks | ||
| $this->assertTrue(isset($res['nodeTypes'])); | ||
|
|
||
| $def = $res['nodeTypes']; | ||
| $this->assertTrue(isset($def['nt:file'])); | ||
| /** @var $parsed NodeTypeDefinitionInterface */ | ||
| $parsed = $def['nt:file']; | ||
| $this->assertEquals('nt:file', $parsed->getName()); | ||
| $this->assertFalse($parsed->isAbstract()); | ||
| $this->assertFalse($parsed->hasOrderableChildNodes()); | ||
| $this->assertFalse($parsed->isMixin()); | ||
| // queryable default is implementation specific | ||
| } | ||
|
|
||
| /** | ||
| * Check if $res matches the expected node type definition from the | ||
| * "worst case" example. | ||
| * | ||
| * @param array $res namespaces and node types | ||
| */ | ||
| protected function assertExampleCnd($res) | ||
| { | ||
| $this->assertTrue(isset($res['namespaces'])); | ||
| $this->assertEquals(array('ns' => 'http://namespace.com/ns'), $res['namespaces']); | ||
|
|
||
| $this->assertTrue(isset($res['nodeTypes'])); | ||
| // get first node type | ||
| reset($res['nodeTypes']); | ||
| /** @var $def NodeTypeDefinitionInterface */ | ||
| list($name, $def) = each($res['nodeTypes']); | ||
|
|
||
| $this->assertEquals('ns:NodeType', $name); | ||
| $this->assertInstanceOf('\PHPCR\NodeType\NodeTypeTemplateInterface', $def); | ||
| $this->assertEquals('ns:NodeType', $def->getName()); | ||
| $this->assertEquals(array('ns:ParentType1', 'ns:ParentType2'), $def->getDeclaredSuperTypeNames()); | ||
| $this->assertTrue($def->hasOrderableChildNodes()); | ||
| $this->assertTrue($def->isMixin()); | ||
| // queryable default is implementation specific | ||
| $this->assertFalse($def->isAbstract()); | ||
| $this->assertEquals(1, count($def->getPropertyDefinitionTemplates())); | ||
|
|
||
| /** @var $prop PropertyDefinitionTemplateInterface */ | ||
| $prop = $def->getPropertyDefinitionTemplates()->getIterator()->current(); | ||
|
|
||
| $this->assertEquals('ex:property', $prop->getName()); | ||
| $this->assertEquals(PropertyType::STRING, $prop->getRequiredType()); | ||
| $this->assertEquals(array('default1', 'default2'), $prop->getDefaultValues()); | ||
| $this->assertEquals(array('constraint1', 'constraint2'), $prop->getValueConstraints()); | ||
| $this->assertTrue($prop->isAutoCreated()); | ||
| $this->assertTrue($prop->isMandatory()); | ||
| $this->assertTrue($prop->isProtected()); | ||
| $this->assertTrue($prop->isMultiple()); | ||
| $this->assertEquals(OnParentVersionAction::VERSION, $prop->getOnParentVersion()); | ||
| $this->assertEquals(array(), $prop->getAvailableQueryOperators()); | ||
| $this->assertTrue($prop->isFullTextSearchable()); // True because there was no "nofulltext" attribute | ||
| $this->assertTrue($prop->isQueryOrderable()); // True because there was no "noqueryorder" attribute | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /* An example node type definition */ | ||
| <ns ='http://namespace.com/ns'> | ||
| [ns:NodeType] > ns:ParentType1, ns:ParentType2 | ||
| orderable mixin | ||
| - ex:property (STRING) | ||
| = 'default1' , 'default2' | ||
| mandatory autocreated protected multiple | ||
| VERSION | ||
| < 'constraint1', 'constraint2' | ||
| + ns:node (ns:reqType1, ns:reqType2) | ||
| = ns:defaultType | ||
| mandatory autocreated protected VERSION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <ns= 'http://namespace.com/ns'> | ||
| [ns:NodeType]>ns:ParentType1, ns:ParentType2 o m | ||
| -ex:property(STRING)='default1','default2' m a p * VERSION | ||
| <'constraint1', 'constraint2' | ||
| +ns:node(ns:reqType1,ns:reqType2)=ns:defaultType | ||
| m a p VERSION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* An example node type definition */ | ||
|
|
||
| // The namespace declaration | ||
| <ns = 'http://namespace.com/ns'> | ||
|
|
||
| // Node type name | ||
| [ns:NodeType] | ||
|
|
||
| // Supertypes | ||
| > ns:ParentType1, ns:ParentType2 | ||
|
|
||
| // This node type supports orderable child nodes | ||
| orderable | ||
|
|
||
| // This is a mixin node type | ||
| mixin | ||
|
|
||
| // Nodes of this node type have a property called 'ex:property' of type STRING | ||
| - ex:property (STRING) | ||
|
|
||
| // The default values for this | ||
| // (multi-value) property are... | ||
| = 'default1', 'default2' | ||
|
|
||
| // and it is... | ||
| mandatory autocreated protected | ||
|
|
||
| // and multi-valued | ||
| multiple | ||
|
|
||
| // and has an on-parent-version setting of ... | ||
| VERSION | ||
|
|
||
| // The constraint settings are... | ||
| < 'constraint1', 'constraint2' | ||
|
|
||
| // Nodes of this node type have a child node called ns:node which must be of | ||
| // at least the node types ns:reqType1 and ns:reqType2 | ||
| + ns:node (ns:reqType1, ns:reqType2) | ||
|
|
||
| // and the default primary node type of the child node is... | ||
| = ns:defaultType | ||
|
|
||
| // This child node is... | ||
| mandatory autocreated protected | ||
|
|
||
| // and has an on-parent-version setting of ... | ||
| VERSION |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sixty-nine do you remember what exactly you wanted to test here?