@@ -146,7 +146,7 @@ public static function getSubstructureProvider(): array
146146 </item>
147147</items>
148148EOF
149- ,
149+ ,
150150 'configuration ' => [
151151 'first ' => [
152152 'field ' => 'foo ' ,
@@ -187,12 +187,64 @@ public function getSubstructureValuesReturnsExpectedRows(string $structure, arra
187187 // Load the XML into a DOM object
188188 $ dom = new \DOMDocument ();
189189 $ dom ->loadXML ($ structure , LIBXML_PARSEHUGE );
190- // Instantiate a XPath object and load with any defined namespaces
191190 $ xPathObject = new \DOMXPath ($ dom );
192191 $ nodeList = $ dom ->getElementsByTagName ('item ' );
193192 self ::assertSame (
194193 $ result ,
195194 $ this ->subject ->getSubstructureValues ($ nodeList , $ configuration , $ xPathObject )
196195 );
197196 }
197+
198+ public static function getNodeListProvider (): array
199+ {
200+ return [
201+ [
202+ 'structure ' => <<<XML
203+ <?xml version="1.0" encoding="UTF-8"?>
204+ <item>
205+ <media>
206+ <images>
207+ <image name="xxl_1234_01.jpg" position="1" updatedDateTime="2025-02-20 15:44:57"/>
208+ <image name="xxl_1234_02.jpg" position="2" updatedDateTime="2025-02-20 15:44:57"/>
209+ <image name="xxl_1234_03.jpg" position="3" updatedDateTime="2025-02-20 15:44:58"/>
210+ </images>
211+ </media>
212+ </item>
213+ XML
214+ ,
215+ 'configuration ' => [
216+ 'xpath ' => 'media/images/image ' ,
217+ ],
218+ 'result ' => <<<XML
219+ <?xml version="1.0"?>
220+ <image name="xxl_1234_01.jpg" position="1" updatedDateTime="2025-02-20 15:44:57"/>
221+ <image name="xxl_1234_02.jpg" position="2" updatedDateTime="2025-02-20 15:44:57"/>
222+ <image name="xxl_1234_03.jpg" position="3" updatedDateTime="2025-02-20 15:44:58"/>
223+
224+ XML
225+ ,
226+ ],
227+ ];
228+ }
229+
230+ #[Test] #[DataProvider('getNodeListProvider ' )]
231+ public function getNodeListReturnsExpectedList (string $ structure , array $ configuration , string $ result ): void
232+ {
233+ // Load the XML into a DOM object
234+ $ dom = new \DOMDocument ();
235+ $ dom ->loadXML ($ structure , LIBXML_PARSEHUGE );
236+ $ records = $ dom ->getElementsByTagName ('item ' );
237+ $ xPathObject = new \DOMXPath ($ dom );
238+ $ nodeList = $ this ->subject ->getNodeList ($ records ->item (0 ), $ configuration , $ xPathObject );
239+ $ resultingDocument = new \DOMDocument ();
240+ // Test the result by writing the selected nodes to a new document
241+ foreach ($ nodeList as $ node ) {
242+ $ node = $ resultingDocument ->importNode ($ node , true );
243+ $ resultingDocument ->appendChild ($ node );
244+ }
245+ self ::assertSame (
246+ $ result ,
247+ $ resultingDocument ->saveXML ()
248+ );
249+ }
198250}
0 commit comments