|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BootstrapComponents\Tests\Unit\Components; |
|
4
|
|
|
|
|
5
|
|
|
use BootstrapComponents\Components\Alert; |
|
6
|
|
|
use BootstrapComponents\Tests\Unit\ComponentsTestBase; |
|
7
|
|
|
use \MWException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \BootstrapComponents\Components\Alert |
|
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 AlertTest extends ComponentsTestBase { |
|
23
|
|
|
|
|
24
|
|
|
private $input = 'Alert test text'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @throws \MWException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testCanConstruct() { |
|
30
|
|
|
|
|
31
|
|
|
$this->assertInstanceOf( |
|
32
|
|
|
'\\BootstrapComponents\\Components\\Alert', |
|
33
|
|
|
new Alert( |
|
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
|
|
|
* @dataProvider placeMeArgumentsProvider |
|
47
|
|
|
* @throws MWException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testCanRender( $input, $arguments, $expectedOutput ) { |
|
50
|
|
|
$instance = new Alert( |
|
51
|
|
|
$this->getComponentLibrary(), |
|
52
|
|
|
$this->getParserOutputHelper(), |
|
53
|
|
|
$this->getNestingController() |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$parserRequest = $this->buildParserRequest( $input, $arguments ); |
|
57
|
|
|
|
|
58
|
|
|
/** @noinspection PhpParamsInspection */ |
|
59
|
|
|
$generatedOutput = $instance->parseComponent( $parserRequest ); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertRegExp( '~^<div.+class="alert alert-.+".*role="alert".*>' . $this->input . '</div>$~', $generatedOutput ); |
|
62
|
|
|
$this->assertEquals( $expectedOutput, $generatedOutput ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function placeMeArgumentsProvider() { |
|
69
|
|
|
return [ |
|
70
|
|
|
'simple' => [ |
|
71
|
|
|
$this->input, |
|
72
|
|
|
[], |
|
73
|
|
|
'<div class="alert alert-info" id="bsc_alert_NULL" role="alert">' . $this->input . '</div>', |
|
74
|
|
|
], |
|
75
|
|
|
'color_unknown' => [ |
|
76
|
|
|
$this->input, |
|
77
|
|
|
[ 'color' => 'unknown' ], |
|
78
|
|
|
'<div class="alert alert-info" id="bsc_alert_NULL" role="alert">' . $this->input . '</div>', |
|
79
|
|
|
], |
|
80
|
|
|
'dismiss_invalid' => [ |
|
81
|
|
|
$this->input, |
|
82
|
|
|
[ 'dismissible' => 'bla' ], |
|
83
|
|
|
'<div class="alert alert-info alert-dismissible" id="bsc_alert_NULL" role="alert"><div type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></div>' . $this->input . '</div>', |
|
84
|
|
|
], |
|
85
|
|
|
'dismiss' => [ |
|
86
|
|
|
$this->input, |
|
87
|
|
|
[ 'dismissible' => true ], |
|
88
|
|
|
'<div class="alert alert-info alert-dismissible" id="bsc_alert_NULL" role="alert"><div type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></div>' . $this->input . '</div>', |
|
89
|
|
|
], |
|
90
|
|
|
'fading' => [ |
|
91
|
|
|
$this->input, |
|
92
|
|
|
[ 'dismissible' => 'fade', 'color' => 'warning' ], |
|
93
|
|
|
'<div class="alert alert-warning fade in" id="bsc_alert_NULL" role="alert"><div type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></div>' . $this->input . '</div>', |
|
94
|
|
|
], |
|
95
|
|
|
'manual id, no dismiss' => [ |
|
96
|
|
|
$this->input, |
|
97
|
|
|
[ 'color' => 'danger', 'id' => 'hms_dortmunder', 'dismissible' => 'false' ], |
|
98
|
|
|
'<div class="alert alert-danger" id="hms_dortmunder" role="alert">' . $this->input . '</div>', |
|
99
|
|
|
], |
|
100
|
|
|
'style and class' => [ |
|
101
|
|
|
$this->input, |
|
102
|
|
|
[ 'class' => 'dummy nice', 'style' => 'float:right;background-color:green' ], |
|
103
|
|
|
'<div class="alert alert-info dummy nice" style="float:right;background-color:green" id="bsc_alert_NULL" role="alert">' . $this->input . '</div>', |
|
104
|
|
|
], |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|