MediaWiki
REL1_24
|
00001 <?php 00007 class HtmlAutoCompleteSelectFieldTest extends MediaWikiTestCase { 00008 00009 var $options = array( 00010 'Bulgaria' => 'BGR', 00011 'Burkina Faso' => 'BFA', 00012 'Burundi' => 'BDI', 00013 ); 00014 00023 function testMissingAutocompletions() { 00024 new HTMLAutoCompleteSelectField( array( 'fieldname' => 'Test' ) ); 00025 } 00026 00033 function testGetAttributes() { 00034 $field = new HTMLAutoCompleteSelectField( array( 00035 'fieldname' => 'Test', 00036 'autocomplete' => $this->options, 00037 ) ); 00038 00039 $attributes = $field->getAttributes( array() ); 00040 $this->assertEquals( array_keys( $this->options ), 00041 FormatJson::decode( $attributes['data-autocomplete'] ), 00042 "The 'data-autocomplete' attribute encodes autocomplete option keys as a JSON array." 00043 ); 00044 } 00045 00050 function testOptionalSelectElement() { 00051 $params = array( 00052 'fieldname' => 'Test', 00053 'autocomplete' => $this->options, 00054 'options' => $this->options, 00055 ); 00056 00057 $field = new HTMLAutoCompleteSelectField( $params ); 00058 $html = $field->getInputHTML( false ); 00059 $this->assertRegExp( '/select/', $html, 00060 "When the 'options' parameter is set, the HTML includes a <select>" ); 00061 00062 unset( $params['options'] ); 00063 $field = new HTMLAutoCompleteSelectField( $params ); 00064 $html = $field->getInputHTML( false ); 00065 $this->assertNotRegExp( '/select/', $html, 00066 "When the 'options' parameter is not set, the HTML does not include a <select>" ); 00067 } 00068 }