Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / htmlform / HTMLFormTest.php
1 <?php
2
3 /**
4 * @covers HTMLForm
5 *
6 * @license GPL-2.0-or-later
7 * @author Gergő Tisza
8 */
9 class HTMLFormTest extends \MediaWikiUnitTestCase {
10
11 private function newInstance() {
12 $form = new HTMLForm( [] );
13 $form->setTitle( Title::newFromText( 'Foo' ) );
14 return $form;
15 }
16
17 public function testGetHTML_empty() {
18 $form = $this->newInstance();
19 $form->prepareForm();
20 $html = $form->getHTML( false );
21 $this->assertStringStartsWith( '<form ', $html );
22 }
23
24 /**
25 * @expectedException LogicException
26 */
27 public function testGetHTML_noPrepare() {
28 $form = $this->newInstance();
29 $form->getHTML( false );
30 }
31
32 public function testAutocompleteDefaultsToNull() {
33 $form = $this->newInstance();
34 $this->assertNotContains( 'autocomplete', $form->wrapForm( '' ) );
35 }
36
37 public function testAutocompleteWhenSetToNull() {
38 $form = $this->newInstance();
39 $form->setAutocomplete( null );
40 $this->assertNotContains( 'autocomplete', $form->wrapForm( '' ) );
41 }
42
43 public function testAutocompleteWhenSetToFalse() {
44 $form = $this->newInstance();
45 // Previously false was used instead of null to indicate the attribute should not be set
46 $form->setAutocomplete( false );
47 $this->assertNotContains( 'autocomplete', $form->wrapForm( '' ) );
48 }
49
50 public function testAutocompleteWhenSetToOff() {
51 $form = $this->newInstance();
52 $form->setAutocomplete( 'off' );
53 $this->assertContains( ' autocomplete="off"', $form->wrapForm( '' ) );
54 }
55
56 public function testGetPreText() {
57 $preText = 'TEST';
58 $form = $this->newInstance();
59 $form->setPreText( $preText );
60 $this->assertSame( $preText, $form->getPreText() );
61 }
62
63 }