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 19
19
*/
20
20
class Element extends \DOMElement implements XPathAware
21
21
{
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
+
22
43
/**
23
44
* Create and append an element with the given name and optionally given value.
24
45
*
46
+ * Note: The value will not be escaped. Use DOMDocument::createTextNode() to create a text node with escaping support.
47
+ *
25
48
* @param string $name
26
49
* @param mixed $value
27
50
*
Original file line number Diff line number Diff line change @@ -35,6 +35,17 @@ public function testAppendElement(): void
35
35
$ this ->assertInstanceOf ('PhpBench\Dom\Element ' , $ element );
36
36
$ this ->assertEquals (1 , $ result );
37
37
}
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
+ }
38
49
39
50
/**
40
51
* It should exeucte an XPath query.
You can’t perform that action at this time.
0 commit comments