Changeset 45873
- Timestamp:
- 08/22/2019 12:21:49 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/template.php
r45814 r45873 1815 1815 } 1816 1816 1817 if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ) ) ) { 1818 $details['type'] = 'notice-' . $details['type']; 1819 } 1820 1817 1821 $css_id = sprintf( 1818 1822 'setting-error-%s', 1819 sanitize_html_class( $details['code'] )1823 esc_attr( $details['code'] ) 1820 1824 ); 1821 1825 $css_class = sprintf( 1822 'notice notice-%s settings-error is-dismissible',1823 sanitize_html_class( $details['type'] )1826 'notice %s settings-error is-dismissible', 1827 esc_attr( $details['type'] ) 1824 1828 ); 1825 1829 -
trunk/tests/phpunit/tests/admin/includesTemplate.php
r42343 r45873 109 109 } 110 110 111 /** 112 * Test calling get_settings_errors() with variations on where it gets errors from. 113 * 114 * @ticket 42498 115 * @covers ::get_settings_errors() 116 * @global array $wp_settings_errors 117 */ 118 public function test_get_settings_errors_sources() { 119 global $wp_settings_errors; 120 121 $blogname_error = array( 122 'setting' => 'blogname', 123 'code' => 'blogname', 124 'message' => 'Capital P dangit!', 125 'type' => 'error', 126 ); 127 $blogdescription_error = array( 128 'setting' => 'blogdescription', 129 'code' => 'blogdescription', 130 'message' => 'Too short', 131 'type' => 'error', 132 ); 133 134 $wp_settings_errors = null; 135 $this->assertSame( array(), get_settings_errors( 'blogname' ) ); 136 137 // Test getting errors from transient. 138 $_GET['settings-updated'] = '1'; 139 set_transient( 'settings_errors', array( $blogname_error ) ); 140 $wp_settings_errors = null; 141 $this->assertSame( array( $blogname_error ), get_settings_errors( 'blogname' ) ); 142 143 // Test getting errors from transient and from global. 144 $_GET['settings-updated'] = '1'; 145 set_transient( 'settings_errors', array( $blogname_error ) ); 146 $wp_settings_errors = null; 147 add_settings_error( $blogdescription_error['setting'], $blogdescription_error['code'], $blogdescription_error['message'], $blogdescription_error['type'] ); 148 $this->assertEqualSets( array( $blogname_error, $blogdescription_error ), get_settings_errors() ); 149 150 $wp_settings_errors = null; 151 } 152 153 /** 154 * @ticket 44941 155 * @covers ::settings_errors() 156 * @global array $wp_settings_errors 157 * @dataProvider settings_errors_css_classes_provider 158 */ 159 public function test_settings_errors_css_classes( $type, $expected ) { 160 global $wp_settings_errors; 161 162 add_settings_error( 'foo', 'bar', 'Capital P dangit!', $type ); 163 164 ob_start(); 165 settings_errors(); 166 $output = ob_get_clean(); 167 168 $wp_settings_errors = null; 169 170 $expected = sprintf( 'notice %s settings-error is-dismissible', $expected ); 171 172 $this->assertContains( $expected, $output ); 173 $this->assertNotContains( 'notice-notice-', $output ); 174 } 175 176 public function settings_errors_css_classes_provider() { 177 return array( 178 array( 'error', 'notice-error' ), 179 array( 'success', 'notice-success' ), 180 array( 'warning', 'notice-warning' ), 181 array( 'info', 'notice-info' ), 182 array( 'updated', 'notice-success' ), 183 array( 'notice-error', 'notice-error' ), 184 array( 'error my-own-css-class hello world', 'error my-own-css-class hello world' ), 185 ); 186 } 187 111 188 } -
trunk/tests/phpunit/tests/option/sanitize-option.php
r42636 r45873 159 159 } 160 160 161 /**162 * Test calling get_settings_errors() with variations on where it gets errors from.163 *164 * @ticket 42498165 * @covers ::get_settings_errors()166 * @global array $wp_settings_errors167 */168 public function test_get_settings_errors_sources() {169 global $wp_settings_errors;170 171 $blogname_error = array(172 'setting' => 'blogname',173 'code' => 'blogname',174 'message' => 'Capital P dangit!',175 'type' => 'error',176 );177 $blogdescription_error = array(178 'setting' => 'blogdescription',179 'code' => 'blogdescription',180 'message' => 'Too short',181 'type' => 'error',182 );183 184 $wp_settings_errors = null;185 $this->assertSame( array(), get_settings_errors( 'blogname' ) );186 187 // Test getting errors from transient.188 $_GET['settings-updated'] = '1';189 set_transient( 'settings_errors', array( $blogname_error ) );190 $wp_settings_errors = null;191 $this->assertSame( array( $blogname_error ), get_settings_errors( 'blogname' ) );192 193 // Test getting errors from transient and from global.194 $_GET['settings-updated'] = '1';195 set_transient( 'settings_errors', array( $blogname_error ) );196 $wp_settings_errors = null;197 add_settings_error( $blogdescription_error['setting'], $blogdescription_error['code'], $blogdescription_error['message'], $blogdescription_error['type'] );198 $this->assertEqualSets( array( $blogname_error, $blogdescription_error ), get_settings_errors() );199 200 $wp_settings_errors = null;201 }202 161 }
Note: See TracChangeset
for help on using the changeset viewer.