Completed
Push — update/add-csstidy-config-sett... ( a816cd...978381 )
by
unknown
549:14 queued 537:38
created

test_preserve_leading_zeros()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class WP_Test_Jetpack_CSSTidy.
4
 *
5
 * @package automattic/jetpack
6
 */
7
8
require_jetpack_file( 'modules/custom-css/csstidy/class.csstidy.php' );
9
10
/**
11
 * Class WP_Test_Jetpack_CSSTidy
12
 */
13
class WP_Test_Jetpack_CSSTidy extends WP_UnitTestCase {
14
15
	/**
16
	 * The tested instance.
17
	 *
18
	 * @var csstidy
19
	 */
20
	public $instance;
21
22
	/**
23
	 * Sets up each test.
24
	 *
25
	 * @inheritDoc
26
	 */
27
	public function setUp() {
28
		parent::setUp();
29
		$this->instance = new csstidy();
30
		$this->instance->set_cfg( 'optimise_shorthands', 0 );
31
	}
32
33
	/** Provides values for CSS preserve leading zeros patterns */
34
	public function custom_preserve_leading_zeros_provider() {
35
		// phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- false positive
36
		// 'test case description' => [ 'input', 'expected output', 'preserve_leading_zeros' ].
37
		return array(
38
			'test_removes_leading_zeros_by_default'       => array( 'marquee {line-height:0.7;opacity:0.05;background-color:rgba(255, 255, 255, 0.25);}', "marquee {\nline-height:.7;\nopacity:.05;\nbackground-color:rgba(255,255,255,0.25)\n}", false ),
39
			'test_decimals_greater_than_one_unchanged_default' => array( 'blink {line-height:1.7;top:-100.55em;}', "blink {\nline-height:1.7;\ntop:-100.55em\n}", false ),
40
			'test_removes_leading_zeros_by_default_units' => array( 'dfn {margin-left:-0.7px;top:0.55rem;line-height:0.3333;text-indent:-9999%}', "dfn {\nmargin-left:-.7px;\ntop:.55rem;\nline-height:.3333;\ntext-indent:-9999%\n}", false ),
41
			'test_preserves_leading_zeros'                => array( 'aside {line-height:0.7;background-color:rgba(255, 255, 255, 0.25);opacity:0.05;}', "aside {\nline-height:0.7;\nbackground-color:rgba(255,255,255,0.25);\nopacity:0.05\n}", true ),
42
			'test_preserves_leading_zeros_units'          => array( 'code {line-height:.70;margin-left:-00.70px;top:0.55rem;padding:0.3333%;}', "code {\nline-height:0.7;\nmargin-left:-0.7px;\ntop:0.55rem;\npadding:0.3333%\n}", true ),
43
			'test_decimals_greater_than_one_unchanged_preserve_zeros' => array( 'blink {line-height:1.70;top:100.55em;margin-left:900px;}', "blink {\nline-height:1.7;\ntop:100.55em;\nmargin-left:900px\n}", false ),
44
		);
45
	}
46
47
	/**
48
	 * Test that leading zeros for decimals values are preserved/discarded as expected.
49
	 *
50
	 * @dataProvider custom_preserve_leading_zeros_provider
51
	 *
52
	 * @param string $input                  potential CSS values.
53
	 * @param string $expected_output        what we expect csstidy to output.
54
	 * @param bool   $preserve_leading_zeros the value of `preserve_leading_zeros` in csstidy's config.
55
	 */
56
	public function test_preserve_leading_zeros( $input, $expected_output, $preserve_leading_zeros ) {
57
		$this->instance->set_cfg( 'preserve_leading_zeros', $preserve_leading_zeros );
58
		$this->instance->parse( $input );
59
		$this->assertEquals(
60
			$expected_output,
61
			$this->instance->print->plain()
62
		);
63
	}
64
}
65