| 1 |
<?php |
| 2 |
namespace MediaWiki\Tests\Integration\HTMLForm\Field; |
| 3 |
|
| 4 |
use MediaWiki\HTMLForm\Field\HTMLButtonField; |
| 5 |
use MediaWiki\Tests\Integration\HTMLForm\HTMLFormFieldTestCase; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class HTMLButtonFieldTest extends HTMLFormFieldTestCase { |
| 11 |
|
| 12 |
protected $className = HTMLButtonField::class; |
| 13 |
|
| 14 |
public static function provideInputHtml() { |
| 15 |
yield 'Basic button' => [ |
| 16 |
[ |
| 17 |
'buttonlabel' => 'Click me', |
| 18 |
], |
| 19 |
'', |
| 20 |
'<button class="mw-htmlform-submit" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 21 |
]; |
| 22 |
|
| 23 |
yield 'Button with CSS class' => [ |
| 24 |
[ |
| 25 |
'buttonlabel' => 'Click me', |
| 26 |
'cssclass' => 'my-button', |
| 27 |
], |
| 28 |
'', |
| 29 |
'<button class="mw-htmlform-submit my-button" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 30 |
]; |
| 31 |
|
| 32 |
yield 'Primary progressive button' => [ |
| 33 |
[ |
| 34 |
'buttonlabel' => 'Click me', |
| 35 |
'flags' => [ 'primary', 'progressive' ] |
| 36 |
], |
| 37 |
'', |
| 38 |
'<button class="mw-htmlform-submit mw-htmlform-primary mw-htmlform-progressive" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 39 |
]; |
| 40 |
|
| 41 |
yield 'Destructive button' => [ |
| 42 |
[ |
| 43 |
'buttonlabel' => 'Click me', |
| 44 |
'flags' => [ 'destructive' ] |
| 45 |
], |
| 46 |
'', |
| 47 |
'<button class="mw-htmlform-submit mw-htmlform-destructive" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 48 |
]; |
| 49 |
|
| 50 |
yield 'Quiet button with CSS class' => [ |
| 51 |
[ |
| 52 |
'buttonlabel' => 'Click me', |
| 53 |
'cssclass' => 'my-button', |
| 54 |
'flags' => [ 'quiet' ] |
| 55 |
], |
| 56 |
'', |
| 57 |
'<button class="mw-htmlform-submit my-button mw-htmlform-quiet" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 58 |
]; |
| 59 |
|
| 60 |
yield 'Disabled button' => [ |
| 61 |
[ |
| 62 |
'buttonlabel' => 'Click me', |
| 63 |
'disabled' => true |
| 64 |
], |
| 65 |
'', |
| 66 |
'<button class="mw-htmlform-submit" id="mw-input-testfield" type="button" name="testfield" disabled="">Click me</button>' |
| 67 |
]; |
| 68 |
} |
| 69 |
|
| 70 |
public static function provideInputCodex() { |
| 71 |
yield 'Basic button' => [ |
| 72 |
[ |
| 73 |
'buttonlabel' => 'Click me', |
| 74 |
], |
| 75 |
'', |
| 76 |
false, |
| 77 |
'<button class="mw-htmlform-submit cdx-button" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 78 |
]; |
| 79 |
|
| 80 |
yield 'Button with CSS class' => [ |
| 81 |
[ |
| 82 |
'buttonlabel' => 'Click me', |
| 83 |
'cssclass' => 'my-button', |
| 84 |
], |
| 85 |
'', |
| 86 |
false, |
| 87 |
'<button class="mw-htmlform-submit cdx-button my-button" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 88 |
]; |
| 89 |
|
| 90 |
yield 'Primary progressive button' => [ |
| 91 |
[ |
| 92 |
'buttonlabel' => 'Click me', |
| 93 |
'flags' => [ 'primary', 'progressive' ] |
| 94 |
], |
| 95 |
'', |
| 96 |
false, |
| 97 |
'<button class="mw-htmlform-submit cdx-button cdx-button--weight-primary cdx-button--action-progressive" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 98 |
]; |
| 99 |
|
| 100 |
yield 'Destructive button' => [ |
| 101 |
[ |
| 102 |
'buttonlabel' => 'Click me', |
| 103 |
'flags' => [ 'destructive' ] |
| 104 |
], |
| 105 |
'', |
| 106 |
false, |
| 107 |
'<button class="mw-htmlform-submit cdx-button cdx-button--action-destructive" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 108 |
]; |
| 109 |
|
| 110 |
yield 'Quiet button with CSS class' => [ |
| 111 |
[ |
| 112 |
'buttonlabel' => 'Click me', |
| 113 |
'cssclass' => 'my-button', |
| 114 |
'flags' => [ 'quiet' ] |
| 115 |
], |
| 116 |
'', |
| 117 |
false, |
| 118 |
'<button class="mw-htmlform-submit cdx-button my-button cdx-button--weight-quiet" id="mw-input-testfield" type="button" name="testfield">Click me</button>' |
| 119 |
]; |
| 120 |
|
| 121 |
yield 'Disabled button' => [ |
| 122 |
[ |
| 123 |
'buttonlabel' => 'Click me', |
| 124 |
'disabled' => true |
| 125 |
], |
| 126 |
'', |
| 127 |
false, |
| 128 |
'<button class="mw-htmlform-submit cdx-button" id="mw-input-testfield" type="button" name="testfield" disabled="">Click me</button>' |
| 129 |
]; |
| 130 |
} |
| 131 |
|
| 132 |
public static function provideInputOOUI() { |
| 133 |
yield 'Basic button' => [ |
| 134 |
[ |
| 135 |
'buttonlabel' => 'Click me', |
| 136 |
], |
| 137 |
'', |
| 138 |
"<span id='mw-input-testfield' class='mw-htmlform-submit oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget'><button type='button' tabindex='0' name='testfield' value='' class='oo-ui-inputWidget-input oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-iconElement-noIcon'></span><span class='oo-ui-labelElement-label'>Click me</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></button></span>" |
| 139 |
]; |
| 140 |
|
| 141 |
yield 'Button with CSS class' => [ |
| 142 |
[ |
| 143 |
'buttonlabel' => 'Click me', |
| 144 |
'cssclass' => 'my-button', |
| 145 |
], |
| 146 |
'', |
| 147 |
"<span id='mw-input-testfield' class='mw-htmlform-submit my-button oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget'><button type='button' tabindex='0' name='testfield' value='' class='oo-ui-inputWidget-input oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-iconElement-noIcon'></span><span class='oo-ui-labelElement-label'>Click me</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></button></span>" |
| 148 |
]; |
| 149 |
|
| 150 |
yield 'Primary progressive button' => [ |
| 151 |
[ |
| 152 |
'buttonlabel' => 'Click me', |
| 153 |
'flags' => [ 'primary', 'progressive' ] |
| 154 |
], |
| 155 |
'', |
| 156 |
"<span id='mw-input-testfield' class='mw-htmlform-submit oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-flaggedElement-primary oo-ui-flaggedElement-progressive oo-ui-buttonInputWidget'><button type='button' tabindex='0' name='testfield' value='' class='oo-ui-inputWidget-input oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-iconElement-noIcon'></span><span class='oo-ui-labelElement-label'>Click me</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></button></span>" |
| 157 |
|
| 158 |
]; |
| 159 |
|
| 160 |
yield 'Destructive button' => [ |
| 161 |
[ |
| 162 |
'buttonlabel' => 'Click me', |
| 163 |
'flags' => [ 'destructive' ] |
| 164 |
], |
| 165 |
'', |
| 166 |
"<span id='mw-input-testfield' class='mw-htmlform-submit oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-flaggedElement-destructive oo-ui-buttonInputWidget'><button type='button' tabindex='0' name='testfield' value='' class='oo-ui-inputWidget-input oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-iconElement-noIcon'></span><span class='oo-ui-labelElement-label'>Click me</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></button></span>" |
| 167 |
]; |
| 168 |
|
| 169 |
yield 'Quiet button with CSS class' => [ |
| 170 |
[ |
| 171 |
'buttonlabel' => 'Click me', |
| 172 |
'cssclass' => 'my-button', |
| 173 |
'flags' => [ 'quiet' ] |
| 174 |
], |
| 175 |
'', |
| 176 |
"<span id='mw-input-testfield' class='mw-htmlform-submit my-button oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-flaggedElement-quiet oo-ui-buttonInputWidget'><button type='button' tabindex='0' name='testfield' value='' class='oo-ui-inputWidget-input oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-iconElement-noIcon'></span><span class='oo-ui-labelElement-label'>Click me</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></button></span>" |
| 177 |
|
| 178 |
]; |
| 179 |
|
| 180 |
yield 'Disabled button' => [ |
| 181 |
[ |
| 182 |
'buttonlabel' => 'Click me', |
| 183 |
'disabled' => true |
| 184 |
], |
| 185 |
'', |
| 186 |
"<span id='mw-input-testfield' aria-disabled='true' class='mw-htmlform-submit oo-ui-widget oo-ui-widget-disabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget'><button type='button' tabindex='-1' aria-disabled='true' name='testfield' disabled='disabled' value='' class='oo-ui-inputWidget-input oo-ui-buttonElement-button'><span class='oo-ui-iconElement-icon oo-ui-iconElement-noIcon'></span><span class='oo-ui-labelElement-label'>Click me</span><span class='oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'></span></button></span>" |
| 187 |
]; |
| 188 |
} |
| 189 |
} |