@@ -21,17 +21,24 @@ public function setUp(): void
2121 $ this ->fieldTypeSerializerMock = $ this ->createMock (FieldTypeSerializer::class);
2222 }
2323
24- /**
25- * @return \DOMDocument
26- */
27- public function testVisitRestFieldDefinition ()
24+ public function testVisitRestFieldDefinition (): \DOMDocument
25+ {
26+ return $ this ->generateDomDocument ();
27+ }
28+
29+ public function testVisitRestFieldDefinitionWithPath (): \DOMDocument
30+ {
31+ return $ this ->generateDomDocument ('/content/types/contentTypeId/fieldDefinition/title ' );
32+ }
33+
34+ protected function generateDomDocument (?string $ path = null ): \DOMDocument
2835 {
2936 $ visitor = $ this ->getVisitor ();
3037 $ generator = $ this ->getGenerator ();
3138
3239 $ generator ->startDocument (null );
3340
34- $ restFieldDefinition = $ this ->getBasicRestFieldDefinition ();
41+ $ restFieldDefinition = $ this ->getBasicRestFieldDefinition ($ path );
3542
3643 $ this ->fieldTypeSerializerMock ->expects ($ this ->once ())
3744 ->method ('serializeFieldDefaultValue ' )
@@ -43,14 +50,16 @@ public function testVisitRestFieldDefinition()
4350 )
4451 );
4552
46- $ this ->addRouteExpectation (
47- 'ezpublish_rest_loadContentTypeFieldDefinition ' ,
48- [
49- 'contentTypeId ' => $ restFieldDefinition ->contentType ->id ,
50- 'fieldDefinitionId ' => $ restFieldDefinition ->fieldDefinition ->id ,
51- ],
52- "/content/types/ {$ restFieldDefinition ->contentType ->id }/fieldDefinitions/ {$ restFieldDefinition ->fieldDefinition ->id }"
53- );
53+ if ($ path === null ) {
54+ $ this ->addRouteExpectation (
55+ 'ezpublish_rest_loadContentTypeFieldDefinition ' ,
56+ [
57+ 'contentTypeId ' => $ restFieldDefinition ->contentType ->id ,
58+ 'fieldDefinitionId ' => $ restFieldDefinition ->fieldDefinition ->id ,
59+ ],
60+ "/content/types/ {$ restFieldDefinition ->contentType ->id }/fieldDefinitions/ {$ restFieldDefinition ->fieldDefinition ->id }"
61+ );
62+ }
5463
5564 $ visitor ->visit (
5665 $ this ->getVisitorMock (),
@@ -68,7 +77,7 @@ public function testVisitRestFieldDefinition()
6877 return $ dom ;
6978 }
7079
71- protected function getBasicRestFieldDefinition ()
80+ protected function getBasicRestFieldDefinition (? string $ path = null ): Server \ Values \ RestFieldDefinition
7281 {
7382 return new Server \Values \RestFieldDefinition (
7483 new Values \ContentType \ContentType (
@@ -95,14 +104,40 @@ protected function getBasicRestFieldDefinition()
95104 'names ' => ['eng-US ' => 'Sindelfingen ' ],
96105 'descriptions ' => ['eng-GB ' => 'Bielefeld ' ],
97106 ]
98- )
107+ ),
108+ $ path
109+ );
110+ }
111+
112+ public function provideXpathAssertions (): array
113+ {
114+ $ xpathAssertions = $ this ->getXpathAssertions ();
115+ $ xpathAssertions [] = '/FieldDefinition[@href="/content/types/contentTypeId/fieldDefinitions/fieldDefinitionId_23"] ' ;
116+
117+ return $ this ->prepareXPathAssertions ($ xpathAssertions );
118+ }
119+
120+ public function provideXpathAssertionsPath (): array
121+ {
122+ $ xpathAssertions = $ this ->getXpathAssertions ();
123+ $ xpathAssertions [] = '/FieldDefinition[@href="/content/types/contentTypeId/fieldDefinition/title"] ' ;
124+
125+ return $ this ->prepareXPathAssertions ($ xpathAssertions );
126+ }
127+
128+ protected function prepareXPathAssertions (array $ xpathAssertions ): array
129+ {
130+ return array_map (
131+ static function (string $ xpath ): array {
132+ return [$ xpath ];
133+ },
134+ $ xpathAssertions
99135 );
100136 }
101137
102- public function provideXpathAssertions ()
138+ protected function getXpathAssertions (): array
103139 {
104- $ xpathAssertions = [
105- '/FieldDefinition[@href="/content/types/contentTypeId/fieldDefinitions/fieldDefinitionId_23"] ' ,
140+ return [
106141 '/FieldDefinition[@media-type="application/vnd.ez.api.FieldDefinition+xml"] ' ,
107142 '/FieldDefinition/id[text()="fieldDefinitionId_23"] ' ,
108143 '/FieldDefinition/identifier[text()="title"] ' ,
@@ -117,33 +152,30 @@ public function provideXpathAssertions()
117152 '/FieldDefinition/names/value[@languageCode="eng-US" and text()="Sindelfingen"] ' ,
118153 '/FieldDefinition/descriptions/value[@languageCode="eng-GB" and text()="Bielefeld"] ' ,
119154 ];
120-
121- return array_map (
122- function ($ xpath ) {
123- return [$ xpath ];
124- },
125- $ xpathAssertions
126- );
127155 }
128156
129157 /**
130- * @param string $xpath
131- * @param \DOMDocument $dom
132- *
133158 * @depends testVisitRestFieldDefinition
134159 * @dataProvider provideXpathAssertions
135160 */
136- public function testGeneratedXml ($ xpath , \DOMDocument $ dom )
161+ public function testGeneratedXml (string $ xpath , \DOMDocument $ dom ): void
162+ {
163+ $ this ->assertXPath ($ dom , $ xpath );
164+ }
165+
166+ /**
167+ * @depends testVisitRestFieldDefinitionWithPath
168+ * @dataProvider provideXpathAssertionsPath
169+ */
170+ public function testGeneratedXmlPath (string $ xpath , \DOMDocument $ dom ): void
137171 {
138172 $ this ->assertXPath ($ dom , $ xpath );
139173 }
140174
141175 /**
142176 * Get the Content visitor.
143- *
144- * @return \EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\RestFieldDefinition
145177 */
146- protected function internalGetVisitor ()
178+ protected function internalGetVisitor (): ValueObjectVisitor \ RestFieldDefinition
147179 {
148180 return new ValueObjectVisitor \RestFieldDefinition ($ this ->fieldTypeSerializerMock );
149181 }
0 commit comments