Skip to content

Commit 245f24a

Browse files
committed
Add failing tests for duplicate attribute removal bug
When using false/null to remove an attribute placeholder, duplicate attributes remain. These tests demonstrate the bug: - test_duplicate_attribute_removed_with_false - test_duplicate_attribute_removed_with_null - test_multiple_duplicate_attributes_removed All three currently fail because render() directly pushes text replacement edits, bypassing the Tag Processor's duplicate tracking.
1 parent 1879747 commit 245f24a

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/phpunit/tests/html-api/wpHtmlTemplate.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,4 +1150,60 @@ public function test_render_returns_false_for_boolean_replacement() {
11501150
$result = T::from( '<p></%val></p>' )->bind( array( 'val' => true ) )->render();
11511151
$this->assertFalse( $result );
11521152
}
1153+
1154+
/**
1155+
* Verifies that duplicate attributes after the placeholder are removed with false.
1156+
*
1157+
* HTML may contain duplicate attributes (e.g., from user error or generated HTML).
1158+
* When false removes the placeholder attribute, duplicates should also be removed.
1159+
*
1160+
* @ticket 60229
1161+
*
1162+
* @covers ::from
1163+
* @covers ::bind
1164+
* @covers ::render
1165+
*/
1166+
public function test_duplicate_attribute_removed_with_false() {
1167+
// The "disabled" attribute appears twice: once with placeholder, once as boolean.
1168+
$result = T::from( '<input disabled="</%d>" disabled type="text">' )
1169+
->bind( array( 'd' => false ) )
1170+
->render();
1171+
// Both occurrences of "disabled" should be removed.
1172+
$this->assertEqualHTML( '<input type="text">', $result );
1173+
}
1174+
1175+
/**
1176+
* Verifies that duplicate attributes after the placeholder are removed with null.
1177+
*
1178+
* @ticket 60229
1179+
*
1180+
* @covers ::from
1181+
* @covers ::bind
1182+
* @covers ::render
1183+
*/
1184+
public function test_duplicate_attribute_removed_with_null() {
1185+
$result = T::from( '<input class="</%c>" class="extra" type="text">' )
1186+
->bind( array( 'c' => null ) )
1187+
->render();
1188+
$this->assertEqualHTML( '<input type="text">', $result );
1189+
}
1190+
1191+
/**
1192+
* Verifies that multiple duplicate attributes are all removed with false.
1193+
*
1194+
* When an attribute appears more than twice, all occurrences should be removed.
1195+
*
1196+
* @ticket 60229
1197+
*
1198+
* @covers ::from
1199+
* @covers ::bind
1200+
* @covers ::render
1201+
*/
1202+
public function test_multiple_duplicate_attributes_removed() {
1203+
// Three occurrences of "disabled": placeholder + two duplicates.
1204+
$result = T::from( '<input disabled="</%d>" disabled disabled type="text">' )
1205+
->bind( array( 'd' => false ) )
1206+
->render();
1207+
$this->assertEqualHTML( '<input type="text">', $result );
1208+
}
11531209
}

0 commit comments

Comments
 (0)