1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace ModernTimeline\Tests\Integration; |
6
|
|
|
|
7
|
|
|
use ModernTimeline\TimelineOptions; |
8
|
|
|
use ParamProcessor\ParamDefinitionFactory; |
9
|
|
|
use ParamProcessor\ProcessingResult; |
10
|
|
|
use ParamProcessor\Processor; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers \ModernTimeline\TimelineOptions |
15
|
|
|
*/ |
16
|
|
|
class OptionsTest extends TestCase { |
17
|
|
|
|
18
|
|
|
private const DEFAULT_SCALE_FACTOR = 2; |
19
|
|
|
private const DEFAULT_START_SLIDE = 0; |
20
|
|
|
|
21
|
|
|
public function testDefaultOptions() { |
22
|
|
|
$this->assertSame( |
23
|
|
|
[ |
24
|
|
|
'hash_bookmark' => false, |
25
|
|
|
'default_bg_color' => 'white', |
26
|
|
|
'scale_factor' => self::DEFAULT_SCALE_FACTOR, |
27
|
|
|
'timenav_position' => 'bottom', |
28
|
|
|
'optimal_tick_width' => 100, |
29
|
|
|
'start_at_slide' => self::DEFAULT_START_SLIDE, |
30
|
|
|
'start_at_end' => false, |
31
|
|
|
'duration' => 1000, |
32
|
|
|
'timenav_height' => 200, |
33
|
|
|
], |
34
|
|
|
$this->processUserInputToTimelineOptions( [] ) |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
private function processUserInputToTimelineOptions( array $userInput ): array { |
39
|
|
|
return TimelineOptions::processedParamsToJson( |
40
|
|
|
$this->processUserInput( $userInput )->getParameterArray() |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
private function processUserInput( array $userInput ): ProcessingResult { |
45
|
|
|
$processor = Processor::newDefault(); |
46
|
|
|
|
47
|
|
|
$processor->setParameters( $userInput ); |
48
|
|
|
$processor->setParameterDefinitions( $this->getParameterDefinitions() ); |
49
|
|
|
|
50
|
|
|
return $processor->processParameters(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function getParameterDefinitions(): array { |
54
|
|
|
return ParamDefinitionFactory::newDefault()->newDefinitionsFromArrays( |
55
|
|
|
TimelineOptions::getTimelineParameterDefinitions() |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testDefaultWidthAndHeight() { |
60
|
|
|
$parameters = $this->processUserInput( [] )->getParameterArray(); |
61
|
|
|
|
62
|
|
|
$this->assertSame( $GLOBALS['wgModernTimelineWidth'], $parameters['width'] ); |
63
|
|
|
$this->assertSame( $GLOBALS['wgModernTimelineHeight'], $parameters['height'] ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @dataProvider widthProvider |
68
|
|
|
*/ |
69
|
|
|
public function testWidth( string $input, string $expected ) { |
70
|
|
|
$parameters = $this->processUserInput( [ |
71
|
|
|
'width' => $input, |
72
|
|
|
] )->getParameterArray(); |
73
|
|
|
|
74
|
|
|
$this->assertSame( $expected, $parameters['width'] ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function widthProvider() { |
78
|
|
|
yield [ '10', '10px' ]; |
79
|
|
|
yield [ '10px', '10px' ]; |
80
|
|
|
yield [ '10%', '10%' ]; |
81
|
|
|
yield [ '10em', '10em' ]; |
82
|
|
|
yield [ '10ex', '10ex' ]; |
83
|
|
|
yield [ 'auto', 'auto' ]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @dataProvider heightProvider |
88
|
|
|
*/ |
89
|
|
|
public function testHeight( string $input, string $expected ) { |
90
|
|
|
$parameters = $this->processUserInput( [ |
91
|
|
|
'height' => $input, |
92
|
|
|
] )->getParameterArray(); |
93
|
|
|
|
94
|
|
|
$this->assertSame( $expected, $parameters['height'] ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function heightProvider() { |
98
|
|
|
yield [ '10', '10px' ]; |
99
|
|
|
yield [ '10px', '10px' ]; |
100
|
|
|
yield [ '10em', '10em' ]; |
101
|
|
|
yield [ '10ex', '10ex' ]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testTooLowScaleFactorDefaults() { |
105
|
|
|
$this->assertProcesses( 'scale factor', '0', self::DEFAULT_SCALE_FACTOR ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
private function assertProcesses( string $paramName, string $input, $expected ) { |
109
|
|
|
$parameters = $this->processUserInput( [ |
110
|
|
|
$paramName => $input, |
111
|
|
|
] )->getParameterArray(); |
112
|
|
|
|
113
|
|
|
$this->assertSame( $expected, $parameters[$paramName] ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testTooLowStartSlideDefaults() { |
117
|
|
|
$this->assertProcesses( 'start slide', '0', 1 ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testStartSlideIsOneBased() { |
121
|
|
|
$this->assertSame( |
122
|
|
|
2, |
123
|
|
|
$this->processUserInputToTimelineOptions( [ 'start slide' => '3' ] )['start_at_slide'] |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @dataProvider animationDurationAliasProvider |
129
|
|
|
*/ |
130
|
|
|
public function testAnimationDurationAliases( string $alias ) { |
131
|
|
|
$parameters = $this->processUserInput( [ |
132
|
|
|
$alias => '42', |
133
|
|
|
] )->getParameterArray(); |
134
|
|
|
|
135
|
|
|
$this->assertSame( 42, $parameters['transition duration'] ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function animationDurationAliasProvider() { |
139
|
|
|
yield 'automatic alias' => [ 'transitionduration' ]; |
140
|
|
|
yield 'manual alias' => [ 'duration' ]; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testNavHeightUsesCorrectJsonFieldWhenGivenPercentage() { |
144
|
|
|
$this->assertSame( |
145
|
|
|
50, |
146
|
|
|
$this->processUserInputToTimelineOptions( [ 'navigation height' => '50%' ] )['timenav_height_percentage'] |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |
151
|
|
|
|