Skip to content

Commit b9039c8

Browse files
committed
Fixed incorrect docblocks on usage of interface token::parse().
Fixed bug in text class where there was no set() method to enable the parent object to be set which is required if you add HTML that has textnodes at the root level. Updated tests.
1 parent 3ce6617 commit b9039c8

File tree

7 files changed

+46
-39
lines changed

7 files changed

+46
-39
lines changed

src/tokens/comment.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ public function __construct(htmldoc $root) {
2020
}
2121

2222
/**
23-
* Parses an array of tokens into an HTML documents
23+
* Parses the next HTML component from a tokenise object
2424
*
25-
* @param array &$tokens An array of tokens generated by tokenise()
26-
* @param array $config An array of configuration options
25+
* @param tokenise $tokens A tokenise object
2726
* @return void
2827
*/
2928
public function parse(tokenise $tokens) : void {

src/tokens/custom.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ public function __construct(htmldoc $root, string $tagName = null) {
3232
}
3333

3434
/**
35-
* Parses an array of tokens into an HTML documents
35+
* Parses the next HTML component from a tokenise object
3636
*
37-
* @param array &$tokens An array of tokens generated by tokenise()
38-
* @param array $config An array of configuration options
37+
* @param tokenise $tokens A tokenise object
3938
* @return void
4039
*/
4140
public function parse(tokenise $tokens) : void {

src/tokens/doctype.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ public function __construct(htmldoc $root) {
2020
}
2121

2222
/**
23-
* Parses an array of tokens into an HTML documents
23+
* Parses the next HTML component from a tokenise object
2424
*
25-
* @param array &$tokens An array of tokens generated by tokenise()
26-
* @param array $config An array of configuration options
25+
* @param tokenise $tokens A tokenise object
2726
* @return void
2827
*/
2928
public function parse(tokenise $tokens) : void {

src/tokens/interfaces/token.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ interface token {
1616
public function __construct(htmldoc $root);
1717

1818
/**
19-
* Parses an array of tokens into an HTML documents
19+
* Parses the next HTML component from a tokenise object
2020
*
21-
* @param array &$tokens An array of tokens generated by tokenise()
22-
* @param array $config An array of configuration options
21+
* @param tokenise $tokens A tokenise object
2322
* @return void
2423
*/
2524
public function parse(tokenise $tokens) : void;

src/tokens/tag.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ public function __clone() {
102102
}
103103

104104
/**
105-
* Parses an array of tokens into an HTML documents
105+
* Parses the next HTML component from a tokenise object
106106
*
107-
* @param tokenise &$tokens An array of tokens generated by tokenise()
108-
* @param array $config An array of configuration options
107+
* @param tokenise $tokens A tokenise object
109108
* @return void
110109
*/
111110
public function parse(tokenise $tokens) : void {

src/tokens/text.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,22 @@ public function __construct(htmldoc $root, ?tag $parent = null) {
3232
}
3333

3434
/**
35-
* Parses an array of tokens into an HTML documents
35+
* Magic method to set protected variables
3636
*
37-
* @param array &$tokens An array of tokens generated by tokenise()
38-
* @param array $config An array of configuration options
37+
* @param string $name The name of the property to set
38+
* @param mixed $value The value of the property to set
39+
* @return void
40+
*/
41+
public function __set(string $name, $value) : void {
42+
if ($name === 'parent' && \get_class($value) === 'hexydec\\html\\tag') {
43+
$this->parent = $value;
44+
}
45+
}
46+
47+
/**
48+
* Parses the next HTML component from a tokenise object
49+
*
50+
* @param tokenise $tokens A tokenise object
3951
* @return void
4052
*/
4153
public function parse(tokenise $tokens) : void {

tests/editHtmldocTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ final class editHtmldocTest extends \PHPUnit\Framework\TestCase {
55

66
public function testCanAppendHtml() {
77
$obj = new htmldoc();
8-
$obj->load('<h1>Appended</h1>');
8+
$obj->load('Data to <span>append</span> here');
99
$tests = [
1010
[
1111
'input' => '<!DOCTYPE html><html><body></body></html>',
1212
'find' => 'body',
13-
'append' => '<h1>Appended</h1>',
14-
'output' => '<!DOCTYPE html><html><body><h1>Appended</h1></body></html>',
13+
'append' => 'Data to <span>append</span> here',
14+
'output' => '<!DOCTYPE html><html><body>Data to <span>append</span> here</body></html>',
15+
],
16+
[
17+
'input' => '<!DOCTYPE html><html><body></body></html>',
18+
'find' => 'body',
19+
'append' => $obj,
20+
'output' => '<!DOCTYPE html><html><body>Data to <span>append</span> here</body></html>',
1521
],
1622
[
1723
'input' => '<ul><li></li><li></li><li></li><li></li></ul>',
@@ -31,12 +37,6 @@ public function testCanAppendHtml() {
3137
'append' => '<h3>Appended</h3><p>Test <span>this</span></p>',
3238
'output' => '<div><div><h3>Appended</h3><p>Test <span>this</span></p></div><h3>Appended</h3><p>Test <span>this</span></p></div>',
3339
],
34-
[
35-
'input' => '<!DOCTYPE html><html><body></body></html>',
36-
'find' => 'body',
37-
'append' => $obj,
38-
'output' => '<!DOCTYPE html><html><body><h1>Appended</h1></body></html>',
39-
],
4040
];
4141

4242
$doc = new htmldoc();
@@ -49,19 +49,19 @@ public function testCanAppendHtml() {
4949

5050
public function testCanPrependHtml() {
5151
$obj = new htmldoc();
52-
$obj->load('<h1>Prepended</h1>');
52+
$obj->load('Data to <span>prepend</span> here');
5353
$tests = [
5454
[
5555
'input' => '<!DOCTYPE html><html><body></body></html>',
5656
'find' => 'body',
57-
'prepend' => '<h1>Prepended</h1>',
58-
'output' => '<!DOCTYPE html><html><body><h1>Prepended</h1></body></html>',
57+
'prepend' => 'Data to <span>prepend</span> here',
58+
'output' => '<!DOCTYPE html><html><body>Data to <span>prepend</span> here</body></html>',
5959
],
6060
[
6161
'input' => '<!DOCTYPE html><html><body></body></html>',
6262
'find' => 'body',
6363
'prepend' => $obj,
64-
'output' => '<!DOCTYPE html><html><body><h1>Prepended</h1></body></html>',
64+
'output' => '<!DOCTYPE html><html><body>Data to <span>prepend</span> here</body></html>',
6565
],
6666
[
6767
'input' => '<ul><li></li><li></li><li></li><li></li></ul>',
@@ -92,19 +92,19 @@ public function testCanPrependHtml() {
9292

9393
public function testCanInserHtmlBefore() {
9494
$obj = new htmldoc();
95-
$obj->load('<h1>Insert Before</h1>');
95+
$obj->load('Data to <span>insert</span> before');
9696
$tests = [
9797
[
9898
'input' => '<!DOCTYPE html><html><body><p>Test</p></body></html>',
9999
'find' => 'p',
100-
'before' => '<h1>Insert Before</h1>',
101-
'output' => '<!DOCTYPE html><html><body><h1>Insert Before</h1><p>Test</p></body></html>',
100+
'before' => 'Data to <span>insert</span> before',
101+
'output' => '<!DOCTYPE html><html><body>Data to <span>insert</span> before<p>Test</p></body></html>',
102102
],
103103
[
104104
'input' => '<!DOCTYPE html><html><body><p>Test</p></body></html>',
105105
'find' => 'p',
106106
'before' => $obj,
107-
'output' => '<!DOCTYPE html><html><body><h1>Insert Before</h1><p>Test</p></body></html>',
107+
'output' => '<!DOCTYPE html><html><body>Data to <span>insert</span> before<p>Test</p></body></html>',
108108
],
109109
[
110110
'input' => '<div><p>Test</p><p>Test</p><p>Test</p></div>',
@@ -135,19 +135,19 @@ public function testCanInserHtmlBefore() {
135135

136136
public function testCanInserHtmlAfter() {
137137
$obj = new htmldoc();
138-
$obj->load('<h1>Insert After</h1>');
138+
$obj->load('Data to <span>insert</span> after');
139139
$tests = [
140140
[
141141
'input' => '<!DOCTYPE html><html><body><p>Test</p></body></html>',
142142
'find' => 'p',
143-
'after' => '<h1>Insert After</h1>',
144-
'output' => '<!DOCTYPE html><html><body><p>Test</p><h1>Insert After</h1></body></html>',
143+
'after' => 'Data to <span>insert</span> after',
144+
'output' => '<!DOCTYPE html><html><body><p>Test</p>Data to <span>insert</span> after</body></html>',
145145
],
146146
[
147147
'input' => '<!DOCTYPE html><html><body><p>Test</p></body></html>',
148148
'find' => 'p',
149149
'after' => $obj,
150-
'output' => '<!DOCTYPE html><html><body><p>Test</p><h1>Insert After</h1></body></html>',
150+
'output' => '<!DOCTYPE html><html><body><p>Test</p>Data to <span>insert</span> after</body></html>',
151151
],
152152
[
153153
'input' => '<div><p>Test</p><p>Test</p><p>Test</p></div>',

0 commit comments

Comments
 (0)