' );
+ $processor->next_tag();
+
+ $this->assertSame(
+ array( 'existing' ),
+ $processor->get_attribute_names_with_prefix( '' ),
+ 'Expected to only report the existing attribute: check test setup.'
+ );
+
+ $processor->add_class( 'added' );
+
+ $this->assertSame(
+ array( 'class' ),
+ $processor->get_attribute_names_with_prefix( 'class' ),
+ 'Failed to report the newly-added `class` attribute.'
+ );
+ }
+
+ /**
+ * Ensures that when the `class` attribute is emptied via remove_class(), that
+ * it’s reported by get_attribute_names_with_prefix() immediately after being added.
+ *
+ * @ticket 64567
+ *
+ * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix
+ */
+ public function test_get_attribute_names_with_prefix_immediately_reflects_class_after_removing_all_classes() {
+ $processor = new WP_HTML_Tag_Processor( '
' );
+ $processor->next_tag();
+
+ $this->assertSame(
+ array( 'class', 'existing' ),
+ $processor->get_attribute_names_with_prefix( '' ),
+ 'Expected to find proper existing attributes: check test setup.'
+ );
+
+ $processor->remove_class( 'red' );
+
+ $this->assertSame(
+ array( 'class', 'existing' ),
+ $processor->get_attribute_names_with_prefix( '' ),
+ 'Should have the same attributes after removing one of two classes.'
+ );
+
+ $processor->remove_class( 'green' );
+
+ $this->assertSame(
+ array( 'existing' ),
+ $processor->get_attribute_names_with_prefix( '' ),
+ 'Should have removed the `class` attribute after removing all class names.'
+ );
+ }
+
+ /**
+ * Ensures get_attribute_names_with_prefix() agrees with get_attribute()
+ * after pending updates, returning each name once with no stale entries.
+ *
+ * @ticket 64567
+ *
+ * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix
+ */
+ public function test_get_attribute_names_with_prefix_immediately_agrees_with_get_attribute_after_updates() {
+ $processor = new WP_HTML_Tag_Processor( '
Test
' );
+ $processor->next_tag();
+
+ $this->assertSame(
+ array( 'data-keep', 'data-drop' ),
+ $processor->get_attribute_names_with_prefix( '' ),
+ 'Failed to find expected existing attributes: check test setup.'
+ );
+
+ $this->assertSame(
+ '1',
+ $processor->get_attribute( 'data-keep' ),
+ 'Failed to find expected existing `data-keep` attribute value: check test setup.'
+ );
+
+ $this->assertSame(
+ '2',
+ $processor->get_attribute( 'data-drop' ),
+ 'Failed to find expected existing `data-drop` attribute value: check test setup.'
+ );
+
+ $processor->set_attribute( 'data-keep', 'updated' );
+ $processor->set_attribute( 'data-add', 'new' );
+ $processor->remove_attribute( 'data-drop' );
+
+ $names = $processor->get_attribute_names_with_prefix( 'data-' );
+
+ $this->assertSame(
+ array( 'data-add', 'data-keep' ),
+ $names,
+ 'Failed to report the expected attribute names after removing and adding attributes.'
+ );
+
+ foreach ( $names as $name ) {
+ $this->assertNotNull(
+ $processor->get_attribute( $name ),
+ "get_attribute_names_with_prefix() reported '{$name}' but get_attribute() did not agree."
+ );
+ }
+ }
+
/**
* @ticket 56299
*