Changeset 58866
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php
r58858 r58866 615 615 * @since 6.5.0 616 616 * 617 * @var string617 * @var int 618 618 */ 619 619 private $text_length; … … 2895 2895 */ 2896 2896 public function get_modifiable_text(): string { 2897 if ( null === $this->text_starts_at || 0 === $this->text_length ) { 2897 $has_enqueued_update = isset( $this->lexical_updates['modifiable text'] ); 2898 2899 if ( ! $has_enqueued_update && ( null === $this->text_starts_at || 0 === $this->text_length ) ) { 2898 2900 return ''; 2899 2901 } 2900 2902 2901 $text = isset( $this->lexical_updates['modifiable text'] )2903 $text = $has_enqueued_update 2902 2904 ? $this->lexical_updates['modifiable text']->text 2903 2905 : substr( $this->html, $this->text_starts_at, $this->text_length ); -
trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php
r58829 r58866 38 38 ); 39 39 } 40 } 41 42 /** 43 * Ensures that `get_modifiable_text()` reads enqueued updates when read 44 * from after writing; guarantees consistency through writes. 45 * 46 * @ticket 61617 47 */ 48 public function test_get_modifiable_text_is_consistent_after_writes() { 49 $before = 'just some text'; 50 $after = 'different text'; 51 $processor = new WP_HTML_Tag_Processor( $before ); 52 $processor->next_token(); 53 54 $this->assertSame( 55 '#text', 56 $processor->get_token_name(), 57 "Should have found text node but found '{$processor->get_token_name()}' instead: check test setup." 58 ); 59 60 $this->assertSame( 61 $before, 62 $processor->get_modifiable_text(), 63 'Should have found initial test text: check test setup.' 64 ); 65 66 $processor->set_modifiable_text( $after ); 67 $this->assertSame( 68 $after, 69 $processor->get_modifiable_text(), 70 'Should have found enqueued updated text.' 71 ); 72 73 $processor->get_updated_html(); 74 $this->assertSame( 75 $after, 76 $processor->get_modifiable_text(), 77 'Should have found updated text.' 78 ); 79 } 80 81 /** 82 * Ensures that `get_modifiable_text()` reads enqueued updates when read from after 83 * writing when starting from an empty text; guarantees consistency through writes. 84 * 85 * @ticket 61617 86 */ 87 public function test_get_modifiable_text_is_consistent_after_writes_to_empty_text() { 88 $after = 'different text'; 89 $processor = new WP_HTML_Tag_Processor( '<script></script>' ); 90 $processor->next_token(); 91 92 $this->assertSame( 93 'SCRIPT', 94 $processor->get_token_name(), 95 "Should have found text node but found '{$processor->get_token_name()}' instead: check test setup." 96 ); 97 98 $this->assertSame( 99 '', 100 $processor->get_modifiable_text(), 101 'Should have found initial test text: check test setup.' 102 ); 103 104 $processor->set_modifiable_text( $after ); 105 $this->assertSame( 106 $after, 107 $processor->get_modifiable_text(), 108 'Should have found enqueued updated text.' 109 ); 110 111 $processor->get_updated_html(); 112 $this->assertSame( 113 $after, 114 $processor->get_modifiable_text(), 115 'Should have found updated text.' 116 ); 40 117 } 41 118
Note: See TracChangeset
for help on using the changeset viewer.