3 * Unit tests for HTMLAutoCompleteSelectField
5 * @covers HTMLAutoCompleteSelectField
7 class HtmlAutoCompleteSelectFieldTest
extends MediaWikiTestCase
{
11 'Burkina Faso' => 'BFA',
16 * Verify that attempting to instantiate an HTMLAutoCompleteSelectField
17 * without providing any autocomplete options causes an exception to be
20 * @expectedException MWException
21 * @expectedExceptionMessage called without any autocompletions
23 function testMissingAutocompletions() {
24 new HTMLAutoCompleteSelectField( array( 'fieldname' => 'Test' ) );
28 * Verify that the autocomplete options are correctly encoded as
29 * the 'data-autocomplete' attribute of the field.
31 * @covers HTMLAutoCompleteSelectField::getAttributes
33 function testGetAttributes() {
34 $field = new HTMLAutoCompleteSelectField( array(
35 'fieldname' => 'Test',
36 'autocomplete' => $this->options
,
39 $attributes = $field->getAttributes( array() );
40 $this->assertEquals( array_keys( $this->options
),
41 FormatJson
::decode( $attributes['data-autocomplete'] ),
42 "The 'data-autocomplete' attribute encodes autocomplete option keys as a JSON array."
47 * Test that the optional select dropdown is included or excluded based on
48 * the presence or absence of the 'options' parameter.
50 function testOptionalSelectElement() {
52 'fieldname' => 'Test',
53 'autocomplete' => $this->options
,
54 'options' => $this->options
,
57 $field = new HTMLAutoCompleteSelectField( $params );
58 $html = $field->getInputHTML( false );
59 $this->assertRegExp( '/select/', $html,
60 "When the 'options' parameter is set, the HTML includes a <select>" );
62 unset( $params['options'] );
63 $field = new HTMLAutoCompleteSelectField( $params );
64 $html = $field->getInputHTML( false );
65 $this->assertNotRegExp( '/select/', $html,
66 "When the 'options' parameter is not set, the HTML does not include a <select>" );