1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BootstrapComponents\Tests\Unit\Components; |
4
|
|
|
|
5
|
|
|
use BootstrapComponents\Components\Panel; |
6
|
|
|
use BootstrapComponents\Tests\Unit\ComponentsTestBase; |
7
|
|
|
use \MWException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers \BootstrapComponents\Components\Panel |
11
|
|
|
* |
12
|
|
|
* @ingroup Test |
13
|
|
|
* |
14
|
|
|
* @group extension-bootstrap-components |
15
|
|
|
* @group mediawiki-databaseless |
16
|
|
|
* |
17
|
|
|
* @license GNU GPL v3+ |
18
|
|
|
* |
19
|
|
|
* @since 1.0 |
20
|
|
|
* @author Tobias Oetterer |
21
|
|
|
*/ |
22
|
|
|
class PanelTest extends ComponentsTestBase { |
23
|
|
|
|
24
|
|
|
private $input = 'Panel test text'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @throws \MWException |
28
|
|
|
*/ |
29
|
|
|
public function testCanConstruct() { |
30
|
|
|
|
31
|
|
|
$this->assertInstanceOf( |
32
|
|
|
'BootstrapComponents\\Components\\Panel', |
33
|
|
|
new Panel( |
34
|
|
|
$this->getComponentLibrary(), |
35
|
|
|
$this->getParserOutputHelper(), |
36
|
|
|
$this->getNestingController() |
37
|
|
|
) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $input |
43
|
|
|
* @param array $arguments |
44
|
|
|
* @param string $expectedOutput |
45
|
|
|
* |
46
|
|
|
* @throws MWException |
47
|
|
|
* |
48
|
|
|
* @dataProvider placeMeArgumentsProvider |
49
|
|
|
*/ |
50
|
|
|
public function testCanRender( $input, $arguments, $expectedOutput ) { |
51
|
|
|
$instance = new Panel( |
52
|
|
|
$this->getComponentLibrary(), |
53
|
|
|
$this->getParserOutputHelper(), |
54
|
|
|
$this->getNestingController() |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$parserRequest = $this->buildParserRequest( $input, $arguments ); |
58
|
|
|
|
59
|
|
|
/** @noinspection PhpParamsInspection */ |
60
|
|
|
$generatedOutput = $instance->parseComponent( $parserRequest ); |
61
|
|
|
|
62
|
|
|
$this->assertEquals( $expectedOutput, $generatedOutput ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $input |
67
|
|
|
* @param array $arguments |
68
|
|
|
* @param string $expectedOutput |
69
|
|
|
* |
70
|
|
|
* @throws MWException |
71
|
|
|
* |
72
|
|
|
* @dataProvider placeMeInsideAccordionArgumentsProvider |
73
|
|
|
*/ |
74
|
|
|
public function testCanRenderAccordionPanel( $input, $arguments, $expectedOutput ) { |
75
|
|
|
$accordion = $this->getMockBuilder( 'BootstrapComponents\\Components\\Accordion' ) |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->getMock(); |
78
|
|
|
$accordion->expects( $this->any() ) |
79
|
|
|
->method( 'getComponentName' ) |
80
|
|
|
->willReturn( 'accordion' ); |
81
|
|
|
$accordion->expects( $this->any() ) |
82
|
|
|
->method( 'getId' ) |
83
|
|
|
->willReturn( 'accordion0' ); |
84
|
|
|
$nestingController = $this->getMockBuilder( 'BootstrapComponents\\NestingController' ) |
85
|
|
|
->disableOriginalConstructor() |
86
|
|
|
->getMock(); |
87
|
|
|
$nestingController->expects( $this->any() ) |
88
|
|
|
->method( 'generateUniqueId' ) |
89
|
|
|
->will( $this->returnCallback( function( $componentName ) { |
90
|
|
|
return 'bsc_' . $componentName . '_NULL'; |
91
|
|
|
} ) ); |
92
|
|
|
$nestingController->expects( $this->any() ) |
93
|
|
|
->method( 'getCurrentElement' ) |
94
|
|
|
->willReturn( $accordion ); |
95
|
|
|
|
96
|
|
|
/** @noinspection PhpParamsInspection */ |
97
|
|
|
$instance = new Panel( |
98
|
|
|
$this->getComponentLibrary(), |
99
|
|
|
$this->getParserOutputHelper(), |
100
|
|
|
$nestingController |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
$parserRequest = $this->buildParserRequest( $input, $arguments ); |
104
|
|
|
|
105
|
|
|
/** @noinspection PhpParamsInspection */ |
106
|
|
|
$generatedOutput = $instance->parseComponent( $parserRequest ); |
107
|
|
|
|
108
|
|
|
$this->assertEquals( $expectedOutput, $generatedOutput ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
|
|
public function placeMeArgumentsProvider() { |
115
|
|
|
return [ |
116
|
|
|
'simple' => [ |
117
|
|
|
$this->input, |
118
|
|
|
[], |
119
|
|
|
'<div class="panel panel-default"><div id="bsc_panel_NULL"><div class="panel-body">' . $this->input . '</div></div></div>', |
120
|
|
|
], |
121
|
|
|
'text missing' => [ |
122
|
|
|
'', |
123
|
|
|
[ 'heading' => 'watch this', 'footer' => 'watch what?', 'collapsible' => 'false', ], |
124
|
|
|
'<div class="panel panel-default"><div class="panel-heading"><h4 class="panel-title" style="margin-top:0;padding-top:0;">watch this</h4></div><div id="bsc_panel_NULL"><div class="panel-body"></div><div class="panel-footer">watch what?</div></div></div>', |
125
|
|
|
], |
126
|
|
|
'all attributes' => [ |
127
|
|
|
$this->input, |
128
|
|
|
[ |
129
|
|
|
'class' => 'dummy nice', |
130
|
|
|
'style' => 'float:right;background-color:green', |
131
|
|
|
'id' => 'badgers_bowler', |
132
|
|
|
'active' => 'yes', |
133
|
|
|
'color' => 'info', |
134
|
|
|
'collapsible' => '', |
135
|
|
|
'heading' => 'HEADING TEXT', |
136
|
|
|
'footer' => 'FOOTER TEXT', |
137
|
|
|
], |
138
|
|
|
'<div class="panel panel-info dummy nice" style="float:right;background-color:green"><div class="panel-heading" data-toggle="collapse" href="#badgers_bowler"><h4 class="panel-title" style="margin-top:0;padding-top:0;">HEADING TEXT</h4></div><div id="badgers_bowler" class="panel-collapse collapse fade in"><div class="panel-body">' . $this->input . '</div><div class="panel-footer">FOOTER TEXT</div></div></div>', |
139
|
|
|
], |
140
|
|
|
'collapsible false' => [ |
141
|
|
|
$this->input, |
142
|
|
|
[ 'collapsible' => 'false', ], |
143
|
|
|
'<div class="panel panel-default"><div id="bsc_panel_NULL"><div class="panel-body">' . $this->input . '</div></div></div>', |
144
|
|
|
], |
145
|
|
|
]; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return array |
150
|
|
|
*/ |
151
|
|
|
public function placeMeInsideAccordionArgumentsProvider() { |
152
|
|
|
return [ |
153
|
|
|
'simple' => [ |
154
|
|
|
$this->input, |
155
|
|
|
[], |
156
|
|
|
'<div class="panel panel-default"><div class="panel-heading" data-parent="#accordion0" data-toggle="collapse" href="#bsc_panel_NULL"><h4 class="panel-title" style="margin-top:0;padding-top:0;">bsc_panel_NULL</h4></div><div id="bsc_panel_NULL" class="panel-collapse collapse fade"><div class="panel-body">' . $this->input . '</div></div></div>', |
157
|
|
|
], |
158
|
|
|
'text missing' => [ |
159
|
|
|
'', |
160
|
|
|
[ 'heading' => 'watch this', 'footer' => 'watch what?', 'collapsible' => 'false', ], |
161
|
|
|
'<div class="panel panel-default"><div class="panel-heading" data-parent="#accordion0" data-toggle="collapse" href="#bsc_panel_NULL"><h4 class="panel-title" style="margin-top:0;padding-top:0;">watch this</h4></div><div id="bsc_panel_NULL" class="panel-collapse collapse fade"><div class="panel-body"></div><div class="panel-footer">watch what?</div></div></div>', |
162
|
|
|
], |
163
|
|
|
'all attributes' => [ |
164
|
|
|
$this->input, |
165
|
|
|
[ |
166
|
|
|
'class' => 'dummy nice', |
167
|
|
|
'style' => 'float:right;background-color:green', |
168
|
|
|
'id' => 'badgers_bowler', |
169
|
|
|
'active' => 'yes', |
170
|
|
|
'color' => 'info', |
171
|
|
|
'collapsible' => '', |
172
|
|
|
'heading' => 'HEADING TEXT', |
173
|
|
|
'footer' => 'FOOTER TEXT', |
174
|
|
|
], |
175
|
|
|
'<div class="panel panel-info dummy nice" style="float:right;background-color:green"><div class="panel-heading" data-parent="#accordion0" data-toggle="collapse" href="#badgers_bowler"><h4 class="panel-title" style="margin-top:0;padding-top:0;">HEADING TEXT</h4></div><div id="badgers_bowler" class="panel-collapse collapse fade in"><div class="panel-body">' . $this->input . '</div><div class="panel-footer">FOOTER TEXT</div></div></div>', |
176
|
|
|
], |
177
|
|
|
'collapsible false' => [ |
178
|
|
|
$this->input, |
179
|
|
|
[ 'collapsible' => 'false', ], |
180
|
|
|
'<div class="panel panel-default"><div class="panel-heading" data-parent="#accordion0" data-toggle="collapse" href="#bsc_panel_NULL"><h4 class="panel-title" style="margin-top:0;padding-top:0;">bsc_panel_NULL</h4></div><div id="bsc_panel_NULL" class="panel-collapse collapse fade"><div class="panel-body">' . $this->input . '</div></div></div>', |
181
|
|
|
], |
182
|
|
|
]; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|