Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / htmlform / HTMLAutoCompleteSelectFieldTest.php
blob2c7f50c9c4c8ae2d338c57a5643ed3d5d64faa98
1 <?php
2 /**
3 * Unit tests for HTMLAutoCompleteSelectField
5 * @covers HTMLAutoCompleteSelectField
6 */
7 class HtmlAutoCompleteSelectFieldTest extends MediaWikiTestCase {
9 var $options = array(
10 'Bulgaria' => 'BGR',
11 'Burkina Faso' => 'BFA',
12 'Burundi' => 'BDI',
15 /**
16 * Verify that attempting to instantiate an HTMLAutoCompleteSelectField
17 * without providing any autocomplete options causes an exception to be
18 * thrown.
20 * @expectedException MWException
21 * @expectedExceptionMessage called without any autocompletions
23 function testMissingAutocompletions() {
24 new HTMLAutoCompleteSelectField( array( 'fieldname' => 'Test' ) );
27 /**
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,
37 ) );
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."
46 /**
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() {
51 $params = array(
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>" );