summaryrefslogtreecommitdiff
path: root/www/wiki/vendor/param-processor/param-processor/tests/phpunit/Definitions/DimensionParamTest.php
blob: 52afad5d29d57c8023d22d7eaa677f19f2d00cfd (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php

namespace ParamProcessor\Tests\Definitions;

/**
 * @licence GNU GPL v2+
 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 */
class DimensionParamTest extends ParamDefinitionTest {

	/**
	 * @see ParamDefinitionTest::getDefinitions
	 * @return array
	 */
	public function getDefinitions() {
		$params = parent::getDefinitions();

		$params['auto'] = [
			'allowauto' => true,
		];

		$params['allunits'] = [
			'units' => [ 'px', 'ex', 'em', '%', '' ],
		];

		$params['bounds'] = [
			'lowerbound' => 42,
			'upperbound' => 9000,
			'maxpercentage' => 34,
			'minpercentage' => 23,
			'units' => [ 'px', 'ex', '%', '' ],
		];

		return $params;
	}

	/**
	 * @see ParamDefinitionTest::valueProvider
	 *
	 * @param boolean $stringlyTyped
	 *
	 * @return array
	 */
	public function valueProvider( $stringlyTyped = true ) {
		$values = [
			'empty' => [
				[ '100px', true, '100px' ],
				[ '100', true, '100px' ],
				[ 42, true, '42px' ],
				[ 42.5, true, '42.5px' ],
				[ 'over9000', false ],
				[ 'yes', false ],
				[ 'auto', false ],
				[ '100%', false ],
			],
			'values' => [
				[ 1, true, '1px' ],
//				array( 2, false ),
				[ 'yes', false ],
				[ 'no', false ],
			],
			'auto' => [
				[ 'auto', true, 'auto' ],
			],
			'allunits' => [
				[ '100%', true, '100%' ],
				[ '100em', true, '100em' ],
				[ '100ex', true, '100ex' ],
				[ '101%', false ],
			],
			'bounds' => [
				[ '30%', true, '30%' ],
				[ '20%', false ],
				[ '40%', false ],
				[ '100px', true, '100px' ],
				[ '100ex', true, '100ex' ],
				[ '10px', false ],
				[ '9001ex', false ],
			],
		];

		if ( $stringlyTyped ) {
			foreach ( $values as &$set ) {
				foreach ( $set as &$value ) {
					if ( is_int( $value[0] ) || is_float( $value[0] ) ) {
						$value[0] = (string)$value[0];
					}
				}
			}

//			$values['empty'][] = array( 42, false );
//			$values['empty'][] = array( 42.5, false );
		}

		return $values;
	}

	/**
	 * @see ParamDefinitionTest::getType
	 * @return string
	 */
	public function getType() {
		return 'dimension';
	}

}