Changeset 64987
- Timestamp:
- 10/28/2026 10:55:06 PM (9 days ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 11 edited
-
block-bindings/patternOverridesSource.php (modified) (4 diffs)
-
block-bindings/postDataSource.php (modified) (4 diffs)
-
block-bindings/termDataSource.php (modified) (3 diffs)
-
bookmark/sanitizeBookmarkField.php (modified) (7 diffs)
-
post/getPostFormatLink.php (modified) (4 diffs)
-
post/theGuid.php (modified) (3 diffs)
-
post/theTitleAttribute.php (modified) (3 diffs)
-
post/walkerPageDropdown.php (modified) (3 diffs)
-
rewrite/wpMatchesMapRegex.php (modified) (4 diffs)
-
term/defaultTopicCountScale.php (modified) (1 diff)
-
term/getTheTermList.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/block-bindings/patternOverridesSource.php
r64324 r64987 83 83 return array( 84 84 'empty attributes' => array( array() ), 85 'missing metadata' => array( array( 'unrelated' => 'value' ) ),86 85 'empty metadata array' => array( array( 'metadata' => array() ) ), 87 86 'empty name string' => array( array( 'metadata' => array( 'name' => '' ) ) ), 88 'null name' => array( array( 'metadata' => array( 'name' => null ) ) ), 89 'false name' => array( array( 'metadata' => array( 'name' => false ) ) ), 90 ); 91 } 92 93 /** 94 * Tests that _block_bindings_pattern_overrides_get_value() returns null when context is empty or missing. 95 * 96 * @ticket 65819 97 * 98 * @covers ::_block_bindings_pattern_overrides_get_value 99 * 100 * @dataProvider data_empty_context 101 * 102 * @param array $context Available block context. 103 */ 104 public function test_get_value_returns_null_when_context_empty( array $context ) { 87 ); 88 } 89 90 /** 91 * Tests that _block_bindings_pattern_overrides_get_value() returns null when context is empty. 92 * 93 * @ticket 65819 94 * 95 * @covers ::_block_bindings_pattern_overrides_get_value 96 * 97 */ 98 public function test_get_value_returns_null_when_context_empty() { 105 99 $block = $this->create_block( 106 100 array( … … 109 103 ), 110 104 ), 111 $context105 array() 112 106 ); 113 107 114 108 $this->assertNull( _block_bindings_pattern_overrides_get_value( array(), $block, 'content' ) ); 115 }116 117 /**118 * Data provider for test_get_value_returns_null_when_context_empty.119 *120 * @return array[]121 */122 public function data_empty_context() {123 return array(124 'empty context' => array( array() ),125 'missing pattern/overrides key' => array( array( 'postType' => 'post' ) ),126 'empty pattern/overrides array' => array( array( 'pattern/overrides' => array() ) ),127 );128 109 } 129 110 … … 181 162 182 163 /** 183 * Tests that _block_bindings_pattern_overrides_get_value() returns the matching override value for an attribute.184 *185 * @ticket 65819186 *187 * @covers ::_block_bindings_pattern_overrides_get_value188 */189 public function test_get_value_returns_override_value() {190 $block = $this->create_block(191 array(192 'metadata' => array(193 'name' => 'custom-header',194 ),195 ),196 array(197 'pattern/overrides' => array(198 'custom-header' => array(199 'content' => 'Overridden Header Text',200 ),201 ),202 )203 );204 205 $result = _block_bindings_pattern_overrides_get_value( array(), $block, 'content' );206 207 $this->assertSame( 'Overridden Header Text', $result );208 }209 210 /**211 164 * Tests that the registered source get_value() method executes correctly. 212 165 * … … 274 227 public function data_override_values_and_types() { 275 228 return array( 276 'string' => array( 'A customized string' ),277 229 'empty string' => array( '' ), 278 'integer' => array( 12345 ),279 230 'zero integer' => array( 0 ), 280 'zero string' => array( '0' ),281 'boolean true' => array( true ),282 231 'boolean false' => array( false ), 283 232 'array' => array( array( 'nested' => 'value' ) ), -
trunk/tests/phpunit/tests/block-bindings/postDataSource.php
r64287 r64987 179 179 'missing args' => array( array() ), 180 180 'empty string field' => array( array( 'field' => '' ) ), 181 'null field' => array( array( 'field' => null ) ),182 181 'empty string key' => array( array( 'key' => '' ) ), 183 'null key' => array( array( 'key' => null ) ),184 182 'both empty field & key' => array( 185 183 array( … … 216 214 return array( 217 215 'missing postId context' => array( array() ), 218 'empty string postId' => array( array( 'postId' => '' ) ),219 'null postId' => array( array( 'postId' => null ) ),220 216 'zero postId' => array( array( 'postId' => 0 ) ), 221 217 ); … … 303 299 304 300 /** 305 * Tests that _block_bindings_post_data_get_value() returns date field formatted in ISO 8601.306 *307 * @ticket 65819308 *309 * @covers ::_block_bindings_post_data_get_value310 */311 public function test_get_value_returns_date_field() {312 $block = $this->create_block(313 'core/paragraph',314 array( 'postId' => self::$post_id )315 );316 317 $this->assertSame(318 '2025-01-01T10:00:00+00:00',319 _block_bindings_post_data_get_value( array( 'field' => 'date' ), $block ),320 'Date field should return the post date in ISO 8601 format.'321 );322 }323 324 /**325 301 * Tests that _block_bindings_post_data_get_value() returns modified date when modified date is later than publish date. 326 302 * … … 359 335 _block_bindings_post_data_get_value( array( 'field' => 'modified' ), $block ), 360 336 'Modified date should return empty string when equal to publish date.' 361 );362 }363 364 /**365 * Tests that _block_bindings_post_data_get_value() returns permalink for link field.366 *367 * @ticket 65819368 *369 * @covers ::_block_bindings_post_data_get_value370 */371 public function test_get_value_returns_link_field() {372 $block = $this->create_block(373 'core/paragraph',374 array( 'postId' => self::$post_id )375 );376 377 $expected_link = esc_url( get_permalink( self::$post_id ) );378 $this->assertSame(379 $expected_link,380 _block_bindings_post_data_get_value( array( 'field' => 'link' ), $block ),381 'Link field should return esc_url( get_permalink() ).'382 337 ); 383 338 } -
trunk/tests/phpunit/tests/block-bindings/termDataSource.php
r64233 r64987 144 144 'missing field' => array( array() ), 145 145 'empty string' => array( array( 'field' => '' ) ), 146 'null field' => array( array( 'field' => null ) ),147 'false field' => array( array( 'field' => false ) ),148 146 ); 149 147 } … … 171 169 public function data_missing_or_empty_context() { 172 170 return array( 173 'empty context' => array( array() ),174 171 'missing taxonomy' => array( array( 'termId' => 123 ) ), 175 172 'missing termId' => array( array( 'taxonomy' => 'category' ) ), … … 186 183 ), 187 184 ), 188 'null identifiers' => array(189 array(190 'termId' => null,191 'taxonomy' => null,192 ),193 ),194 185 ); 195 186 } -
trunk/tests/phpunit/tests/bookmark/sanitizeBookmarkField.php
r64416 r64987 75 75 public static function data_casts_integer_fields() { 76 76 return array( 77 'link_id, raw' => array( 'link_id', '12abc', 'raw', 12 ), 78 'link_id, display' => array( 'link_id', '5', 'display', 5 ), 79 'link_id, edit' => array( 'link_id', '6', 'edit', 6 ), 80 'link_id, attribute' => array( 'link_id', '7', 'attribute', 7 ), 81 'link_rating, db' => array( 'link_rating', '8', 'db', 8 ), 82 'link_rating, js' => array( 'link_rating', '9', 'js', 9 ), 83 'link_rating, empty string' => array( 'link_rating', '', 'display', 0 ), 84 'link_rating, zero string' => array( 'link_rating', '0', 'display', 0 ), 77 'link_id, raw' => array( 'link_id', '12abc', 'raw', 12 ), 78 'link_id, attribute' => array( 'link_id', '7', 'attribute', 7 ), 79 'link_rating, js' => array( 'link_rating', '9', 'js', 9 ), 85 80 ); 86 81 } … … 115 110 'array of mixed values, display' => array( array( '1', '-2', 'abc', 3 ), 'display', array( 1, 2, 0, 3 ) ), 116 111 'single value, edit' => array( '5', 'edit', array( 5 ) ), 117 'empty array, db' => array( array(), 'db', array() ),118 112 'empty string, raw' => array( '', 'raw', array( 0 ) ), 119 113 ); … … 148 142 'markup' => array( '<b>N</b>', 'N' ), 149 143 'other character' => array( 'x', '' ), 150 'empty string' => array( '', '' ),151 'zero string' => array( '0', '' ),152 144 ); 153 145 } … … 176 168 public static function data_link_target_values() { 177 169 return array( 178 '_blank' => array( '_blank', '_blank' ), 179 '_top' => array( '_top', '_top' ), 180 '_self' => array( '_self', '' ), 181 'uppercase' => array( '_BLANK', '' ), 182 'frame name' => array( 'my-frame', '' ), 183 'empty string' => array( '', '' ), 184 'zero string' => array( '0', '' ), 170 '_blank' => array( '_blank', '_blank' ), 171 '_top' => array( '_top', '_top' ), 172 '_self' => array( '_self', '' ), 173 'uppercase' => array( '_BLANK', '' ), 185 174 ); 186 175 } … … 277 266 * @dataProvider data_edit_escaping_function 278 267 * 279 * @param string $field Bookmark field name. 280 * @param string $filter Filter run by the expected escaping function. 281 */ 282 public function test_edit_context_escaping_function( $field, $filter ) { 268 * @param string $field Bookmark field name. 269 * @param string $filter Filter run by the expected escaping function. 270 * @param string $expected Expected escaped and filtered value. 271 */ 272 public function test_edit_context_escaping_function( $field, $filter, $expected ) { 283 273 // Isolates the escaping from the default filters on the link_notes hooks. 284 274 remove_all_filters( "edit_{$field}" ); … … 292 282 add_filter( $hook, array( $mock, 'filter' ) ); 293 283 } 294 295 sanitize_bookmark_field( $field, self::MARKUP, self::BOOKMARK_ID, 'edit' ); 284 add_filter( 285 'esc_html', 286 static function ( $escaped ) { 287 return $escaped . '|html'; 288 }, 289 20 290 ); 291 add_filter( 292 'attribute_escape', 293 static function ( $escaped ) { 294 return $escaped . '|attribute'; 295 }, 296 20 297 ); 298 299 $result = sanitize_bookmark_field( $field, self::MARKUP, self::BOOKMARK_ID, 'edit' ); 300 301 $this->assertSame( $expected, $result ); 296 302 297 303 foreach ( $escaping_filters as $hook => $mock ) { … … 307 313 public static function data_edit_escaping_function() { 308 314 return array( 309 'link_notes' => array( 'link_notes', 'esc_html' ),310 'other field' => array( 'link_foo', 'attribute_escape' ),315 'link_notes' => array( 'link_notes', 'esc_html', '<b>Bold</b> & "double" 'single'|html' ), 316 'other field' => array( 'link_foo', 'attribute_escape', '<b>Bold</b> & "double" 'single'|attribute' ), 311 317 ); 312 318 } -
trunk/tests/phpunit/tests/post/getPostFormatLink.php
r64546 r64987 17 17 */ 18 18 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 19 $formats = array( 'aside', ' chat', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio' );19 $formats = array( 'aside', 'video' ); 20 20 21 21 foreach ( $formats as $format ) { … … 35 35 public function test_get_post_format_link_non_existent_term() { 36 36 $this->assertFalse( get_post_format_link( 'nonexistent' ) ); 37 }38 39 /**40 * Tests that get_post_format_link() returns false for an empty string.41 *42 * @ticket 6581943 */44 public function test_get_post_format_link_empty_string() {45 $this->assertFalse( get_post_format_link( '' ) );46 37 } 47 38 … … 107 98 108 99 /** 109 * Tests that get_post_format_link() respects a custom permastruct base.110 *111 * @ticket 65819112 */113 public function test_get_post_format_link_with_custom_permastruct() {114 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );115 add_permastruct( 'post_format', 'format/%post_format%' );116 117 $expected = home_url( '/format/aside/' );118 $actual = get_post_format_link( 'aside' );119 120 remove_permastruct( 'post_format' );121 122 $this->assertSame( $expected, $actual );123 }124 125 /**126 * Tests that get_post_format_link() strips the 'post-format-' prefix from the query arg in plain permalinks.127 *128 * @ticket 65819129 */130 public function test_get_post_format_link_strips_prefix_in_query_args() {131 $link = get_post_format_link( 'video' );132 133 $this->assertStringNotContainsString( 'post-format-video', $link );134 $this->assertStringContainsString( 'post_format=video', $link );135 }136 137 /**138 * Tests that get_post_format_link() returns false for non-string inputs.139 *140 * @ticket 65819141 */142 public function test_get_post_format_link_non_string_input() {143 $this->assertFalse( get_post_format_link( 123 ) );144 $this->assertFalse( get_post_format_link( null ) );145 }146 147 /**148 100 * Tests that the 'term_link' filter can modify the post format link. 149 101 * … … 172 124 public static function data_standard_post_formats() { 173 125 return array( 174 'aside format' => array( 'aside' ), 175 'chat format' => array( 'chat' ), 176 'gallery format' => array( 'gallery' ), 177 'link format' => array( 'link' ), 178 'image format' => array( 'image' ), 179 'quote format' => array( 'quote' ), 180 'status format' => array( 'status' ), 181 'video format' => array( 'video' ), 182 'audio format' => array( 'audio' ), 126 'aside format' => array( 'aside' ), 127 'video format' => array( 'video' ), 183 128 ); 184 129 } -
trunk/tests/phpunit/tests/post/theGuid.php
r64535 r64987 46 46 47 47 /** 48 * Tests that the_guid() displays the guid when given a post ID.49 *50 * @ticket 6581951 */52 public function test_the_guid_with_post_id() {53 $this->expectOutputString( self::$guid );54 the_guid( self::$post_id );55 }56 57 /**58 48 * Tests that the_guid() displays the guid when given a WP_Post object. 59 49 * … … 87 77 $this->expectOutputString( '' ); 88 78 the_guid( 999999 ); 89 }90 91 /**92 * Tests that the_guid() outputs an empty string when called with 0 and no global post exists.93 *94 * @ticket 6581995 */96 public function test_the_guid_with_zero_and_no_global_post() {97 unset( $GLOBALS['post'] );98 99 $this->expectOutputString( '' );100 the_guid( 0 );101 79 } 102 80 … … 175 153 remove_filter( 'get_the_guid', $custom_callback, 10 ); 176 154 } 177 178 /**179 * Tests that the_guid() displays the guid for an attachment.180 *181 * @ticket 65819182 */183 public function test_the_guid_with_attachment() {184 $attachment_guid = 'https://example.org/wp-content/uploads/2026/10/test.jpg';185 $attachment_id = self::factory()->attachment->create_object(186 'test.jpg',187 0,188 array(189 'post_mime_type' => 'image/jpeg',190 'post_type' => 'attachment',191 'guid' => $attachment_guid,192 )193 );194 195 $this->expectOutputString( $attachment_guid );196 the_guid( $attachment_id );197 }198 155 } -
trunk/tests/phpunit/tests/post/theTitleAttribute.php
r64515 r64987 118 118 return array( 119 119 'array with boolean false' => array( array( 'echo' => false ) ), 120 'array with integer 0' => array( array( 'echo' => 0 ) ),121 120 'query string with echo=0' => array( 'echo=0' ), 122 121 ); … … 234 233 235 234 /** 236 * Tests that the_title_attribute() accepts both a post ID and a WP_Post object. 237 * 238 * @ticket 65819 239 */ 240 public function test_accepts_post_id_and_post_object() { 241 $by_id = the_title_attribute( 242 array( 243 'post' => self::$post_id, 244 'echo' => false, 245 ) 246 ); 247 235 * Tests that the_title_attribute() accepts a WP_Post object. 236 * 237 * @ticket 65819 238 */ 239 public function test_accepts_post_object() { 248 240 $by_object = the_title_attribute( 249 241 array( … … 253 245 ); 254 246 255 $this->assertSame( 'Standard Post Title', $by_id ); 256 $this->assertSame( $by_id, $by_object ); 247 $this->assertSame( 'Standard Post Title', $by_object ); 257 248 } 258 249 -
trunk/tests/phpunit/tests/post/walkerPageDropdown.php
r64380 r64987 66 66 '<option class="level-0" value="7">About</option>', 67 67 ), 68 'first level of depth' => array(69 array(),70 1,71 '<option class="level-1" value="7"> About</option>',72 ),73 'second level of depth' => array(74 array(),75 2,76 '<option class="level-2" value="7"> About</option>',77 ),78 'selected by integer ID' => array(79 array( 'selected' => 7 ),80 0,81 '<option class="level-0" value="7" selected="selected">About</option>',82 ),83 68 'selected by string ID' => array( 84 69 array( 'selected' => '7' ), 85 70 0, 86 71 '<option class="level-0" value="7" selected="selected">About</option>', 87 ),88 'another page is selected' => array(89 array( 'selected' => 70 ),90 0,91 '<option class="level-0" value="7">About</option>',92 ),93 'selected value is an empty string' => array(94 array( 'selected' => '' ),95 0,96 '<option class="level-0" value="7">About</option>',97 ),98 'selected value is false' => array(99 array( 'selected' => false ),100 0,101 '<option class="level-0" value="7">About</option>',102 72 ), 103 73 'post name as the value field' => array( … … 127 97 '<option class="level-0" value="7">About</option>', 128 98 ), 129 'with depth and selection' => array(130 array( 'selected' => 7 ),131 1,132 '<option class="level-1" value="7" selected="selected"> About</option>',133 ),134 99 ); 135 100 } … … 164 129 public static function data_page_titles() { 165 130 return array( 166 'plain title' => array( 'Contact us', 'Contact us' ), 167 'title with markup' => array( 'Tom & <b>Jerry</b> "quoted"', 'Tom & <b>Jerry</b> "quoted"' ), 168 'empty title' => array( '', '#7 (no title)' ), 169 'zero title' => array( '0', '0' ), 170 'title with only spaces' => array( ' ', ' ' ), 131 'title with markup' => array( 'Tom & <b>Jerry</b> "quoted"', 'Tom & <b>Jerry</b> "quoted"' ), 132 'empty title' => array( '', '#7 (no title)' ), 133 'zero title' => array( '0', '0' ), 171 134 ); 172 135 } -
trunk/tests/phpunit/tests/rewrite/wpMatchesMapRegex.php
r64400 r64987 39 39 40 40 return array( 41 'single placeholder' => array(42 'index.php?pagename=$matches[1]',43 array( 'about/', 'about' ),44 'index.php?pagename=about',45 ),46 41 'several placeholders' => array( 47 42 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]', … … 74 69 'index.php?a=first&b=', 75 70 ), 76 'empty match' => array(77 'index.php?a=$matches[1]&b=$matches[2]',78 array( 'full', '', 'second' ),79 'index.php?a=&b=second',80 ),81 71 'zero string match' => array( 82 72 'index.php?page=$matches[1]', 83 73 array( 'full', '0' ), 84 74 'index.php?page=0', 85 ),86 'no matches' => array(87 'index.php?a=$matches[1]',88 array(),89 'index.php?a=',90 75 ), 91 76 'two-digit placeholders' => array( … … 117 102 'index.php?a=$match[1]', 118 103 ), 119 'subject without placeholders' => array(120 'index.php?feed=rss2',121 array( 'full', 'first' ),122 'index.php?feed=rss2',123 ),124 104 'empty subject' => array( 125 105 '', … … 129 109 ); 130 110 } 131 132 /**133 * Tests that a new instance stores the mapped subject in its output property.134 *135 * @ticket 65819136 *137 * @covers ::__construct138 * @covers ::_map139 */140 public function test_constructor_sets_output() {141 $map = new WP_MatchesMapRegex( 'index.php?p=$matches[1]', array( 'full', '123' ) );142 143 $this->assertSame( 'index.php?p=123', $map->output );144 }145 111 } -
trunk/tests/phpunit/tests/term/defaultTopicCountScale.php
r64427 r64987 31 31 public static function data_counts() { 32 32 return array( 33 'zero' => array( 0, 0 ), 34 'one' => array( 1, 30 ), 35 'rounds down' => array( 2, 48 ), 36 'rounds up' => array( 4, 70 ), 37 'nine' => array( 9, 100 ), 38 'ninety-nine' => array( 99, 200 ), 39 'nine hundred ninety' => array( 999, 300 ), 40 'numeric string' => array( '9', 100 ), 33 'zero' => array( 0, 0 ), 34 'one' => array( 1, 30 ), 35 'rounds down' => array( 2, 48 ), 36 'rounds up' => array( 4, 70 ), 37 'ninety-nine' => array( 99, 200 ), 41 38 ); 42 39 } -
trunk/tests/phpunit/tests/term/getTheTermList.php
r64473 r64987 118 118 119 119 $this->assertWPError( $result ); 120 $this->assertSame( 'invalid_term', $result->get_error_code() ); 120 121 } 121 122
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)