Skip to content

Commit

Permalink
Updating @return comment to reflect usage
Browse files Browse the repository at this point in the history
Adding base test file

Whatever, linter.
  • Loading branch information
ramonjd committed Mar 21, 2022
1 parent 0fcafbe commit 1187a23
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/style-engine/class-wp-style-engine-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ public function add_style( $key, $options ) {
* @param string|array $style_value A single raw Gutenberg style attributes value for a CSS property.
* @param array $path An array of strings representing a path to the style value.
*
* @return array The class name for the added style.
* @return array A CSS ruleset compatible with add_style().
*/
protected function get_block_style_css_rules( $style_value, $path ) {
$style_definition = _wp_array_get( static::BLOCK_STYLE_DEFINITIONS_METADATA, $path, null );

if ( $style_definition ) {
if ( ! empty( $style_definition ) ) {
if (
isset( $style_definition['value_func'] ) &&
is_callable( $style_definition['value_func'] )
Expand Down
2 changes: 1 addition & 1 deletion lib/style-engine/style-definition-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function gutenberg_get_style_engine_css_box_rules( $style_value, $style_property
$rules[ "$style_property-$key" ] = $value; // . ' !important'; Challenge: deal with specificity that inline styles bring us. Maybe we could pass an option.
}
} else {
$rules[] = sprintf( "$style_property:%s;", $style_value );
$rules[ $style_property ] = $style_value;
}
return $rules;
}
Expand Down
62 changes: 62 additions & 0 deletions phpunit/style-engine/class-wp-style-engine-gutenberg-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Tests the Style Engine class and associated functionality.
*
* @package Gutenberg
* @subpackage block-library
*/

/**
* Tests for registering, storing and generating styles.
*/
class WP_Style_Engine_Gutenberg_Test extends WP_UnitTestCase {
function test_returns_inline_styles_from_string() {
$style_engine = WP_Style_Engine_Gutenberg::get_instance();
$block_styles = array(
'spacing' => array(
'padding' => '111px',
),
);
$padding_styles = $style_engine->get_inline_styles_from_attributes(
$block_styles,
array( 'spacing', 'padding' )
);
$expected = 'padding:111px;';
$this->assertSame( $expected, $padding_styles );
}

function test_returns_inline_styles_from_box_rules() {
$style_engine = WP_Style_Engine_Gutenberg::get_instance();
$block_styles = array(
'spacing' => array(
'padding' => array(
'top' => '42px',
'left' => '2%',
'bottom' => '44px',
'right' => '5rem',
),
),
);
$padding_styles = $style_engine->get_inline_styles_from_attributes(
$block_styles,
array( 'spacing', 'padding' )
);
$expected = 'padding-top:42px;padding-left:2%;padding-bottom:44px;padding-right:5rem;';
$this->assertSame( $expected, $padding_styles );
}

function test_returns_empty_string_when_invalid_path_passed() {
$style_engine = WP_Style_Engine_Gutenberg::get_instance();
$block_styles = array(
'spacing' => array(
'padding' => '111px',
),
);
$padding_styles = $style_engine->get_inline_styles_from_attributes(
$block_styles,
null
);
$expected = '';
$this->assertSame( $expected, $padding_styles );
}
}

0 comments on commit 1187a23

Please sign in to comment.