Skip to content

Commit

Permalink
Standardizing PHP doc comments for tests and new methods. (#43968)
Browse files Browse the repository at this point in the history
Replaced parent::set_up(); with parent::tear_down();.
  • Loading branch information
ramonjd authored Sep 8, 2022
1 parent 85b96b7 commit 40c1212
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 24 deletions.
39 changes: 25 additions & 14 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,13 @@ function gutenberg_typography_get_css_variable_inline_style( $attributes, $featu
* @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 gutenberg_get_typography_value_and_unit( $raw_value, $options = array() ) {
Expand Down Expand Up @@ -289,13 +291,15 @@ function gutenberg_get_typography_value_and_unit( $raw_value, $options = array()
*
* @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 gutenberg_get_computed_fluid_typography_value( $args = array() ) {
Expand Down Expand Up @@ -361,8 +365,15 @@ function gutenberg_get_computed_fluid_typography_value( $args = array() ) {
* Returns a font-size value based on a given font-size preset.
* Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.
*
* @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 gutenberg_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
Expand Down
70 changes: 60 additions & 10 deletions phpunit/block-supports/typography-test.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
<?php

/**
* Test the typography block supports.
* Tests the typography block supports.
*
* @package Gutenberg
*/

class WP_Block_Supports_Typography_Test extends WP_UnitTestCase {
/**
* Stores the current test block name.
*
* @var string|null
*/
private $test_block_name;

/**
* Sets up tests.
*/
function set_up() {
parent::set_up();
$this->test_block_name = null;
}

/**
* Tears down tests.
*/
function tear_down() {
unregister_block_type( $this->test_block_name );
$this->test_block_name = null;
parent::tear_down();
}

function test_font_size_slug_with_numbers_is_kebab_cased_properly() {
/**
* Tests whether slugs with numbers are kebab cased.
*
* @covers ::wp_apply_typography_support
*/
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,7 +63,12 @@ function test_font_size_slug_with_numbers_is_kebab_cased_properly() {
$this->assertSame( $expected, $actual );
}

function test_font_family_with_legacy_inline_styles_using_a_value() {
/**
* Tests legacy inline styles for font family.
*
* @covers ::wp_apply_typography_support
*/
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 @@ -80,7 +96,12 @@ function test_font_family_with_legacy_inline_styles_using_a_value() {
$this->assertSame( $expected, $actual );
}

function test_typography_with_skipped_serialization_block_supports() {
/**
* Tests skipping serialization.
*
* @covers ::wp_apply_typography_support
*/
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 @@ -121,7 +142,12 @@ function test_typography_with_skipped_serialization_block_supports() {
$this->assertSame( $expected, $actual );
}

function test_letter_spacing_with_individual_skipped_serialization_block_supports() {
/**
* Tests skipping serialization of individual block supports properties.
*
* @covers ::wp_apply_typography_support
*/
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 @@ -152,7 +178,12 @@ function test_letter_spacing_with_individual_skipped_serialization_block_support
$this->assertSame( $expected, $actual );
}

function test_font_family_with_legacy_inline_styles_using_a_css_var() {
/**
* Tests legacy css var inline styles for font family.
*
* @covers ::wp_apply_typography_support
*/
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 Down Expand Up @@ -180,7 +211,12 @@ function test_font_family_with_legacy_inline_styles_using_a_css_var() {
$this->assertSame( $expected, $actual );
}

function test_font_family_with_class() {
/**
* Tests that a classname is generated for font family.
*
* @covers ::wp_apply_typography_support
*/
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 @@ -211,7 +247,21 @@ function test_font_family_with_class() {
/**
* Tests generating font size values, including fluid formulae, from fontSizes preset.
*
* @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_gutenberg_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography, $expected_output ) {
$actual = gutenberg_get_typography_font_size_value( $font_size_preset, $should_use_fluid_typography );
Expand All @@ -220,7 +270,7 @@ function test_gutenberg_get_typography_font_size_value( $font_size_preset, $shou
}

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

0 comments on commit 40c1212

Please sign in to comment.