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