summaryrefslogtreecommitdiff
path: root/www/wiki/vendor/param-processor/param-processor/tests/Unit/PackagePrivate/DimensionParserTest.php
blob: e82bb8b7de31e0ce8aa9398e5c3452a56225d15d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

declare( strict_types = 1 );

namespace ParamProcessor\Tests\Unit\PackagePrivate;

use ParamProcessor\PackagePrivate\DimensionParser;
use PHPUnit\Framework\TestCase;
use ValueParsers\ParseException;
use ValueParsers\ParserOptions;

class DimensionParserTest extends TestCase {

	public function testParserExceptionOnNonString() {
		$this->expectException( ParseException::class );
		$this->parse( 32202 );
	}

	private function parse( $input ) {
		return ( new DimensionParser() )->parse( $input );
	}

	/**
	 * @dataProvider validDimensionProvider
	 */
	public function testParsingValidInputs( string $input, string $expected ) {
		$this->assertSame( $expected, $this->parse( $input ) );
	}

	public function validDimensionProvider() {
		yield [ '10px', '10px' ];
		yield [ '10ex', '10ex' ];
		yield [ '10em', '10em' ];
		yield [ '2.5px', '2.5px' ];

		yield [ '10 px', '10px' ];
		yield [ '10  px', '10px' ];
		yield [ ' 10  px ', '10px' ];

		yield [ '10', '10px' ];
		yield [ '2.5', '2.5px' ];
	}

	public function testAlternateDefaultUnit() {
		$this->assertSame(
			'1%',
			( new DimensionParser( new ParserOptions( [ DimensionParser::DEFAULT_UNIT => '%' ] ) ) )->parse( '1' )
		);
	}

}