mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Let's unregister the block in the tear_down method. The block will be unregistered even if the test fails. Props ramonopoly, antonvlasenko. See #55505. Follow-up [53085], [53076]. git-svn-id: https://develop.svn.wordpress.org/trunk@53153 602fd350-edb4-49c9-b593-d223f7449a82
235 lines
6.0 KiB
PHP
235 lines
6.0 KiB
PHP
<?php
|
|
/**
|
|
* @group block-supports
|
|
*/
|
|
class Tests_Block_Supports_Typography extends WP_UnitTestCase {
|
|
/**
|
|
* @var string|null
|
|
*/
|
|
private $test_block_name;
|
|
|
|
function set_up() {
|
|
parent::set_up();
|
|
$this->test_block_name = null;
|
|
}
|
|
|
|
function tear_down() {
|
|
unregister_block_type( $this->test_block_name );
|
|
$this->test_block_name = null;
|
|
parent::set_up();
|
|
}
|
|
|
|
/**
|
|
* @ticket 54337
|
|
*
|
|
* @covers ::wp_apply_typography_support
|
|
*/
|
|
function test_font_size_slug_with_numbers_is_kebab_cased_properly() {
|
|
$this->test_block_name = 'test/font-size-slug-with-numbers';
|
|
register_block_type(
|
|
$this->test_block_name,
|
|
array(
|
|
'api_version' => 2,
|
|
'attributes' => array(
|
|
'fontSize' => array(
|
|
'type' => 'string',
|
|
),
|
|
),
|
|
'supports' => array(
|
|
'typography' => array(
|
|
'fontSize' => true,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
$registry = WP_Block_Type_Registry::get_instance();
|
|
$block_type = $registry->get_registered( $this->test_block_name );
|
|
|
|
$block_atts = array( 'fontSize' => 'h1' );
|
|
|
|
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
|
$expected = array( 'class' => 'has-h-1-font-size' );
|
|
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
/**
|
|
* @ticket 54337
|
|
*
|
|
* @covers ::wp_apply_typography_support
|
|
*/
|
|
function test_font_family_with_legacy_inline_styles_using_a_value() {
|
|
$this->test_block_name = 'test/font-family-with-inline-styles-using-value';
|
|
register_block_type(
|
|
$this->test_block_name,
|
|
array(
|
|
'api_version' => 2,
|
|
'attributes' => array(
|
|
'style' => array(
|
|
'type' => 'object',
|
|
),
|
|
),
|
|
'supports' => array(
|
|
'typography' => array(
|
|
'__experimentalFontFamily' => true,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
$registry = WP_Block_Type_Registry::get_instance();
|
|
$block_type = $registry->get_registered( $this->test_block_name );
|
|
$block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'serif' ) ) );
|
|
|
|
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
|
$expected = array( 'style' => 'font-family: serif;' );
|
|
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
|
|
/**
|
|
* @ticket 55505
|
|
*
|
|
* @covers ::wp_apply_typography_support
|
|
*/
|
|
function test_typography_with_skipped_serialization_block_supports() {
|
|
$this->test_block_name = 'test/typography-with-skipped-serialization-block-supports';
|
|
register_block_type(
|
|
$this->test_block_name,
|
|
array(
|
|
'api_version' => 2,
|
|
'attributes' => array(
|
|
'style' => array(
|
|
'type' => 'object',
|
|
),
|
|
),
|
|
'supports' => array(
|
|
'typography' => array(
|
|
'fontSize' => true,
|
|
'lineHeight' => true,
|
|
'__experimentalFontFamily' => true,
|
|
'__experimentalLetterSpacing' => true,
|
|
'__experimentalSkipSerialization' => true,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
$registry = WP_Block_Type_Registry::get_instance();
|
|
$block_type = $registry->get_registered( $this->test_block_name );
|
|
$block_atts = array(
|
|
'style' => array(
|
|
'typography' => array(
|
|
'fontSize' => 'serif',
|
|
'lineHeight' => 'serif',
|
|
'fontFamily' => '22px',
|
|
'letterSpacing' => '22px',
|
|
),
|
|
),
|
|
);
|
|
|
|
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
|
$expected = array();
|
|
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
|
|
/**
|
|
* @ticket 55505
|
|
*
|
|
* @covers ::wp_apply_typography_support
|
|
*/
|
|
function test_letter_spacing_with_individual_skipped_serialization_block_supports() {
|
|
$this->test_block_name = 'test/letter-spacing-with-individua-skipped-serialization-block-supports';
|
|
register_block_type(
|
|
$this->test_block_name,
|
|
array(
|
|
'api_version' => 2,
|
|
'attributes' => array(
|
|
'style' => array(
|
|
'type' => 'object',
|
|
),
|
|
),
|
|
'supports' => array(
|
|
'typography' => array(
|
|
'__experimentalLetterSpacing' => true,
|
|
'__experimentalSkipSerialization' => array(
|
|
'letterSpacing',
|
|
),
|
|
),
|
|
),
|
|
)
|
|
);
|
|
$registry = WP_Block_Type_Registry::get_instance();
|
|
$block_type = $registry->get_registered( $this->test_block_name );
|
|
$block_atts = array( 'style' => array( 'typography' => array( 'letterSpacing' => '22px' ) ) );
|
|
|
|
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
|
$expected = array();
|
|
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
/**
|
|
* @ticket 54337
|
|
*
|
|
* @covers ::wp_apply_typography_support
|
|
*/
|
|
function test_font_family_with_legacy_inline_styles_using_a_css_var() {
|
|
$this->test_block_name = 'test/font-family-with-inline-styles-using-css-var';
|
|
register_block_type(
|
|
$this->test_block_name,
|
|
array(
|
|
'api_version' => 2,
|
|
'attributes' => array(
|
|
'style' => array(
|
|
'type' => 'object',
|
|
),
|
|
),
|
|
'supports' => array(
|
|
'typography' => array(
|
|
'__experimentalFontFamily' => true,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
$registry = WP_Block_Type_Registry::get_instance();
|
|
$block_type = $registry->get_registered( $this->test_block_name );
|
|
$block_atts = array( 'style' => array( 'typography' => array( 'fontFamily' => 'var:preset|font-family|h1' ) ) );
|
|
|
|
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
|
$expected = array( 'style' => 'font-family: var(--wp--preset--font-family--h-1);' );
|
|
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
/**
|
|
* @ticket 54337
|
|
*
|
|
* @covers ::wp_apply_typography_support
|
|
*/
|
|
function test_font_family_with_class() {
|
|
$this->test_block_name = 'test/font-family-with-class';
|
|
register_block_type(
|
|
$this->test_block_name,
|
|
array(
|
|
'api_version' => 2,
|
|
'attributes' => array(
|
|
'style' => array(
|
|
'type' => 'object',
|
|
),
|
|
),
|
|
'supports' => array(
|
|
'typography' => array(
|
|
'__experimentalFontFamily' => true,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
$registry = WP_Block_Type_Registry::get_instance();
|
|
$block_type = $registry->get_registered( $this->test_block_name );
|
|
$block_atts = array( 'fontFamily' => 'h1' );
|
|
|
|
$actual = wp_apply_typography_support( $block_type, $block_atts );
|
|
$expected = array( 'class' => 'has-h-1-font-family' );
|
|
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
|
|
}
|