Skip to content

Commit

Permalink
Declare tidyNode properties as readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed May 8, 2022
1 parent 448e4bb commit 3d94aa1
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 122 deletions.
4 changes: 3 additions & 1 deletion ext/tidy/tests/010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var_dump($a->head());

?>
--EXPECTF--
object(tidyNode)#2 (8) {
object(tidyNode)#2 (9) {
["value"]=>
string(94) "<html>
<head>
Expand All @@ -31,6 +31,8 @@ object(tidyNode)#2 (8) {
int(1)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand Down
40 changes: 30 additions & 10 deletions ext/tidy/tests/012.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object(tidyNode)#5 (9) {
["child"]=>
array(1) {
[0]=>
object(tidyNode)#7 (8) {
object(tidyNode)#7 (9) {
["value"]=>
string(2) "Hi"
["name"]=>
Expand All @@ -161,6 +161,8 @@ object(tidyNode)#5 (9) {
int(46)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand Down Expand Up @@ -189,7 +191,7 @@ object(tidyNode)#5 (9) {
["child"]=>
array(2) {
[0]=>
object(tidyNode)#9 (8) {
object(tidyNode)#9 (9) {
["value"]=>
string(3) "Bye"
["name"]=>
Expand All @@ -202,6 +204,8 @@ object(tidyNode)#5 (9) {
int(55)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand All @@ -228,7 +232,7 @@ object(tidyNode)#5 (9) {
["child"]=>
array(1) {
[0]=>
object(tidyNode)#11 (8) {
object(tidyNode)#11 (9) {
["value"]=>
string(4) "Test"
["name"]=>
Expand All @@ -241,6 +245,8 @@ object(tidyNode)#5 (9) {
int(61)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand Down Expand Up @@ -273,7 +279,7 @@ object(tidyNode)#6 (9) {
["child"]=>
array(1) {
[0]=>
object(tidyNode)#7 (8) {
object(tidyNode)#7 (9) {
["value"]=>
string(2) "Hi"
["name"]=>
Expand All @@ -286,6 +292,8 @@ object(tidyNode)#6 (9) {
int(46)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand All @@ -294,7 +302,7 @@ object(tidyNode)#6 (9) {
}
}
bool(true)
object(tidyNode)#7 (8) {
object(tidyNode)#7 (9) {
["value"]=>
string(2) "Hi"
["name"]=>
Expand All @@ -307,6 +315,8 @@ object(tidyNode)#7 (8) {
int(46)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand All @@ -332,7 +342,7 @@ object(tidyNode)#8 (9) {
["child"]=>
array(2) {
[0]=>
object(tidyNode)#9 (8) {
object(tidyNode)#9 (9) {
["value"]=>
string(3) "Bye"
["name"]=>
Expand All @@ -345,6 +355,8 @@ object(tidyNode)#8 (9) {
int(55)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand All @@ -371,7 +383,7 @@ object(tidyNode)#8 (9) {
["child"]=>
array(1) {
[0]=>
object(tidyNode)#11 (8) {
object(tidyNode)#11 (9) {
["value"]=>
string(4) "Test"
["name"]=>
Expand All @@ -384,6 +396,8 @@ object(tidyNode)#8 (9) {
int(61)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand All @@ -394,7 +408,7 @@ object(tidyNode)#8 (9) {
}
}
bool(true)
object(tidyNode)#9 (8) {
object(tidyNode)#9 (9) {
["value"]=>
string(3) "Bye"
["name"]=>
Expand All @@ -407,6 +421,8 @@ object(tidyNode)#9 (8) {
int(55)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand All @@ -432,7 +448,7 @@ object(tidyNode)#10 (9) {
["child"]=>
array(1) {
[0]=>
object(tidyNode)#11 (8) {
object(tidyNode)#11 (9) {
["value"]=>
string(4) "Test"
["name"]=>
Expand All @@ -445,6 +461,8 @@ object(tidyNode)#10 (9) {
int(61)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand All @@ -453,7 +471,7 @@ object(tidyNode)#10 (9) {
}
}
bool(true)
object(tidyNode)#11 (8) {
object(tidyNode)#11 (9) {
["value"]=>
string(4) "Test"
["name"]=>
Expand All @@ -466,6 +484,8 @@ object(tidyNode)#11 (8) {
int(61)
["proprietary"]=>
bool(false)
["id"]=>
NULL
["attribute"]=>
NULL
["child"]=>
Expand Down
75 changes: 75 additions & 0 deletions ext/tidy/tests/036.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
--TEST--
Test readonly tidyNode properties
--EXTENSIONS--
tidy
--FILE--
<?php

$tidy = tidy_parse_string("<HTML><BODY BGCOLOR=#FFFFFF ALINK=#000000></BODY></HTML>");
$node = $tidy->body();

try {
$node->value = "";
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->name = "";
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->type = 1;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->line = 1;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->column = 1;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->proprietary = true;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->id = null;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->attribute = [];
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$node->child = [];
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECT--
Cannot modify readonly property tidyNode::$value
Cannot modify readonly property tidyNode::$name
Cannot modify readonly property tidyNode::$type
Cannot modify readonly property tidyNode::$line
Cannot modify readonly property tidyNode::$column
Cannot modify readonly property tidyNode::$proprietary
Cannot modify readonly property tidyNode::$id
Cannot modify readonly property tidyNode::$attribute
Cannot modify readonly property tidyNode::$child
Loading

0 comments on commit 3d94aa1

Please sign in to comment.