|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BootstrapComponents\Tests\Unit\Components; |
|
4
|
|
|
|
|
5
|
|
|
use BootstrapComponents\Components\Button; |
|
6
|
|
|
use BootstrapComponents\Tests\Unit\ComponentsTestBase; |
|
7
|
|
|
use \MWException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \BootstrapComponents\Components\Button |
|
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 ButtonTest extends ComponentsTestBase { |
|
23
|
|
|
|
|
24
|
|
|
private $input = 'Button test text'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @throws \MWException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testCanConstruct() { |
|
30
|
|
|
|
|
31
|
|
|
$this->assertInstanceOf( |
|
32
|
|
|
'BootstrapComponents\\Components\\Button', |
|
33
|
|
|
new Button( |
|
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 $expectedOutputPattern |
|
45
|
|
|
* |
|
46
|
|
|
* @dataProvider placeMeArgumentsProvider |
|
47
|
|
|
* @throws MWException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testCanRender( $input, $arguments, $expectedOutputPattern ) { |
|
50
|
|
|
$instance = new Button( |
|
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
|
|
|
if ( is_array( $generatedOutput ) ) { |
|
61
|
|
|
$generatedOutput = $generatedOutput[0]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->assertRegExp( |
|
65
|
|
|
$expectedOutputPattern, |
|
66
|
|
|
$generatedOutput |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @throws MWException |
|
72
|
|
|
*/ |
|
73
|
|
|
public function testCanInjectRawAttributes() { |
|
74
|
|
|
|
|
75
|
|
|
$instance = new Button( |
|
76
|
|
|
$this->getComponentLibrary(), |
|
77
|
|
|
$this->getParserOutputHelper(), |
|
78
|
|
|
$this->getNestingController() |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$parserRequest = $this->buildParserRequest( |
|
82
|
|
|
$this->input, |
|
83
|
|
|
[ 'class' => 'manual', 'size' => 'md' ] |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$instance->injectRawAttributes( |
|
87
|
|
|
[ 'data-toggle' => 'foo', 'data-target' => '#bar' ] |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
/** @noinspection PhpParamsInspection */ |
|
91
|
|
|
$generatedOutput = $instance->parseComponent( $parserRequest ); |
|
92
|
|
|
if ( is_array( $generatedOutput ) ) { |
|
93
|
|
|
$generatedOutput = $generatedOutput[0]; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$this->assertRegExp( |
|
97
|
|
|
'~^<a class="btn btn-default btn-md manual" role="button" id="bsc_button_NULL" href=".*/' . str_replace( ' ', '_', $this->input ) . '" data-toggle="foo" data-target="#bar">' . $this->input . '</a>$~', |
|
98
|
|
|
$generatedOutput |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
public function placeMeArgumentsProvider() { |
|
106
|
|
|
return [ |
|
107
|
|
|
'simple' => [ |
|
108
|
|
|
$this->input, |
|
109
|
|
|
[], |
|
110
|
|
|
'~^<a class="btn btn-default" role="button" id="bsc_button_NULL" href=".*/' . str_replace( ' ', '_', $this->input ) . '">' . $this->input . '</a>$~', |
|
111
|
|
|
], |
|
112
|
|
|
'empty' => [ |
|
113
|
|
|
'', |
|
114
|
|
|
[], |
|
115
|
|
|
'~bootstrap-components-button-target-missing~', // because getParserOutputHelper-mock returns the message key instead of parsing it. |
|
116
|
|
|
], |
|
117
|
|
|
'invalid' => [ |
|
118
|
|
|
' ', |
|
119
|
|
|
[], |
|
120
|
|
|
'~bootstrap-components-button-target-invalid~', // because getParserOutputHelper-mock returns the message key instead of parsing it. |
|
121
|
|
|
], |
|
122
|
|
|
'disabled, color, text and id' => [ |
|
123
|
|
|
$this->input, |
|
124
|
|
|
[ 'disabled' => true, 'color' => 'danger', 'text' => 'BUTTON', 'id' => 'red' ], |
|
125
|
|
|
'~^<a class="btn btn-danger disabled" role="button" id="red" href=".*/' . str_replace( ' ', '_', $this->input ) . '">BUTTON</a>$~', |
|
126
|
|
|
], |
|
127
|
|
|
'size and active' => [ |
|
128
|
|
|
$this->input, |
|
129
|
|
|
[ 'size' => 'lg', 'active' => true ], |
|
130
|
|
|
'~^<a class="btn btn-default btn-lg active" role="button" id="bsc_button_NULL" href=".*/' . str_replace( ' ', '_', $this->input ) . '">' . $this->input . '</a>$~', |
|
131
|
|
|
], |
|
132
|
|
|
'invlid size' => [ |
|
133
|
|
|
$this->input, |
|
134
|
|
|
[ 'size' => 'nice' ], |
|
135
|
|
|
'~^<a class="btn btn-default" role="button" id="bsc_button_NULL" href=".*/' . str_replace( ' ', '_', $this->input ) . '">' . $this->input . '</a>$~', |
|
136
|
|
|
], |
|
137
|
|
|
'link inside button' => [ |
|
138
|
|
|
$this->input, |
|
139
|
|
|
[ 'text' => 'This is a <a href="/wiki/index.php/Link>Link</a> inside the button text' ], |
|
140
|
|
|
'~^<a class="btn btn-default" role="button" id="bsc_button_NULL" href=".*/' . str_replace( ' ', '_', $this->input ) . '">This is a Link inside the button text</a>$~', |
|
141
|
|
|
], |
|
142
|
|
|
]; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|