Changeset 64282
- Timestamp:
- 10/10/2026 02:18:37 PM (3 days ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
-
src/js/_enqueues/admin/common.js (modified) (3 diffs)
-
src/wp-admin/admin.php (modified) (1 diff)
-
src/wp-includes/class-wp-admin-notice-collector.php (added)
-
src/wp-includes/functions.php (modified) (2 diffs)
-
src/wp-settings.php (modified) (1 diff)
-
tests/phpunit/tests/functions/wpAdminNotice.php (modified) (36 diffs)
-
tests/phpunit/tests/functions/wpGetAdminNotice.php (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/common.js
r64133 r64282 1076 1076 } 1077 1077 1078 /*1079 * The `.below-h2` class is here just for backward compatibility with plugins1080 * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570.1081 * If '.wp-header-end' is found, append the notices after it otherwise1082 * after the first h1 or h2 heading found within the main content.1083 */1084 if ( ! $headerEnd.length ) {1085 $headerEnd = $( '.wrap h1, .wrap h2' ).first();1086 }1087 $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $headerEnd );1088 1089 1078 /** 1090 1079 * Makes notices dismissible. … … 1525 1514 input.on('change', toggleUploadButton); 1526 1515 })(); 1516 1517 /** 1518 * Moves the admin notices into an `aside` element after the first `h1`. 1519 * Prior to 7.2.0, admin notices were only moved after the first `h1`; 1520 * The `aside` wrapper was added in 7.2.0. 1521 * 1522 * @since 7.2.0 1523 * 1524 * @return {void} 1525 */ 1526 function moveAdminNotices() { 1527 /* 1528 * The `.below-h2` class is here just for backward compatibility with plugins 1529 * that are (incorrectly) using it. Do not use. Use `.inline` instead. See #34570. 1530 * If '.wp-header-end' is found, append the notices after it otherwise 1531 * after the first h1 or h2 heading found within the main content. 1532 */ 1533 if ( ! $headerEnd.length ) { 1534 $headerEnd = $( '.wrap h1, .wrap h2' ).first(); 1535 } 1536 const $notices = $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ); 1537 if ( $notices.length ) { 1538 const $wpAdminNotices = $( '<aside id="wp-admin-notices"></aside>' ).attr( 'aria-label', __( 'Admin Notices' ) ).insertAfter( $headerEnd ); 1539 $notices.appendTo( $wpAdminNotices ); 1540 } 1541 } 1527 1542 1528 1543 /** … … 2128 2143 2129 2144 window.wpResponsive.init(); 2145 moveAdminNotices(); 2130 2146 setPinMenu(); 2131 2147 setMenuState(); -
trunk/src/wp-admin/admin.php
r64120 r64282 101 101 102 102 require_once ABSPATH . 'wp-admin/includes/admin.php'; 103 104 WP_Admin_Notice_Collector::init(); 103 105 104 106 auth_redirect(); -
trunk/src/wp-includes/functions.php
r64253 r64282 9343 9343 $args = apply_filters( 'wp_admin_notice_args', $args, $message ); 9344 9344 9345 // Unique ID is intended for internal use, and is not a filterable argument. 9346 $unique_id = wp_unique_prefixed_id( 'wp-admin-notice-' ); 9347 $args['notice_id'] = $unique_id; 9348 9345 9349 $wrap_with_p = false !== $args['paragraph_wrap']; 9346 9350 $wrap_opener = $wrap_with_p ? '<p>' : ''; … … 9352 9356 $trimmed_id = trim( $args['id'] ); 9353 9357 9358 $html_builder->set_attribute( 'data-id', $unique_id ); 9354 9359 if ( '' !== $trimmed_id ) { 9355 9360 $html_builder->set_attribute( 'id', $trimmed_id ); 9356 } 9361 } else { 9362 $html_builder->set_attribute( 'id', $unique_id ); 9363 } 9364 } else { 9365 $html_builder->set_attribute( 'data-id', $unique_id ); 9366 $html_builder->set_attribute( 'id', $unique_id ); 9357 9367 } 9358 9368 -
trunk/src/wp-settings.php
r63361 r64282 116 116 require ABSPATH . WPINC . '/meta.php'; 117 117 require ABSPATH . WPINC . '/functions.php'; 118 require ABSPATH . WPINC . '/class-wp-admin-notice-collector.php'; 118 119 require ABSPATH . WPINC . '/class-wp-meta-query.php'; 119 120 require ABSPATH . WPINC . '/class-wp-matchesmapregex.php'; -
trunk/tests/phpunit/tests/functions/wpAdminNotice.php
r63380 r64282 22 22 */ 23 23 public function test_should_output_admin_notice( $message, $args, $expected ) { 24 // Replace placeholder %%ID%% in expected string, required for test isolation. 25 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) ); 26 ++$next_id; 27 $expected = str_replace( '%%ID%%', $next_id, $expected ); 28 24 29 ob_start(); 25 30 wp_admin_notice( $message, $args ); … … 39 44 'message' => 'A notice with defaults.', 40 45 'args' => array(), 41 'expected' => '<div class="notice"><p>A notice with defaults.</p></div>',46 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with defaults.</p></div>', 42 47 ), 43 48 'an empty message (used for templates)' => array( … … 49 54 'additional_classes' => array( 'inline', 'hidden' ), 50 55 ), 51 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>',56 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>', 52 57 ), 53 58 'an empty message (used for templates) without paragraph wrapping' => array( … … 60 65 'paragraph_wrap' => false, 61 66 ), 62 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"></div>',67 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice notice-error is-dismissible inline hidden"></div>', 63 68 ), 64 69 'an "error" notice' => array( … … 67 72 'type' => 'error', 68 73 ), 69 'expected' => '<div class="notice notice-error"><p>An "error" notice.</p></div>',74 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-error"><p>An "error" notice.</p></div>', 70 75 ), 71 76 'a "success" notice' => array( … … 74 79 'type' => 'success', 75 80 ), 76 'expected' => '<div class="notice notice-success"><p>A "success" notice.</p></div>',81 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-success"><p>A "success" notice.</p></div>', 77 82 ), 78 83 'a "warning" notice' => array( … … 81 86 'type' => 'warning', 82 87 ), 83 'expected' => '<div class="notice notice-warning"><p>A "warning" notice.</p></div>',88 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-warning"><p>A "warning" notice.</p></div>', 84 89 ), 85 90 'an "info" notice' => array( … … 88 93 'type' => 'info', 89 94 ), 90 'expected' => '<div class="notice notice-info"><p>An "info" notice.</p></div>',95 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-info"><p>An "info" notice.</p></div>', 91 96 ), 92 97 'a type that already starts with "notice-"' => array( … … 95 100 'type' => 'notice-info', 96 101 ), 97 'expected' => '<div class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>',102 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>', 98 103 ), 99 104 'a dismissible notice' => array( … … 102 107 'dismissible' => true, 103 108 ), 104 'expected' => '<div class="notice is-dismissible"><p>A dismissible notice.</p></div>',109 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice is-dismissible"><p>A dismissible notice.</p></div>', 105 110 ), 106 111 'no type and an ID' => array( … … 109 114 'id' => 'message', 110 115 ), 111 'expected' => '<div id="message" class="notice"><p>A notice with an ID.</p></div>',116 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice"><p>A notice with an ID.</p></div>', 112 117 ), 113 118 'a type and an ID' => array( … … 117 122 'id' => 'message', 118 123 ), 119 'expected' => '<div id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>',124 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>', 120 125 ), 121 126 'no type and additional classes' => array( … … 124 129 'additional_classes' => array( 'error', 'notice-alt' ), 125 130 ), 126 'expected' => '<div class="notice error notice-alt"><p>A notice with additional classes.</p></div>',131 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice error notice-alt"><p>A notice with additional classes.</p></div>', 127 132 ), 128 133 'a type and additional classes' => array( … … 132 137 'additional_classes' => array( 'error', 'notice-alt' ), 133 138 ), 134 'expected' => '<div class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>',139 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>', 135 140 ), 136 141 'a dismissible notice with a type and additional classes' => array( … … 141 146 'additional_classes' => array( 'error', 'notice-alt' ), 142 147 ), 143 'expected' => '<div class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>',148 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>', 144 149 ), 145 150 'a notice without paragraph wrapping' => array( … … 148 153 'paragraph_wrap' => false, 149 154 ), 150 'expected' => '<div class="notice"><span>A notice without paragraph wrapping.</span></div>',155 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><span>A notice without paragraph wrapping.</span></div>', 151 156 ), 152 157 'an unsafe type' => array( … … 155 160 'type' => '"><script>alert("Howdy,admin!");</script>', 156 161 ), 157 'expected' => '<div class="notice notice-"><script>alert("Howdy,admin!");</script>"><p>A notice with an unsafe type.</p></div>',162 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-"><script>alert("Howdy,admin!");</script>"><p>A notice with an unsafe type.</p></div>', 158 163 ), 159 164 'an unsafe ID' => array( … … 162 167 'id' => '"><script>alert( "Howdy, admin!" );</script> <div class="notice', 163 168 ), 164 'expected' => '<div id=""><script>alert( "Howdy, admin!" );</script> <div class="notice" class="notice"><p>A notice with an unsafe ID.</p></div>',169 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id=""><script>alert( "Howdy, admin!" );</script> <div class="notice" class="notice"><p>A notice with an unsafe ID.</p></div>', 165 170 ), 166 171 'unsafe additional classes' => array( … … 169 174 'additional_classes' => array( '"><script>alert( "Howdy, admin!" );</script> <div class="notice' ), 170 175 ), 171 'expected' => '<div class="notice "><script>alert( "Howdy, admin!" );</script> <div class="notice"><p>A notice with unsafe additional classes.</p></div>',176 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice "><script>alert( "Howdy, admin!" );</script> <div class="notice"><p>A notice with unsafe additional classes.</p></div>', 172 177 ), 173 178 'a type that is not a string' => array( … … 176 181 'type' => array(), 177 182 ), 178 'expected' => '<div class="notice"><p>A notice with a type that is not a string.</p></div>',183 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with a type that is not a string.</p></div>', 179 184 ), 180 185 'a type with only empty space' => array( … … 183 188 'type' => " \t\r\n", 184 189 ), 185 'expected' => '<div class="notice"><p>A notice with a type with only empty space.</p></div>',190 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with a type with only empty space.</p></div>', 186 191 ), 187 192 'an ID that is not a string' => array( … … 190 195 'id' => array( 'message' ), 191 196 ), 192 'expected' => '<div class="notice"><p>A notice with an ID that is not a string.</p></div>',197 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with an ID that is not a string.</p></div>', 193 198 ), 194 199 'an ID with only empty space' => array( … … 197 202 'id' => " \t\r\n", 198 203 ), 199 'expected' => '<div class="notice"><p>A notice with an ID with only empty space.</p></div>',204 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with an ID with only empty space.</p></div>', 200 205 ), 201 206 'dismissible as a truthy value rather than (bool) true' => array( … … 204 209 'dismissible' => 1, 205 210 ), 206 'expected' => '<div class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>',211 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>', 207 212 ), 208 213 'additional classes that are not an array' => array( … … 211 216 'additional_classes' => 'class-1 class-2 class-3', 212 217 ), 213 'expected' => '<div class="notice"><p>A notice with additional classes that are not an array.</p></div>',218 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with additional classes that are not an array.</p></div>', 214 219 ), 215 220 'additional attribute with a value' => array( … … 218 223 'attributes' => array( 'aria-live' => 'assertive' ), 219 224 ), 220 'expected' => '<div class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>',225 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>', 221 226 ), 222 227 'additional hidden attribute' => array( … … 225 230 'attributes' => array( 'hidden' => true ), 226 231 ), 227 'expected' => '<div class="notice" hidden><p>A notice with the hidden attribute.</p></div>',232 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" hidden><p>A notice with the hidden attribute.</p></div>', 228 233 ), 229 234 'additional attribute no associative keys' => array( … … 232 237 'attributes' => array( 'hidden' ), 233 238 ), 234 'expected' => '<div class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>',239 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>', 235 240 ), 236 241 'additional attribute with role' => array( … … 239 244 'attributes' => array( 'role' => 'alert' ), 240 245 ), 241 'expected' => '<div class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>',246 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>', 242 247 ), 243 248 'multiple additional attributes' => array( … … 249 254 ), 250 255 ), 251 'expected' => '<div class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>',256 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>', 252 257 ), 253 258 'data attribute with unsafe value' => array( … … 256 261 'attributes' => array( 'data-unsafe' => '<script>alert( "Howdy, admin!" );</script>' ), 257 262 ), 258 'expected' => '<div class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>',263 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>', 259 264 ), 260 265 'additional invalid attribute' => array( … … 263 268 'attributes' => array( 'not-valid' => 'not-valid' ), 264 269 ), 265 'expected' => '<div class="notice"><p>A notice with an additional attribute that is invalid.</p></div>',270 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with an additional attribute that is invalid.</p></div>', 266 271 ), 267 272 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array( … … 276 281 ), 277 282 ), 278 'expected' => '<div class="notice" role="alert" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>',283 'expected' => '<div id="wp-admin-notice-%%ID%%" class="notice" role="alert" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>', 279 284 ), 280 285 'paragraph wrapping as a falsy value rather than (bool) false' => array( … … 283 288 'paragraph_wrap' => 0, 284 289 ), 285 'expected' => '<div class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>',290 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>', 286 291 ), 287 292 ); … … 296 301 */ 297 302 public function test_should_throw_doing_it_wrong_with_a_type_containing_spaces() { 303 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) ); 304 ++$next_id; 305 298 306 ob_start(); 299 307 wp_admin_notice( … … 304 312 305 313 $this->assertSame( 306 '<div class="notice notice-first second third fourth" ><p>A type containing spaces.</p></div>',314 '<div class="notice notice-first second third fourth" data-id="wp-admin-notice-' . $next_id . '" id="wp-admin-notice-' . $next_id . '"><p>A type containing spaces.</p></div>', 307 315 $actual 308 316 ); -
trunk/tests/phpunit/tests/functions/wpGetAdminNotice.php
r63380 r64282 22 22 */ 23 23 public function test_should_return_admin_notice( $message, $args, $expected ) { 24 // Replace placeholder %%ID%% in expected string, required for test isolation. 25 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) ); 26 ++$next_id; 27 $expected = str_replace( '%%ID%%', $next_id, $expected ); 28 24 29 $this->assertEqualHTML( $expected, wp_get_admin_notice( $message, $args ) ); 25 30 } … … 35 40 'message' => 'A notice with defaults.', 36 41 'args' => array(), 37 'expected' => '<div class="notice"><p>A notice with defaults.</p></div>',42 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with defaults.</p></div>', 38 43 ), 39 44 'an empty message (used for templates)' => array( … … 45 50 'additional_classes' => array( 'inline', 'hidden' ), 46 51 ), 47 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>',52 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice notice-error is-dismissible inline hidden"><p></p></div>', 48 53 ), 49 54 'an empty message (used for templates) without paragraph wrapping' => array( … … 56 61 'paragraph_wrap' => false, 57 62 ), 58 'expected' => '<div id="message" class="notice notice-error is-dismissible inline hidden"></div>',63 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice notice-error is-dismissible inline hidden"></div>', 59 64 ), 60 65 'an "error" notice' => array( … … 63 68 'type' => 'error', 64 69 ), 65 'expected' => '<div class="notice notice-error"><p>An "error" notice.</p></div>',70 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-error"><p>An "error" notice.</p></div>', 66 71 ), 67 72 'a "success" notice' => array( … … 70 75 'type' => 'success', 71 76 ), 72 'expected' => '<div class="notice notice-success"><p>A "success" notice.</p></div>',77 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-success"><p>A "success" notice.</p></div>', 73 78 ), 74 79 'a "warning" notice' => array( … … 77 82 'type' => 'warning', 78 83 ), 79 'expected' => '<div class="notice notice-warning"><p>A "warning" notice.</p></div>',84 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-warning"><p>A "warning" notice.</p></div>', 80 85 ), 81 86 'an "info" notice' => array( … … 84 89 'type' => 'info', 85 90 ), 86 'expected' => '<div class="notice notice-info"><p>An "info" notice.</p></div>',91 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-info"><p>An "info" notice.</p></div>', 87 92 ), 88 93 'a type that already starts with "notice-"' => array( … … 91 96 'type' => 'notice-info', 92 97 ), 93 'expected' => '<div class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>',98 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-notice-info"><p>A type that already starts with "notice-".</p></div>', 94 99 ), 95 100 'a dismissible notice' => array( … … 98 103 'dismissible' => true, 99 104 ), 100 'expected' => '<div class="notice is-dismissible"><p>A dismissible notice.</p></div>',105 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice is-dismissible"><p>A dismissible notice.</p></div>', 101 106 ), 102 107 'no type and an ID' => array( … … 105 110 'id' => 'message', 106 111 ), 107 'expected' => '<div id="message" class="notice"><p>A notice with an ID.</p></div>',112 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice"><p>A notice with an ID.</p></div>', 108 113 ), 109 114 'a type and an ID' => array( … … 113 118 'id' => 'message', 114 119 ), 115 'expected' => '<div id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>',120 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="message" class="notice notice-warning"><p>A warning notice with an ID.</p></div>', 116 121 ), 117 122 'no type and additional classes' => array( … … 120 125 'additional_classes' => array( 'error', 'notice-alt' ), 121 126 ), 122 'expected' => '<div class="notice error notice-alt"><p>A notice with additional classes.</p></div>',127 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice error notice-alt"><p>A notice with additional classes.</p></div>', 123 128 ), 124 129 'a type and additional classes' => array( … … 128 133 'additional_classes' => array( 'error', 'notice-alt' ), 129 134 ), 130 'expected' => '<div class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>',135 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-warning error notice-alt"><p>A warning notice with additional classes.</p></div>', 131 136 ), 132 137 'a dismissible notice with a type and additional classes' => array( … … 137 142 'additional_classes' => array( 'error', 'notice-alt' ), 138 143 ), 139 'expected' => '<div class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>',144 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-warning is-dismissible error notice-alt"><p>A dismissible warning notice with a type and additional classes.</p></div>', 140 145 ), 141 146 'a notice without paragraph wrapping' => array( … … 144 149 'paragraph_wrap' => false, 145 150 ), 146 'expected' => '<div class="notice"><span>A notice without paragraph wrapping.</span></div>',151 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><span>A notice without paragraph wrapping.</span></div>', 147 152 ), 148 153 'an unsafe type' => array( … … 151 156 'type' => '"><script>alert("Howdy,admin!");</script>', 152 157 ), 153 'expected' => '<div class="notice notice-"><script>alert("Howdy,admin!");</script>"><p>A notice with an unsafe type.</p></div>',158 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice notice-"><script>alert("Howdy,admin!");</script>"><p>A notice with an unsafe type.</p></div>', 154 159 ), 155 160 'an unsafe ID' => array( … … 158 163 'id' => '"><script>alert( "Howdy, admin!" );</script> <div class="notice', 159 164 ), 160 'expected' => '<div id=""><script>alert( "Howdy, admin!" );</script> <div class="notice" class="notice"><p>A notice with an unsafe ID.</p></div>',165 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id=""><script>alert( "Howdy, admin!" );</script> <div class="notice" class="notice"><p>A notice with an unsafe ID.</p></div>', 161 166 ), 162 167 'unsafe additional classes' => array( … … 165 170 'additional_classes' => array( '"><script>alert( "Howdy, admin!" );</script> <div class="notice' ), 166 171 ), 167 'expected' => '<div class="notice "><script>alert( "Howdy, admin!" );</script> <div class="notice"><p>A notice with unsafe additional classes.</p></div>',172 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice "><script>alert( "Howdy, admin!" );</script> <div class="notice"><p>A notice with unsafe additional classes.</p></div>', 168 173 ), 169 174 'a type that is not a string' => array( … … 172 177 'type' => array(), 173 178 ), 174 'expected' => '<div class="notice"><p>A notice with a type that is not a string.</p></div>',179 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with a type that is not a string.</p></div>', 175 180 ), 176 181 'a type with only empty space' => array( … … 179 184 'type' => " \t\r\n", 180 185 ), 181 'expected' => '<div class="notice"><p>A notice with a type with only empty space.</p></div>',186 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with a type with only empty space.</p></div>', 182 187 ), 183 188 'an ID that is not a string' => array( … … 186 191 'id' => array( 'message' ), 187 192 ), 188 'expected' => '<div class="notice"><p>A notice with an ID that is not a string.</p></div>',193 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with an ID that is not a string.</p></div>', 189 194 ), 190 195 'an ID with only empty space' => array( … … 193 198 'id' => " \t\r\n", 194 199 ), 195 'expected' => '<div class="notice"><p>A notice with an ID with only empty space.</p></div>',200 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with an ID with only empty space.</p></div>', 196 201 ), 197 202 'dismissible as a truthy value rather than (bool) true' => array( … … 200 205 'dismissible' => 1, 201 206 ), 202 'expected' => '<div class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>',207 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with dismissible as a truthy value rather than (bool) true.</p></div>', 203 208 ), 204 209 'additional classes that are not an array' => array( … … 207 212 'additional_classes' => 'class-1 class-2 class-3', 208 213 ), 209 'expected' => '<div class="notice"><p>A notice with additional classes that are not an array.</p></div>',214 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with additional classes that are not an array.</p></div>', 210 215 ), 211 216 'additional attribute with a value' => array( … … 214 219 'attributes' => array( 'aria-live' => 'assertive' ), 215 220 ), 216 'expected' => '<div class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>',221 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" aria-live="assertive"><p>A notice with an additional attribute with a value.</p></div>', 217 222 ), 218 223 'additional hidden attribute' => array( … … 221 226 'attributes' => array( 'hidden' => true ), 222 227 ), 223 'expected' => '<div class="notice" hidden><p>A notice with the hidden attribute.</p></div>',228 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" hidden><p>A notice with the hidden attribute.</p></div>', 224 229 ), 225 230 'additional attribute no associative keys' => array( … … 228 233 'attributes' => array( 'hidden' ), 229 234 ), 230 'expected' => '<div class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>',235 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" hidden><p>A notice with a boolean attribute without an associative key.</p></div>', 231 236 ), 232 237 'additional attribute with role' => array( … … 235 240 'attributes' => array( 'role' => 'alert' ), 236 241 ), 237 'expected' => '<div class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>',242 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" role="alert"><p>A notice with an additional attribute role.</p></div>', 238 243 ), 239 244 'multiple additional attributes' => array( … … 245 250 ), 246 251 ), 247 'expected' => '<div class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>',252 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" role="alert" data-test="-1"><p>A notice with multiple additional attributes.</p></div>', 248 253 ), 249 254 'data attribute with unsafe value' => array( … … 252 257 'attributes' => array( 'data-unsafe' => '<script>alert( "Howdy, admin!" );</script>' ), 253 258 ), 254 'expected' => '<div class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>',259 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice" data-unsafe="<script>alert( "Howdy, admin!" );</script>"><p>A notice with an additional attribute with an unsafe value.</p></div>', 255 260 ), 256 261 'multiple attributes with "role", invalid, data-*, numeric, and boolean' => array( … … 265 270 ), 266 271 ), 267 'expected' => '<div class="notice" role="alert" disabled="disabled" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>',272 'expected' => '<div id="wp-admin-notice-%%ID%%" class="notice" role="alert" disabled="disabled" data-name="my-name" data-id="1" hidden><p>A notice with multiple attributes with "role", invalid, "data-*", numeric, and boolean.</p></div>', 268 273 ), 269 274 'paragraph wrapping as a falsy value rather than (bool) false' => array( … … 272 277 'paragraph_wrap' => 0, 273 278 ), 274 'expected' => '<div class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>',279 'expected' => '<div data-id="wp-admin-notice-%%ID%%" id="wp-admin-notice-%%ID%%" class="notice"><p>A notice with paragraph wrapping as a falsy value rather than (bool) false.</p></div>', 275 280 ), 276 281 ); … … 286 291 */ 287 292 public function test_should_throw_doing_it_wrong_with_a_type_containing_spaces() { 288 $this->assertSame( 289 '<div class="notice notice-first second third fourth"><p>A type containing spaces.</p></div>', 293 // Replace placeholder %%ID%% in expected string, required for test isolation. 294 $expected = '<div class="notice notice-first second third fourth" id="wp-admin-notice-%%ID%%" data-id="wp-admin-notice-%%ID%%"><p>A type containing spaces.</p></div>'; 295 $next_id = array_last( explode( '-', wp_unique_prefixed_id( 'wp-admin-notice-' ) ) ); 296 ++$next_id; 297 $expected = str_replace( '%%ID%%', $next_id, $expected ); 298 299 $this->assertEqualHTML( 300 $expected, 290 301 wp_get_admin_notice( 291 302 'A type containing spaces.',
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)