Skip to content

Commit

Permalink
Standardizing PHP doc comments for tests and new methods.
Browse files Browse the repository at this point in the history
Replaced parent::set_up(); with parent::tear_down();.
  • Loading branch information
ramonjd committed Sep 8, 2022
1 parent b006d94 commit d61912a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 24 deletions.
39 changes: 25 additions & 14 deletions src/wp-includes/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ function wp_typography_get_preset_inline_style_value( $style_value, $css_propert
* @access private
*
* @param string $raw_value Raw size value from theme.json.
* @param array $options array(
* 'coerce_to' => (string) Coerce the value to rem or px. Default `'rem'`.
* 'root_size_value' => (number) Value of root font size for rem|em <-> px conversion. Default `16`.
* 'acceptable_units' => (array) An array of font size units. Default `[ 'rem', 'px', 'em' ]`;
* );.
* @param array $options {
* Optional. An associative array of options. Default is empty array.
*
* @type string $coerce_to Coerce the value to rem or px. Default `'rem'`.
* @type int $root_size_value Value of root font size for rem|em <-> px conversion. Default `16`.
* @type array<string> $acceptable_units An array of font size units. Default `[ 'rem', 'px', 'em' ]`;
* }
* @return array An array consisting of `'value'` and `'unit'` properties.
*/
function wp_get_typography_value_and_unit( $raw_value, $options = array() ) {
Expand Down Expand Up @@ -260,13 +262,15 @@ function wp_get_typography_value_and_unit( $raw_value, $options = array() ) {
* @since 6.1.0
* @access private
*
* @param array $args array(
* 'maximum_viewport_width' => (string) Maximum size up to which type will have fluidity.
* 'minimum_viewport_width' => (string) Minimum viewport size from which type will have fluidity.
* 'maximum_font_size' => (string) Maximum font size for any clamp() calculation.
* 'minimum_font_size' => (string) Minimum font size for any clamp() calculation.
* 'scale_factor' => (number) A scale factor to determine how fast a font scales within boundaries.
* );.
* @param array $args {
* Optional. An associative array of values to calculate a fluid formula for font size. Default is empty array.
*
* @type string $maximum_viewport_width Maximum size up to which type will have fluidity.
* @type string $minimum_viewport_width Minimum viewport size from which type will have fluidity.
* @type string $maximum_font_size Maximum font size for any clamp() calculation.
* @type string $minimum_font_size Minimum font size for any clamp() calculation.
* @type int $scale_factor A scale factor to determine how fast a font scales within boundaries.
* }
* @return string|null A font-size value using clamp().
*/
function wp_get_computed_fluid_typography_value( $args = array() ) {
Expand Down Expand Up @@ -334,8 +338,15 @@ function wp_get_computed_fluid_typography_value( $args = array() ) {
*
* @since 6.1.0
*
* @param array $preset fontSizes preset value as seen in theme.json.
* @param boolean $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
* @param array $preset {
* Required. fontSizes preset value as seen in theme.json.
*
* @type string $name Name of the font size preset.
* @type string $slug Kebab-case unique identifier for the font size preset.
* @type string $size CSS font-size value, including units where applicable.
* }
* @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing. Default is `false`.
*
* @return string Font-size value.
*/
function wp_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
Expand Down
52 changes: 42 additions & 10 deletions tests/phpunit/tests/block-supports/typography.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
/**
* @group block-supports
*
* @covers ::wp_apply_typography_support
*/
class Tests_Block_Supports_Typography extends WP_UnitTestCase {
/**
Expand All @@ -18,13 +16,16 @@ function set_up() {
function tear_down() {
unregister_block_type( $this->test_block_name );
$this->test_block_name = null;
parent::set_up();
parent::tear_down();
}

/**
* Tests whether slugs with numbers are kebab cased.
*
* @ticket 54337
* @covers ::wp_apply_typography_support
*/
function test_font_size_slug_with_numbers_is_kebab_cased_properly() {
function test_should_kebab_case_font_size_slug_with_numbers() {
$this->test_block_name = 'test/font-size-slug-with-numbers';
register_block_type(
$this->test_block_name,
Expand Down Expand Up @@ -52,10 +53,14 @@ function test_font_size_slug_with_numbers_is_kebab_cased_properly() {

$this->assertSame( $expected, $actual );
}

/**
* Tests legacy inline styles for font family.
*
* @ticket 54337
* @covers ::wp_apply_typography_support
*/
function test_font_family_with_legacy_inline_styles_using_a_value() {
function test_should_generate_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,
Expand Down Expand Up @@ -84,9 +89,12 @@ function test_font_family_with_legacy_inline_styles_using_a_value() {
}

/**
* Tests skipping serialization.
*
* @ticket 55505
* @covers ::wp_apply_typography_support
*/
function test_typography_with_skipped_serialization_block_supports() {
function test_should_skip_serialization_for_typography_block_supports() {
$this->test_block_name = 'test/typography-with-skipped-serialization-block-supports';
register_block_type(
$this->test_block_name,
Expand Down Expand Up @@ -128,9 +136,12 @@ function test_typography_with_skipped_serialization_block_supports() {
}

/**
* Tests skipping serialization of individual block supports properties.
*
* @ticket 55505
* @covers ::wp_apply_typography_support
*/
function test_letter_spacing_with_individual_skipped_serialization_block_supports() {
function test_should_skip_serialization_for_letter_spacing_block_supports() {
$this->test_block_name = 'test/letter-spacing-with-individual-skipped-serialization-block-supports';
register_block_type(
$this->test_block_name,
Expand Down Expand Up @@ -160,10 +171,14 @@ function test_letter_spacing_with_individual_skipped_serialization_block_support

$this->assertSame( $expected, $actual );
}

/**
* Tests legacy css var inline styles for font family.
*
* @ticket 54337
* @covers ::wp_apply_typography_support
*/
function test_font_family_with_legacy_inline_styles_using_a_css_var() {
function test_should_generate_css_var_for_font_family_with_legacy_inline_styles() {
$this->test_block_name = 'test/font-family-with-inline-styles-using-css-var';
register_block_type(
$this->test_block_name,
Expand All @@ -190,10 +205,14 @@ function test_font_family_with_legacy_inline_styles_using_a_css_var() {

$this->assertSame( $expected, $actual );
}

/**
* Tests that a classname is generated for font family.
*
* @ticket 54337
* @covers ::wp_apply_typography_support
*/
function test_font_family_with_class() {
function test_should_generate_classname_for_font_family() {
$this->test_block_name = 'test/font-family-with-class';
register_block_type(
$this->test_block_name,
Expand Down Expand Up @@ -225,8 +244,21 @@ function test_font_family_with_class() {
* Tests generating font size values, including fluid formulae, from fontSizes preset.
*
* @ticket 56467
* @covers ::wp_get_typography_font_size_value
* @covers ::wp_get_typography_value_and_unit
* @covers ::wp_get_computed_fluid_typography_value
*
* @dataProvider data_generate_font_size_preset_fixtures
*
* @param array $font_size_preset {
* Required. fontSizes preset value as seen in theme.json.
*
* @type string $name Name of the font size preset.
* @type string $slug Kebab-case unique identifier for the font size preset.
* @type string $size CSS font-size value, including units where applicable.
* }
* @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
* @param string $expected_output Expected output of gutenberg_get_typography_font_size_value().
*/
function test_wp_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography, $expected_output ) {
$actual = wp_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography );
Expand All @@ -235,7 +267,7 @@ function test_wp_get_typography_font_size_value( $font_size_preset, $should_use_
}

/**
* Data provider.
* Data provider for test_wp_get_typography_font_size_value.
*
* @return array
*/
Expand Down

0 comments on commit d61912a

Please sign in to comment.