Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Combining tests for get_declarations_string
Updating php doc params
  • Loading branch information
ramonjd committed Sep 9, 2022
commit f044bf428e8135a470a194e59e76f96d2773a147
16 changes: 12 additions & 4 deletions tests/phpunit/tests/style-engine/styleEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ public function tear_down() {
* @ticket 56467
* @covers ::wp_style_engine_get_styles
*
* @dataProvider data_get_styles_fixtures
* @dataProvider data_wp_style_engine_get_styles
*
* @param array $block_styles The incoming block styles object.
* @param array $options Style engine options.
* @param array $options {
* An array of options to pass to `wp_style_engine_get_styles()`.
*
* @type string|null $context An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is `null`.
* When set, the style engine will attempt to store the CSS rules, where a selector is also passed.
* @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.
* @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`,
* otherwise, the value will be a concatenated string of CSS declarations.
* }
* @param string $expected_output The expected output.
*/
public function test_wp_style_engine_get_styles( $block_styles, $options, $expected_output ) {
Expand All @@ -39,11 +47,11 @@ public function test_wp_style_engine_get_styles( $block_styles, $options, $expec
}

/**
* Data provider for test_generate_get_styles().
* Data provider for test_wp_style_engine_get_styles().
*
* @return array
*/
public function data_get_styles_fixtures() {
public function data_wp_style_engine_get_styles() {
return array(
'default_return_value' => array(
'block_styles' => array(),
Expand Down
96 changes: 35 additions & 61 deletions tests/phpunit/tests/style-engine/wpStyleEngineCssDeclarations.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,86 +113,60 @@ public function test_should_remove_unsafe_properties_and_values() {
}

/**
* Tests that css declarations are compiled into a css declarations block string.
* Tests that CSS declarations are compiled into a CSS declarations block string.
*
* @ticket 56467
* @covers ::get_declarations_string
*/
public function test_should_generate_css_declarations_string() {
$input_declarations = array(
'color' => 'red',
'border-top-left-radius' => '99px',
'text-decoration' => 'underline',
);
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );

$this->assertSame(
'color:red;border-top-left-radius:99px;text-decoration:underline;',
$css_declarations->get_declarations_string()
);
}

/**
* Tests that inline css declarations are compiled into a prettified css declarations block string.
*
* @ticket 56467
* @covers ::get_declarations_string
*/
public function test_should_generate_prettified_css_declarations_string() {
$input_declarations = array(
'color' => 'red',
'border-top-left-radius' => '99px',
'text-decoration' => 'underline',
);
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );

$this->assertSame(
'color: red; border-top-left-radius: 99px; text-decoration: underline;',
$css_declarations->get_declarations_string( true )
);
}

/**
* Tests that inline css declarations are compiled into a prettified css declarations block string with new lines and indents.
*
* @ticket 56467
* @covers ::get_declarations_string
* @dataProvider data_should_compile_css_declarations_to_css_declarations_string
*
* @param string $expected The expected declarations block string.
* @param bool $should_prettify Optional. Whether to pretty the string. Default false.
* @param int $indent_count Optional. The number of tab indents. Default false.
*/
public function test_should_generate_prettified_css_declarations_string_with_new_lines_and_indents() {
public function test_should_compile_css_declarations_to_css_declarations_string( $expected, $should_prettify = false, $indent_count = 0 ) {
$input_declarations = array(
'color' => 'red',
'border-top-left-radius' => '99px',
'text-decoration' => 'underline',
);
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );

$this->assertSame(
' color: red;
border-top-left-radius: 99px;
text-decoration: underline;',
$css_declarations->get_declarations_string( true, 1 )
$expected,
$css_declarations->get_declarations_string( $should_prettify, $indent_count )
);
}

/**
* Tests that inline css declarations are compiled into a prettified css declarations block string with extra indents.
* Data provider for test_should_compile_css_declarations_to_css_declarations_string().
*
* @ticket 56467
* @covers ::get_declarations_string
* @return array
*/
public function test_should_generate_prettified_with_extra_indents_css_declarations_string() {
$input_declarations = array(
'color' => 'red',
'border-top-left-radius' => '99px',
'text-decoration' => 'underline',
);
$css_declarations = new WP_Style_Engine_CSS_Declarations( $input_declarations );

$this->assertSame(
' color: red;
border-top-left-radius: 99px;
text-decoration: underline;',
$css_declarations->get_declarations_string( true, 2 )
public function data_should_compile_css_declarations_to_css_declarations_string() {
return array(
'unprettified, no indent' => array(
'expected' => 'color:red;border-top-left-radius:99px;text-decoration:underline;',
),
'unprettified, one indent' => array(
'expected' => 'color:red;border-top-left-radius:99px;text-decoration:underline;',
'should_prettify' => false,
'indent_count' => 1,
),
'prettified, no indent' => array(
'expected' => 'color: red; border-top-left-radius: 99px; text-decoration: underline;',
'should_prettify' => true,
),
'prettified, one indent' => array(
'expected' => "\tcolor: red;\n\tborder-top-left-radius: 99px;\n\ttext-decoration: underline;",
'should_prettify' => true,
'indent_count' => 1,
),
'prettified, two indents' => array(
'expected' => "\t\tcolor: red;\n\t\tborder-top-left-radius: 99px;\n\t\ttext-decoration: underline;",
'should_prettify' => true,
'indent_count' => 2,
),
);
}

Expand Down