From a7fbce90b792efab82237e317025603417d1b31e Mon Sep 17 00:00:00 2001 From: ramonjd Date: Thu, 8 Sep 2022 15:50:55 +1000 Subject: [PATCH] Standardizing PHP doc comments for tests and new methods. Replaced parent::set_up(); with parent::tear_down();. --- src/wp-includes/block-supports/typography.php | 39 +++++++++----- .../tests/block-supports/typography.php | 52 +++++++++++++++---- 2 files changed, 67 insertions(+), 24 deletions(-) diff --git a/src/wp-includes/block-supports/typography.php b/src/wp-includes/block-supports/typography.php index 5f4e55bfe65aa..dd25a0767c877 100644 --- a/src/wp-includes/block-supports/typography.php +++ b/src/wp-includes/block-supports/typography.php @@ -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 $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() ) { @@ -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() ) { @@ -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 ) { diff --git a/tests/phpunit/tests/block-supports/typography.php b/tests/phpunit/tests/block-supports/typography.php index ad6a05bd6a85c..551aeb824b4ea 100644 --- a/tests/phpunit/tests/block-supports/typography.php +++ b/tests/phpunit/tests/block-supports/typography.php @@ -1,8 +1,6 @@ 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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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 ); @@ -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 */