This repository was archived by the owner on Oct 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1919 */
2020class Element extends \DOMElement implements XPathAware
2121{
22+ /**
23+ * Create and append a text-node with the given name and value.
24+ *
25+ * @param string $name
26+ * @param string $value
27+ *
28+ * @return Element
29+ */
30+ public function appendTextNode ($ name , $ value )
31+ {
32+ $ el = new self ($ name );
33+ $ element = $ this ->appendChild ($ el );
34+ assert ($ element instanceof Element);
35+
36+ $ element ->appendChild (
37+ $ this ->owner ()->createTextNode ($ value )
38+ );
39+
40+ return $ element ;
41+ }
42+
2243 /**
2344 * Create and append an element with the given name and optionally given value.
2445 *
46+ * Note: The value will not be escaped. Use DOMDocument::createTextNode() to create a text node with escaping support.
47+ *
2548 * @param string $name
2649 * @param mixed $value
2750 *
Original file line number Diff line number Diff line change @@ -35,6 +35,17 @@ public function testAppendElement(): void
3535 $ this ->assertInstanceOf ('PhpBench\Dom\Element ' , $ element );
3636 $ this ->assertEquals (1 , $ result );
3737 }
38+
39+ /**
40+ * It should create and append text.
41+ */
42+ public function testAppendTextNode (): void
43+ {
44+ $ element = $ this ->element ->appendTextNode ('hello ' , 'fix&foxy ' );
45+ $ result = $ this ->document ->evaluate ('count(//hello) ' );
46+ $ this ->assertInstanceOf ('PhpBench\Dom\Element ' , $ element );
47+ $ this ->assertEquals (1 , $ result );
48+ }
3849
3950 /**
4051 * It should exeucte an XPath query.
You can’t perform that action at this time.
0 commit comments