Skip to content

Commit 2e082a8

Browse files
committed
Merge branch 'master' into importer-bug
2 parents 7400661 + dd64a2d commit 2e082a8

File tree

2 files changed

+104
-3
lines changed

2 files changed

+104
-3
lines changed

tests/PhpcrUtils/CndParserTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function testParseVerbose()
4343
$this->assertExampleCnd($res);
4444
}
4545

46-
4746
public function testParseString()
4847
{
4948
// the "worst case" example from http://jackrabbit.apache.org/node-type-notation.html
@@ -62,12 +61,13 @@ public function testParseString()
6261
mandatory autocreated protected VERSION
6362
EOT;
6463

65-
6664
$res = $this->cndParser->parseString($cnd);
6765
$this->assertExampleCnd($res);
6866
}
6967

7068
/**
69+
* Have invalid-string in the middle of options for a property
70+
*
7171
* @expectedException \PHPCR\Util\CND\Exception\ParserException
7272
*/
7373
public function testParseError()
@@ -99,6 +99,9 @@ public function testErrorNoFile()
9999
}
100100

101101
/**
102+
* Have a comment that is never closed. Starting that at the end of the
103+
* file turned out to be particularly nasty.
104+
*
102105
* @expectedException \PHPCR\Util\CND\Exception\ScannerException
103106
*/
104107
public function testScannerErrorComment()
@@ -111,6 +114,8 @@ public function testScannerErrorComment()
111114
}
112115

113116
/**
117+
* Have a newline in a name (here the ns declaration)
118+
*
114119
* @expectedException \PHPCR\Util\CND\Exception\ScannerException
115120
*/
116121
public function testScannerErrorNewline()
@@ -179,7 +184,7 @@ protected function assertExampleCnd($res)
179184
/** @var $def NodeTypeDefinitionInterface */
180185
list($name, $def) = each($res['nodeTypes']);
181186

182-
$this->assertEquals('ns:NodeType', $name);
187+
$this->assertEquals('ns:NodeType', $name);
183188
$this->assertInstanceOf('\PHPCR\NodeType\NodeTypeTemplateInterface', $def);
184189
$this->assertEquals('ns:NodeType', $def->getName());
185190
$this->assertEquals(array('ns:ParentType1', 'ns:ParentType2'), $def->getDeclaredSuperTypeNames());

tests/PhpcrUtils/CndWriterTest.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace PHPCR\Tests\PhpcrUtils;
4+
5+
require_once(__DIR__ . '/../../inc/BaseCase.php');
6+
7+
use PHPCR\NamespaceRegistryInterface;
8+
use PHPCR\PropertyType;
9+
10+
use PHPCR\Util\CND\Writer\CndWriter;
11+
use PHPCR\Version\OnParentVersionAction;
12+
use PHPCR\WorkspaceInterface;
13+
14+
class CndWriterTest extends \PHPCR\Test\BaseCase
15+
{
16+
/**
17+
* the "worst case" example from http://jackrabbit.apache.org/node-type-notation.html
18+
*/
19+
public function testWorstCaseExample()
20+
{
21+
$cnd = <<<EOT
22+
<ns='http://namespace.com/ns'>
23+
<ex='http://namespace.com/example'>
24+
[ns:NodeType] > ns:ParentType1, ns:ParentType2
25+
orderable mixin query
26+
- ex:property (String)
27+
= 'default1', 'default2'
28+
mandatory autocreated protected multiple VERSION
29+
< 'constraint1', 'constraint2'
30+
+ ns:node (ns:reqType1, ns:reqType2)
31+
= ns:defaultType
32+
mandatory autocreated protected VERSION
33+
34+
EOT;
35+
36+
/** @var $workspace WorkspaceInterface */
37+
$workspace = $this->sharedFixture['session']->getWorkspace();
38+
$ntm = $workspace->getNodeTypeManager();
39+
40+
$tpl = $ntm->createNodeTypeTemplate();
41+
$tpl->setName('ns:NodeType');
42+
$tpl->setMixin(true);
43+
$tpl->setDeclaredSuperTypeNames(array('ns:ParentType1', 'ns:ParentType2'));
44+
$tpl->setOrderableChildNodes(true);
45+
46+
$prop = $ntm->createPropertyDefinitionTemplate();
47+
$prop->setName('ex:property');
48+
$prop->setRequiredType(PropertyType::STRING);
49+
$prop->setDefaultValues(array('default1', 'default2'));
50+
$prop->setMandatory(true);
51+
$prop->setAutoCreated(true);
52+
$prop->setProtected(true);
53+
$prop->setMultiple(true);
54+
$prop->setOnParentVersion(OnParentVersionAction::VERSION);
55+
$prop->setValueConstraints(array('constraint1', 'constraint2'));
56+
$prop->setFullTextSearchable(true);
57+
$prop->setQueryOrderable(true);
58+
59+
$tpl->getPropertyDefinitionTemplates()->append($prop);
60+
61+
$child = $ntm->createNodeDefinitionTemplate();
62+
$child->setName('ns:node');
63+
$child->setRequiredPrimaryTypeNames(array('ns:reqType1', 'ns:reqType2'));
64+
$child->setDefaultPrimaryTypeName('ns:defaultType');
65+
$child->setMandatory(true);
66+
$child->setAutoCreated(true);
67+
$child->setProtected(true);
68+
$child->setOnParentVersion(OnParentVersionAction::VERSION);
69+
70+
$tpl->getNodeDefinitionTemplates()->append($child);
71+
72+
$ns = $this->getMock('PHPCR\Tests\PhpcrUtils\MockNamespaceRegistry');
73+
$ns->expects($this->any())
74+
->method('getUri')
75+
->will($this->returnCallback(
76+
function($prefix) {
77+
switch($prefix) {
78+
case 'ns':
79+
return 'http://namespace.com/ns';
80+
case 'ex':
81+
return 'http://namespace.com/example';
82+
default:
83+
throw new \Exception($prefix);
84+
}
85+
}
86+
))
87+
;
88+
$cndWriter = new CndWriter($ns);
89+
$res = $cndWriter->writeString(array($tpl));
90+
91+
$this->assertEquals($cnd, $res);
92+
}
93+
}
94+
95+
abstract class MockNamespaceRegistry implements \Iterator, NamespaceRegistryInterface
96+
{}

0 commit comments

Comments
 (0)