3 * @covers HTMLAutoCompleteSelectField
5 class HTMLAutoCompleteSelectFieldTest
extends MediaWikiTestCase
{
9 'Burkina Faso' => 'BFA',
14 * Verify that attempting to instantiate an HTMLAutoCompleteSelectField
15 * without providing any autocomplete options causes an exception to be
18 * @expectedException MWException
19 * @expectedExceptionMessage called without any autocompletions
21 function testMissingAutocompletions() {
22 new HTMLAutoCompleteSelectField( [ 'fieldname' => 'Test' ] );
26 * Verify that the autocomplete options are correctly encoded as
27 * the 'data-autocomplete' attribute of the field.
29 * @covers HTMLAutoCompleteSelectField::getAttributes
31 function testGetAttributes() {
32 $field = new HTMLAutoCompleteSelectField( [
33 'fieldname' => 'Test',
34 'autocomplete' => $this->options
,
37 $attributes = $field->getAttributes( [] );
38 $this->assertEquals( array_keys( $this->options
),
39 FormatJson
::decode( $attributes['data-autocomplete'] ),
40 "The 'data-autocomplete' attribute encodes autocomplete option keys as a JSON array."
45 * Test that the optional select dropdown is included or excluded based on
46 * the presence or absence of the 'options' parameter.
48 function testOptionalSelectElement() {
50 'fieldname' => 'Test',
51 'autocomplete-data' => $this->options
,
52 'options' => $this->options
,
55 $field = new HTMLAutoCompleteSelectField( $params );
56 $html = $field->getInputHTML( false );
57 $this->assertRegExp( '/select/', $html,
58 "When the 'options' parameter is set, the HTML includes a <select>" );
60 unset( $params['options'] );
61 $field = new HTMLAutoCompleteSelectField( $params );
62 $html = $field->getInputHTML( false );
63 $this->assertNotRegExp( '/select/', $html,
64 "When the 'options' parameter is not set, the HTML does not include a <select>" );