Changeset 45873 for trunk/tests/phpunit/tests/admin/includesTemplate.php
- Timestamp:
- 08/22/2019 12:21:49 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.