Changeset 59250
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php
r59076 r59250 2460 2460 2461 2461 // Accumulate shift of the given pointer within this function call. 2462 if ( $diff->start < =$shift_this_point ) {2462 if ( $diff->start < $shift_this_point ) { 2463 2463 $accumulated_shift_for_given_point += $shift; 2464 2464 } -
trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php
r58866 r59250 41 41 42 42 /** 43 * Data provider. 44 * 45 * @return array[] 46 */ 47 public static function data_get_modifiable_text_replacements() { 48 return array( 49 'shorter' => array( 'just some text', 'shorter text' ), 50 'same length' => array( 'just some text', 'different text' ), 51 'longer' => array( 'just some text', 'a bit longer text' ), 52 ); 53 } 54 55 /** 43 56 * Ensures that `get_modifiable_text()` reads enqueued updates when read 44 57 * from after writing; guarantees consistency through writes. 45 58 * 46 59 * @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 ); 60 * @ticket 62241 61 * 62 * @dataProvider data_get_modifiable_text_replacements 63 * 64 * @param string $initial Initial text. 65 * @param string $replacement Replacement text. 66 */ 67 public function test_get_modifiable_text_is_consistent_after_writes( $initial, $replacement ) { 68 $processor = new WP_HTML_Tag_Processor( $initial ); 52 69 $processor->next_token(); 53 70 … … 59 76 60 77 $this->assertSame( 61 $ before,78 $initial, 62 79 $processor->get_modifiable_text(), 63 80 'Should have found initial test text: check test setup.' 64 81 ); 65 82 66 $processor->set_modifiable_text( $ after);67 $this->assertSame( 68 $ after,83 $processor->set_modifiable_text( $replacement ); 84 $this->assertSame( 85 $replacement, 69 86 $processor->get_modifiable_text(), 70 87 'Should have found enqueued updated text.' 71 88 ); 72 73 $processor->get_updated_html(); 74 $this->assertSame( 75 $after, 89 $this->assertSame( 90 $replacement, 91 $processor->get_updated_html(), 92 'Should match updated HTML.' 93 ); 94 $this->assertSame( 95 $replacement, 96 $processor->get_modifiable_text(), 97 'Should have found updated text.' 98 ); 99 } 100 101 /** 102 * Ensures that `get_modifiable_text()` reads enqueued updates when read from 103 * after writing; guarantees consistency through writes after closed tag element. 104 * 105 * @ticket 62241 106 * 107 * @dataProvider data_get_modifiable_text_replacements 108 * 109 * @param string $initial Initial text. 110 * @param string $replacement Replacement text. 111 */ 112 public function test_get_modifiable_text_is_consistent_after_writes_when_text_after_closed_tag_element( $initial, $replacement ) { 113 $html_before = '<p>some content</p>'; 114 $processor = new WP_HTML_Tag_Processor( $html_before . $initial ); 115 // Move to the text node after the closing p tag. 116 $processor->next_token(); 117 $processor->next_token(); 118 $processor->next_token(); 119 $processor->next_token(); 120 121 $this->assertSame( 122 '#text', 123 $processor->get_token_name(), 124 "Should have found text node but found '{$processor->get_token_name()}' instead: check test setup." 125 ); 126 127 $this->assertSame( 128 $initial, 129 $processor->get_modifiable_text(), 130 'Should have found initial test text: check test setup.' 131 ); 132 133 $processor->set_modifiable_text( $replacement ); 134 $this->assertSame( 135 $replacement, 136 $processor->get_modifiable_text(), 137 'Should have found enqueued updated text.' 138 ); 139 140 $this->assertSame( 141 $html_before . $replacement, 142 $processor->get_updated_html(), 143 'Should match updated HTML.' 144 ); 145 146 $this->assertSame( 147 $replacement, 76 148 $processor->get_modifiable_text(), 77 149 'Should have found updated text.'
Note: See TracChangeset
for help on using the changeset viewer.