File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
tests/Rct567/DomQuery/Tests Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -645,7 +645,17 @@ public function filter($selector)
645645 */
646646 public function clone ()
647647 {
648- return $ this ->createChildInstance ($ this ->getClonedNodes ());
648+ $ new_instance = self ::create ($ this ->getClonedNodes ());
649+
650+ if (\is_bool ($ this ->xml_mode )) {
651+ $ new_instance ->xml_mode = $ this ->xml_mode ;
652+ }
653+
654+ if (isset ($ this ->document ) && $ this ->dom_xpath instanceof \DOMXPath) {
655+ $ new_instance ->dom_xpath = $ this ->dom_xpath ;
656+ }
657+
658+ return $ new_instance ;
649659 }
650660
651661 /**
Original file line number Diff line number Diff line change @@ -123,4 +123,22 @@ public function testEachIteration()
123123 $ this ->assertCount (2 , $ result );
124124 $ this ->assertInstanceOf (\DOMNode::class, $ result [0 ]);
125125 }
126+
127+ /*
128+ * Test clone
129+ */
130+ public function testClone ()
131+ {
132+ $ dom = new DomQuery ('<div><p>My words</p></div> ' );
133+ $ elm = $ dom ->find ('p ' );
134+ $ cloned_elm = $ elm ->clone ();
135+ $ this ->assertEquals ('<p>My words</p> ' , (string ) $ elm );
136+ $ this ->assertEquals ('<p>My words</p> ' , (string ) $ cloned_elm );
137+ $ this ->assertFalse ( $ elm ->get (0 )->isSameNode ( $ cloned_elm ->get (0 )) );
138+
139+ $ dom_clone = $ dom ->clone ();
140+ $ this ->assertEquals ('<div><p>My words</p></div> ' , $ dom_clone );
141+ $ this ->assertEquals ('<p>My words</p> ' , $ dom_clone ->find ('p ' )->first ());
142+ $ this ->assertTrue ($ dom_clone ->find ('p ' )->first ()->is ('p ' ));
143+ }
126144}
You can’t perform that action at this time.
0 commit comments