Ticket #53363: 53363-GH-1519-move-incorrectly-placed-test.patch
File 53363-GH-1519-move-incorrectly-placed-test.patch, 13.8 KB (added by , 3 years ago) |
---|
-
tests/phpunit/includes/bootstrap.php
From 139dc0d44c2735edd442322163cc4be1dcc7448c Mon Sep 17 00:00:00 2001 From: jrfnl <jrfnl@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:03:16 +0200 Subject: [PATCH] QA: move incorrectly placed test file The `Block_Supported_Styles_Test` class is not a `TestCase` to be extended, but an actual concrete test class. Note: the tests as-is are failing. This should be fixed before this can be merged. Includes minor CS fixes and adding the `$message` parameter to assertions to aid in debugging. * Block_Supported_Styles_Test: update the style related test to current expected format * Block_Supported_Styles_Test: remove two outdated tests The functionality which these tests were testing is no longer available in this manner, so these tests are redundant. --- tests/phpunit/includes/bootstrap.php | 1 - .../blocks/block-supported-styles.php} | 176 +++++++----------- 2 files changed, 67 insertions(+), 110 deletions(-) rename tests/phpunit/{includes/testcase-block-supports.php => tests/blocks/block-supported-styles.php} (86%) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index ce50a89534..367d445790 100644
a b require __DIR__ . '/testcase-rest-controller.php'; 203 203 require __DIR__ . '/testcase-rest-post-type-controller.php'; 204 204 require __DIR__ . '/testcase-xmlrpc.php'; 205 205 require __DIR__ . '/testcase-ajax.php'; 206 require __DIR__ . '/testcase-block-supports.php';207 206 require __DIR__ . '/testcase-canonical.php'; 208 207 require __DIR__ . '/testcase-xml.php'; 209 208 require __DIR__ . '/exceptions.php'; -
.php
diff --git a/tests/phpunit/includes/testcase-block-supports.php b/tests/phpunit/tests/blocks/block-supported-styles.php similarity index 86% rename from tests/phpunit/includes/testcase-block-supports.php rename to tests/phpunit/tests/blocks/block-supported-styles.php index 981bfcd190..faf26e59c4 100644
old new 1 1 <?php 2 /** 3 * Block Tests 4 * 5 * @package WordPress 6 * @subpackage Blocks 7 * @since 5.6.0 8 */ 9 2 10 /** 3 11 * Test block supported styles. 4 12 * 5 * @ package WordPress6 * @subpackage UnitTests7 * @ since 5.6.013 * @since 5.6.0 14 * 15 * @group blocks 8 16 */ 9 17 class Block_Supported_Styles_Test extends WP_UnitTestCase { 10 18 19 /** 20 * Block content to test with (i.e. what's wrapped by the block wrapper `<div />`). 21 * 22 * @var string 23 */ 24 const BLOCK_CONTENT = ' 25 <p data-image-description="<p>Test!</p>">Test</p> 26 <p>äöü</p> 27 <p>ß</p> 28 <p>系の家庭に</p> 29 <p>Example <p>Test!</p></p> 30 '; 31 11 32 /** 12 33 * Registered block names. 13 34 * … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 72 93 return substr( $split_arr, 0, $end_index ); // String between first '>' and last '<'. 73 94 } 74 95 75 /**76 * Block content to test with (i.e. what's wrapped by the block wrapper `<div />`).77 *78 * @var string79 */80 const BLOCK_CONTENT = '81 <p data-image-description="<p>Test!</p>">Test</p>82 <p>äöü</p>83 <p>ß</p>84 <p>系の家庭に</p>85 <p>Example <p>Test!</p></p>86 ';87 88 96 /** 89 97 * Returns the rendered output for the current block. 90 98 * … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 116 124 $class_list = $this->get_attribute_from_block( 'class', $styled_block ); 117 125 $style_list = $this->get_attribute_from_block( 'style', $styled_block ); 118 126 119 $this->assertSame( $expected_classes, $class_list );120 $this->assertSame( $expected_styles, $style_list );127 $this->assertSame( $expected_classes, $class_list, 'Class list does not match expected classes' ); 128 $this->assertSame( $expected_styles, $style_list, 'Style list does not match expected styles' ); 121 129 } 122 130 123 131 /** … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 137 145 $class_list = $this->get_attribute_from_block( 'class', $styled_block ); 138 146 $style_list = $this->get_attribute_from_block( 'style', $styled_block ); 139 147 140 $this->assertSame( self::BLOCK_CONTENT, $content );148 $this->assertSame( self::BLOCK_CONTENT, $content, 'Block content does not match expected content' ); 141 149 $this->assertSameSets( 142 150 explode( ' ', $expected_classes ), 143 explode( ' ', $class_list ) 151 explode( ' ', $class_list ), 152 'Class list does not match expected classes' 144 153 ); 145 154 $this->assertSame( 146 155 array_map( 'trim', explode( ';', $expected_styles ) ), 147 array_map( 'trim', explode( ';', $style_list ) ) 156 array_map( 'trim', explode( ';', $style_list ) ), 157 'Style list does not match expected styles' 148 158 ); 149 159 } 150 160 151 161 /** 152 162 * Tests color support for named color support for named colors. 153 163 */ 154 function test_named_color_support() {164 public function test_named_color_support() { 155 165 $block_type_settings = array( 156 166 'attributes' => array(), 157 167 'supports' => array( … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 183 193 /** 184 194 * Tests color support for custom colors. 185 195 */ 186 function test_custom_color_support() {196 public function test_custom_color_support() { 187 197 $block_type_settings = array( 188 198 'attributes' => array(), 189 199 'supports' => array( … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 217 227 $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles ); 218 228 } 219 229 220 /**221 * Tests link color support for named colors.222 */223 function test_named_link_color_support() {224 $block_type_settings = array(225 'attributes' => array(),226 'supports' => array(227 'color' => array(228 'link' => true,229 ),230 ),231 'render_callback' => true,232 );233 $this->register_block_type( 'core/example', $block_type_settings );234 235 $block = array(236 'blockName' => 'core/example',237 'attrs' => array(238 'style' => array( 'color' => array( 'link' => 'var:preset|color|red' ) ),239 ),240 'innerBlock' => array(),241 'innerContent' => array(),242 'innerHTML' => array(),243 );244 245 $expected_classes = 'foo-bar-class wp-block-example has-link-color';246 $expected_styles = 'test: style; --wp--style--color--link: var(--wp--preset--color--red);';247 248 $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );249 }250 251 /**252 * Tests link color support for custom colors.253 */254 function test_custom_link_color_support() {255 $block_type_settings = array(256 'attributes' => array(),257 'supports' => array(258 'color' => array(259 'link' => true,260 ),261 ),262 'render_callback' => true,263 );264 $this->register_block_type( 'core/example', $block_type_settings );265 266 $block = array(267 'blockName' => 'core/example',268 'attrs' => array(269 'style' => array( 'color' => array( 'link' => '#fff' ) ),270 ),271 'innerBlock' => array(),272 'innerContent' => array(),273 'innerHTML' => array(),274 );275 276 $expected_classes = 'foo-bar-class wp-block-example has-link-color';277 $expected_styles = 'test: style; --wp--style--color--link: #fff;';278 279 $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );280 }281 282 230 /** 283 231 * Tests gradient color support for named gradients. 284 232 */ 285 function test_named_gradient_support() {233 public function test_named_gradient_support() { 286 234 $block_type_settings = array( 287 235 'attributes' => array(), 288 236 'supports' => array( … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 313 261 /** 314 262 * Tests gradient color support for custom gradients. 315 263 */ 316 function test_custom_gradient_support() {264 public function test_custom_gradient_support() { 317 265 $block_type_settings = array( 318 266 'attributes' => array(), 319 267 'supports' => array( … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 344 292 /** 345 293 * Tests that style attributes for colors are not applied without the support flag. 346 294 */ 347 function test_color_unsupported() {295 public function test_color_unsupported() { 348 296 $block_type_settings = array( 349 297 'attributes' => array(), 350 298 'supports' => array(), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 380 328 /** 381 329 * Tests support for named font sizes. 382 330 */ 383 function test_named_font_size() {331 public function test_named_font_size() { 384 332 $block_type_settings = array( 385 333 'attributes' => array(), 386 334 'supports' => array( 387 'fontSize' => true, 335 'typography' => array( 336 'fontSize' => true, 337 ), 388 338 ), 389 339 ); 390 340 $this->register_block_type( 'core/example', $block_type_settings ); … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 408 358 /** 409 359 * Tests support for custom font sizes. 410 360 */ 411 function test_custom_font_size() {361 public function test_custom_font_size() { 412 362 $block_type_settings = array( 413 363 'attributes' => array(), 414 364 'supports' => array( 415 'fontSize' => true, 365 'typography' => array( 366 'fontSize' => true, 367 ), 416 368 ), 417 369 ); 418 370 $this->register_block_type( 'core/example', $block_type_settings ); … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 420 372 $block = array( 421 373 'blockName' => 'core/example', 422 374 'attrs' => array( 423 'style' => array( 'typography' => array( 'fontSize' => '10 ' ) ),375 'style' => array( 'typography' => array( 'fontSize' => '10px' ) ), 424 376 ), 425 377 'innerBlock' => array(), 426 378 'innerContent' => array(), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 436 388 /** 437 389 * Tests that font size attributes are not applied without support flag. 438 390 */ 439 function test_font_size_unsupported() {391 public function test_font_size_unsupported() { 440 392 $block_type_settings = array( 441 393 'attributes' => array(), 442 394 'supports' => array(), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 463 415 /** 464 416 * Tests line height support. 465 417 */ 466 function test_line_height() {418 public function test_line_height() { 467 419 $block_type_settings = array( 468 420 'attributes' => array(), 469 421 'supports' => array( 470 'lineHeight' => true, 422 'typography' => array( 423 'lineHeight' => true, 424 ), 471 425 ), 472 426 ); 473 427 $this->register_block_type( 'core/example', $block_type_settings ); … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 491 445 /** 492 446 * Tests line height not applied without support flag. 493 447 */ 494 function test_line_height_unsupported() {448 public function test_line_height_unsupported() { 495 449 $block_type_settings = array( 496 450 'attributes' => array(), 497 451 'supports' => array(), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 517 471 /** 518 472 * Tests support for block alignment. 519 473 */ 520 function test_block_alignment() {474 public function test_block_alignment() { 521 475 $block_type_settings = array( 522 476 'attributes' => array(), 523 477 'supports' => array( … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 545 499 /** 546 500 * Tests block alignment requires support to be added. 547 501 */ 548 function test_block_alignment_unsupported() {502 public function test_block_alignment_unsupported() { 549 503 $block_type_settings = array( 550 504 'attributes' => array(), 551 505 'supports' => array(), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 571 525 /** 572 526 * Tests all support flags together to ensure they work together as expected. 573 527 */ 574 function test_all_supported() {528 public function test_all_supported() { 575 529 $block_type_settings = array( 576 530 'attributes' => array(), 577 531 'supports' => array( … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 579 533 'gradients' => true, 580 534 'link' => true, 581 535 ), 582 'fontSize' => true, 583 'lineHeight' => true, 536 'typography' => array( 537 'fontSize' => true, 538 'lineHeight' => true, 539 ), 584 540 'align' => true, 585 541 ), 586 542 ); … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 598 554 ), 599 555 'typography' => array( 600 556 'lineHeight' => '20', 601 'fontSize' => '10 ',557 'fontSize' => '10px', 602 558 ), 603 559 ), 604 560 ), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 617 573 * Tests that only styles for the supported flag are added. 618 574 * Verify one support enabled does not imply multiple supports enabled. 619 575 */ 620 function test_one_supported() {576 public function test_one_supported() { 621 577 $block_type_settings = array( 622 578 'attributes' => array(), 623 579 'supports' => array( 624 'fontSize' => true, 580 'typography' => array( 581 'fontSize' => true, 582 ), 625 583 ), 626 584 ); 627 585 $this->register_block_type( 'core/example', $block_type_settings ); … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 639 597 ), 640 598 'typography' => array( 641 599 'lineHeight' => '20', 642 'fontSize' => '10 ',600 'fontSize' => '10px', 643 601 ), 644 602 ), 645 603 ), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 657 615 /** 658 616 * Tests custom classname server-side block support. 659 617 */ 660 function test_custom_classnames_support() {618 public function test_custom_classnames_support() { 661 619 $block_type_settings = array( 662 620 'attributes' => array(), 663 621 'supports' => array(), … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 683 641 /** 684 642 * Tests custom classname server-side block support opt-out. 685 643 */ 686 function test_custom_classnames_support_opt_out() {644 public function test_custom_classnames_support_opt_out() { 687 645 $block_type_settings = array( 688 646 'attributes' => array(), 689 647 'supports' => array( … … class Block_Supported_Styles_Test extends WP_UnitTestCase { 711 669 /** 712 670 * Tests generated classname server-side block support opt-out. 713 671 */ 714 function test_generatted_classnames_support_opt_out() {672 public function test_generated_classnames_support_opt_out() { 715 673 $block_type_settings = array( 716 674 'attributes' => array(), 717 675 'supports' => array(