Changeset 58136
- Timestamp:
- 05/12/2024 03:54:33 PM (5 months ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 2 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 * -
trunk/tests/phpunit/tests/template.php
r56635 r58136 454 454 'singular.php', 455 455 ) 456 );457 }458 459 /**460 * @ticket 17851461 * @covers ::add_settings_section462 */463 public function test_add_settings_section() {464 add_settings_section( 'test-section', 'Section title', '__return_false', 'test-page' );465 466 global $wp_settings_sections;467 $this->assertIsArray( $wp_settings_sections, 'List of sections is not initialized.' );468 $this->assertArrayHasKey( 'test-page', $wp_settings_sections, 'List of sections for the test page has not been added to sections list.' );469 $this->assertIsArray( $wp_settings_sections['test-page'], 'List of sections for the test page is not initialized.' );470 $this->assertArrayHasKey( 'test-section', $wp_settings_sections['test-page'], 'Test section has not been added to the list of sections for the test page.' );471 472 $this->assertEqualSetsWithIndex(473 array(474 'id' => 'test-section',475 'title' => 'Section title',476 'callback' => '__return_false',477 'before_section' => '',478 'after_section' => '',479 'section_class' => '',480 ),481 $wp_settings_sections['test-page']['test-section'],482 'Test section data does not match the expected dataset.'483 );484 }485 486 /**487 * @ticket 17851488 *489 * @param array $extra_args Extra arguments to pass to function `add_settings_section()`.490 * @param array $expected_section_data Expected set of section data.491 * @param string $expected_before_section_html Expected HTML markup to be rendered before the settings section.492 * @param string $expected_after_section_html Expected HTML markup to be rendered after the settings section.493 *494 * @covers ::add_settings_section495 * @covers ::do_settings_sections496 *497 * @dataProvider data_extra_args_for_add_settings_section498 */499 public function test_add_settings_section_with_extra_args( $extra_args, $expected_section_data, $expected_before_section_html, $expected_after_section_html ) {500 add_settings_section( 'test-section', 'Section title', '__return_false', 'test-page', $extra_args );501 add_settings_field( 'test-field', 'Field title', '__return_false', 'test-page', 'test-section' );502 503 global $wp_settings_sections;504 $this->assertIsArray( $wp_settings_sections, 'List of sections is not initialized.' );505 $this->assertArrayHasKey( 'test-page', $wp_settings_sections, 'List of sections for the test page has not been added to sections list.' );506 $this->assertIsArray( $wp_settings_sections['test-page'], 'List of sections for the test page is not initialized.' );507 $this->assertArrayHasKey( 'test-section', $wp_settings_sections['test-page'], 'Test section has not been added to the list of sections for the test page.' );508 509 $this->assertEqualSetsWithIndex(510 $expected_section_data,511 $wp_settings_sections['test-page']['test-section'],512 'Test section data does not match the expected dataset.'513 );514 515 ob_start();516 do_settings_sections( 'test-page' );517 $output = ob_get_clean();518 519 $this->assertStringContainsString( $expected_before_section_html, $output, 'Test page output does not contain the custom markup to be placed before the section.' );520 $this->assertStringContainsString( $expected_after_section_html, $output, 'Test page output does not contain the custom markup to be placed after the section.' );521 }522 523 /**524 * Data provider for `test_add_settings_section_with_extra_args()`.525 *526 * @return array527 */528 public function data_extra_args_for_add_settings_section() {529 return array(530 'class placeholder section_class present' => array(531 array(532 'before_section' => '<div class="%s">',533 'after_section' => '</div><!-- end of the test section -->',534 'section_class' => 'test-section-wrap',535 ),536 array(537 'id' => 'test-section',538 'title' => 'Section title',539 'callback' => '__return_false',540 'before_section' => '<div class="%s">',541 'after_section' => '</div><!-- end of the test section -->',542 'section_class' => 'test-section-wrap',543 ),544 '<div class="test-section-wrap">',545 '</div><!-- end of the test section -->',546 ),547 'missing class placeholder section_class' => array(548 array(549 'before_section' => '<div class="testing-section-wrapper">',550 'after_section' => '</div><!-- end of the test section -->',551 'section_class' => 'test-section-wrap',552 ),553 array(554 'id' => 'test-section',555 'title' => 'Section title',556 'callback' => '__return_false',557 'before_section' => '<div class="testing-section-wrapper">',558 'after_section' => '</div><!-- end of the test section -->',559 'section_class' => 'test-section-wrap',560 ),561 '<div class="testing-section-wrapper">',562 '</div><!-- end of the test section -->',563 ),564 'empty section_class' => array(565 array(566 'before_section' => '<div class="test-section-container">',567 'after_section' => '</div><!-- end of the test section -->',568 'section_class' => '',569 ),570 array(571 'id' => 'test-section',572 'title' => 'Section title',573 'callback' => '__return_false',574 'before_section' => '<div class="test-section-container">',575 'after_section' => '</div><!-- end of the test section -->',576 'section_class' => '',577 ),578 '<div class="test-section-container">',579 '</div><!-- end of the test section -->',580 ),581 'section_class missing' => array(582 array(583 'before_section' => '<div class="wp-whitelabel-section">',584 'after_section' => '</div><!-- end of the test section -->',585 ),586 array(587 'id' => 'test-section',588 'title' => 'Section title',589 'callback' => '__return_false',590 'before_section' => '<div class="wp-whitelabel-section">',591 'after_section' => '</div><!-- end of the test section -->',592 'section_class' => '',593 ),594 '<div class="wp-whitelabel-section">',595 '</div><!-- end of the test section -->',596 ),597 'disallowed tag in before_section' => array(598 array(599 'before_section' => '<div class="video-settings-section"><iframe src="https://www.wordpress.org/" />',600 'after_section' => '</div><!-- end of the test section -->',601 ),602 array(603 'id' => 'test-section',604 'title' => 'Section title',605 'callback' => '__return_false',606 'before_section' => '<div class="video-settings-section"><iframe src="https://www.wordpress.org/" />',607 'after_section' => '</div><!-- end of the test section -->',608 'section_class' => '',609 ),610 '<div class="video-settings-section">',611 '</div><!-- end of the test section -->',612 ),613 'disallowed tag in after_section' => array(614 array(615 'before_section' => '<div class="video-settings-section">',616 'after_section' => '</div><iframe src="https://www.wordpress.org/" />',617 ),618 array(619 'id' => 'test-section',620 'title' => 'Section title',621 'callback' => '__return_false',622 'before_section' => '<div class="video-settings-section">',623 'after_section' => '</div><iframe src="https://www.wordpress.org/" />',624 'section_class' => '',625 ),626 '<div class="video-settings-section">',627 '</div>',628 ),629 456 ); 630 457 }
Note: See TracChangeset
for help on using the changeset viewer.