@@ -869,24 +869,95 @@ public function test_adjusts_for_mathml_integration_points() {
869
869
*
870
870
* @dataProvider data_set_inner_html
871
871
*/
872
- public function test_set_inner_html ( string $ html , string $ replacement , string $ expected ) {
872
+ public function test_set_inner_html ( string $ html , ? string $ replacement , string $ expected ) {
873
873
$ processor = WP_HTML_Processor::create_fragment ( $ html );
874
874
while ( $ processor ->next_tag () ) {
875
875
if ( $ processor ->get_attribute ( 'target ' ) ) {
876
876
break ;
877
877
}
878
878
}
879
- $ processor ->set_inner_html ( $ replacement );
879
+
880
+ $ this ->assertTrue ( $ processor ->set_inner_html ( $ replacement ) );
880
881
$ this ->assertSame ( $ expected , $ processor ->get_updated_html () );
881
882
}
882
883
883
884
public static function data_set_inner_html () {
884
885
return array (
885
- ' image in mathml ' => array (
886
+ array (
886
887
'<div target>replace me</div> ' ,
887
888
'with me! ' ,
888
889
'<div target>with me!</div> ' ,
889
890
),
891
+ array (
892
+ '<div target><div><p><a>replace me</div></div> ' ,
893
+ 'with me! ' ,
894
+ '<div target>with me!</div> ' ,
895
+ ),
896
+ array (
897
+ '<table target><td>replace me</table> ' ,
898
+ '<td>with me! ' ,
899
+ '<table target><td>with me!</td></table> ' ,
900
+ ),
901
+ );
902
+ }
903
+
904
+ /**
905
+ * @ticket TBD
906
+ *
907
+ * @dataProvider data_set_inner_html_not_allowed
908
+ */
909
+ public function test_set_inner_html_not_allowed ( string $ html , string $ replacement ) {
910
+ $ processor = WP_HTML_Processor::create_fragment ( $ html );
911
+ while ( $ processor ->next_tag () ) {
912
+ if ( $ processor ->get_attribute ( 'target ' ) ) {
913
+ break ;
914
+ }
915
+ }
916
+ $ this ->assertFalse ( $ processor ->set_inner_html ( $ replacement ) );
917
+ $ this ->assertSame ( $ html , $ processor ->get_updated_html () );
918
+ }
919
+
920
+ /**
921
+ * Data provider.
922
+ *
923
+ * @return array[]
924
+ */
925
+ public static function data_set_inner_html_not_allowed (): array {
926
+ return array (
927
+ 'not allowed in void tags ' => array (
928
+ '<br target> ' ,
929
+ 'anything ' ,
930
+ ),
931
+ 'not allowed in self-closing tags ' => array (
932
+ '<svg><text target /> ' ,
933
+ 'anything ' ,
934
+ ),
935
+ 'must have closing tag ' => array (
936
+ '<body><div target></body> ' ,
937
+ 'anything ' ,
938
+ ),
939
+
940
+ 'a in a ' => array (
941
+ '<a target></a> ' ,
942
+ '<a> ' ,
943
+ ),
944
+ 'a nested in a ' => array (
945
+ '<a><i><em><strong target></a> ' ,
946
+ '<a>A cannot nest inside a ' ,
947
+ ),
948
+
949
+ 'text in table ' => array (
950
+ '<table target><td>hello</table> ' ,
951
+ 'text triggers forstering - not allowed ' ,
952
+ ),
953
+ 'text in thead ' => array (
954
+ '<table><thead target><td>hello</thead> ' ,
955
+ 'text triggers forstering - not allowed ' ,
956
+ ),
957
+ 'text in tr ' => array (
958
+ '<table><tr target>hello</tr> ' ,
959
+ 'text triggers forstering - not allowed ' ,
960
+ ),
890
961
);
891
962
}
892
963
}
0 commit comments