From b9b464de8a4aeb333c2ca6191df5db5c10ca01ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=83=C2=B3=C3=85=E2=80=9Akowski?= Date: Mon, 24 May 2021 06:26:00 +0000 Subject: [PATCH] Editor: Add missing unit tests for `block_has_support` Follow-up for [50761]. Props ntsekouras. Fixes #53257. See #52991. git-svn-id: https://develop.svn.wordpress.org/trunk@50955 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/blocks/block.php | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/phpunit/tests/blocks/block.php b/tests/phpunit/tests/blocks/block.php index 74c5143059..e74516fcd5 100644 --- a/tests/phpunit/tests/blocks/block.php +++ b/tests/phpunit/tests/blocks/block.php @@ -567,4 +567,65 @@ class WP_Block_Test extends WP_UnitTestCase { ) ); } + + /** + * @ticket 52991 + */ + public function test_block_has_support() { + $this->registry->register( + 'core/example', + array( + 'supports' => array( + 'align' => array( 'wide', 'full' ), + 'fontSize' => true, + 'color' => array( + 'link' => true, + 'gradient' => false, + ), + ), + ) + ); + $block_type = $this->registry->get_registered( 'core/example' ); + $align_support = block_has_support( $block_type, array( 'align' ) ); + $this->assertTrue( $align_support ); + $gradient_support = block_has_support( $block_type, array( 'color', 'gradient' ) ); + $this->assertFalse( $gradient_support ); + $link_support = block_has_support( $block_type, array( 'color', 'link' ), false ); + $this->assertTrue( $link_support ); + $text_support = block_has_support( $block_type, array( 'color', 'text' ) ); + $this->assertFalse( $text_support ); + $font_nested = block_has_support( $block_type, array( 'fontSize', 'nested' ) ); + $this->assertFalse( $font_nested ); + } + + /** + * @ticket 52991 + */ + public function test_block_has_support_no_supports() { + $this->registry->register( 'core/example', array() ); + $block_type = $this->registry->get_registered( 'core/example' ); + $has_support = block_has_support( $block_type, array( 'color' ) ); + $this->assertFalse( $has_support ); + } + + /** + * @ticket 52991 + */ + public function test_block_has_support_provided_defaults() { + $this->registry->register( + 'core/example', + array( + 'supports' => array( + 'color' => array( + 'gradient' => false, + ), + ), + ) + ); + $block_type = $this->registry->get_registered( 'core/example' ); + $align_support = block_has_support( $block_type, array( 'align' ), true ); + $this->assertTrue( $align_support ); + $gradient_support = block_has_support( $block_type, array( 'color', 'gradient' ), true ); + $this->assertFalse( $gradient_support ); + } }