Changeset 58136 for trunk/tests/phpunit/tests/admin/includesTemplate.php
- Timestamp:
- 05/12/2024 03:54:33 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/admin/includesTemplate.php
r56547 r58136 178 178 179 179 /** 180 * @ticket 17851 181 * @covers ::add_settings_section 182 */ 183 public function test_add_settings_section() { 184 add_settings_section( 'test-section', 'Section title', '__return_false', 'test-page' ); 185 186 global $wp_settings_sections; 187 $this->assertIsArray( $wp_settings_sections, 'List of sections is not initialized.' ); 188 $this->assertArrayHasKey( 'test-page', $wp_settings_sections, 'List of sections for the test page has not been added to sections list.' ); 189 $this->assertIsArray( $wp_settings_sections['test-page'], 'List of sections for the test page is not initialized.' ); 190 $this->assertArrayHasKey( 'test-section', $wp_settings_sections['test-page'], 'Test section has not been added to the list of sections for the test page.' ); 191 192 $this->assertEqualSetsWithIndex( 193 array( 194 'id' => 'test-section', 195 'title' => 'Section title', 196 'callback' => '__return_false', 197 'before_section' => '', 198 'after_section' => '', 199 'section_class' => '', 200 ), 201 $wp_settings_sections['test-page']['test-section'], 202 'Test section data does not match the expected dataset.' 203 ); 204 } 205 206 /** 207 * @ticket 17851 208 * 209 * @param array $extra_args Extra arguments to pass to function `add_settings_section()`. 210 * @param array $expected_section_data Expected set of section data. 211 * @param string $expected_before_section_html Expected HTML markup to be rendered before the settings section. 212 * @param string $expected_after_section_html Expected HTML markup to be rendered after the settings section. 213 * 214 * @covers ::add_settings_section 215 * @covers ::do_settings_sections 216 * 217 * @dataProvider data_extra_args_for_add_settings_section 218 */ 219 public function test_add_settings_section_with_extra_args( $extra_args, $expected_section_data, $expected_before_section_html, $expected_after_section_html ) { 220 add_settings_section( 'test-section', 'Section title', '__return_false', 'test-page', $extra_args ); 221 add_settings_field( 'test-field', 'Field title', '__return_false', 'test-page', 'test-section' ); 222 223 global $wp_settings_sections; 224 $this->assertIsArray( $wp_settings_sections, 'List of sections is not initialized.' ); 225 $this->assertArrayHasKey( 'test-page', $wp_settings_sections, 'List of sections for the test page has not been added to sections list.' ); 226 $this->assertIsArray( $wp_settings_sections['test-page'], 'List of sections for the test page is not initialized.' ); 227 $this->assertArrayHasKey( 'test-section', $wp_settings_sections['test-page'], 'Test section has not been added to the list of sections for the test page.' ); 228 229 $this->assertEqualSetsWithIndex( 230 $expected_section_data, 231 $wp_settings_sections['test-page']['test-section'], 232 'Test section data does not match the expected dataset.' 233 ); 234 235 ob_start(); 236 do_settings_sections( 'test-page' ); 237 $output = ob_get_clean(); 238 239 $this->assertStringContainsString( $expected_before_section_html, $output, 'Test page output does not contain the custom markup to be placed before the section.' ); 240 $this->assertStringContainsString( $expected_after_section_html, $output, 'Test page output does not contain the custom markup to be placed after the section.' ); 241 } 242 243 /** 244 * Data provider for `test_add_settings_section_with_extra_args()`. 245 * 246 * @return array 247 */ 248 public function data_extra_args_for_add_settings_section() { 249 return array( 250 'class placeholder section_class present' => array( 251 array( 252 'before_section' => '<div class="%s">', 253 'after_section' => '</div><!-- end of the test section -->', 254 'section_class' => 'test-section-wrap', 255 ), 256 array( 257 'id' => 'test-section', 258 'title' => 'Section title', 259 'callback' => '__return_false', 260 'before_section' => '<div class="%s">', 261 'after_section' => '</div><!-- end of the test section -->', 262 'section_class' => 'test-section-wrap', 263 ), 264 '<div class="test-section-wrap">', 265 '</div><!-- end of the test section -->', 266 ), 267 'missing class placeholder section_class' => array( 268 array( 269 'before_section' => '<div class="testing-section-wrapper">', 270 'after_section' => '</div><!-- end of the test section -->', 271 'section_class' => 'test-section-wrap', 272 ), 273 array( 274 'id' => 'test-section', 275 'title' => 'Section title', 276 'callback' => '__return_false', 277 'before_section' => '<div class="testing-section-wrapper">', 278 'after_section' => '</div><!-- end of the test section -->', 279 'section_class' => 'test-section-wrap', 280 ), 281 '<div class="testing-section-wrapper">', 282 '</div><!-- end of the test section -->', 283 ), 284 'empty section_class' => array( 285 array( 286 'before_section' => '<div class="test-section-container">', 287 'after_section' => '</div><!-- end of the test section -->', 288 'section_class' => '', 289 ), 290 array( 291 'id' => 'test-section', 292 'title' => 'Section title', 293 'callback' => '__return_false', 294 'before_section' => '<div class="test-section-container">', 295 'after_section' => '</div><!-- end of the test section -->', 296 'section_class' => '', 297 ), 298 '<div class="test-section-container">', 299 '</div><!-- end of the test section -->', 300 ), 301 'section_class missing' => array( 302 array( 303 'before_section' => '<div class="wp-whitelabel-section">', 304 'after_section' => '</div><!-- end of the test section -->', 305 ), 306 array( 307 'id' => 'test-section', 308 'title' => 'Section title', 309 'callback' => '__return_false', 310 'before_section' => '<div class="wp-whitelabel-section">', 311 'after_section' => '</div><!-- end of the test section -->', 312 'section_class' => '', 313 ), 314 '<div class="wp-whitelabel-section">', 315 '</div><!-- end of the test section -->', 316 ), 317 'disallowed tag in before_section' => array( 318 array( 319 'before_section' => '<div class="video-settings-section"><iframe src="https://www.wordpress.org/" />', 320 'after_section' => '</div><!-- end of the test section -->', 321 ), 322 array( 323 'id' => 'test-section', 324 'title' => 'Section title', 325 'callback' => '__return_false', 326 'before_section' => '<div class="video-settings-section"><iframe src="https://www.wordpress.org/" />', 327 'after_section' => '</div><!-- end of the test section -->', 328 'section_class' => '', 329 ), 330 '<div class="video-settings-section">', 331 '</div><!-- end of the test section -->', 332 ), 333 'disallowed tag in after_section' => array( 334 array( 335 'before_section' => '<div class="video-settings-section">', 336 'after_section' => '</div><iframe src="https://www.wordpress.org/" />', 337 ), 338 array( 339 'id' => 'test-section', 340 'title' => 'Section title', 341 'callback' => '__return_false', 342 'before_section' => '<div class="video-settings-section">', 343 'after_section' => '</div><iframe src="https://www.wordpress.org/" />', 344 'section_class' => '', 345 ), 346 '<div class="video-settings-section">', 347 '</div>', 348 ), 349 ); 350 } 351 352 /** 180 353 * Test calling get_settings_errors() with variations on where it gets errors from. 181 354 *
Note:
See TracChangeset
for help on using the changeset viewer.