2016-04-27 10:28:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
2017-12-25 04:05:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers HTMLForm
|
2016-04-21 05:39:08 +00:00
|
|
|
*
|
2018-05-23 23:23:42 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2016-04-21 05:39:08 +00:00
|
|
|
* @author Gergő Tisza
|
2017-12-25 04:05:52 +00:00
|
|
|
*/
|
2019-06-01 14:10:15 +00:00
|
|
|
class HTMLFormTest extends \MediaWikiUnitTestCase {
|
2016-04-21 05:39:08 +00:00
|
|
|
|
|
|
|
|
private function newInstance() {
|
2016-04-27 10:28:55 +00:00
|
|
|
$form = new HTMLForm( [] );
|
|
|
|
|
$form->setTitle( Title::newFromText( 'Foo' ) );
|
2016-04-21 05:39:08 +00:00
|
|
|
return $form;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetHTML_empty() {
|
|
|
|
|
$form = $this->newInstance();
|
2016-04-27 10:28:55 +00:00
|
|
|
$form->prepareForm();
|
|
|
|
|
$html = $form->getHTML( false );
|
2016-04-21 05:39:08 +00:00
|
|
|
$this->assertStringStartsWith( '<form ', $html );
|
2016-04-27 10:28:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException LogicException
|
|
|
|
|
*/
|
|
|
|
|
public function testGetHTML_noPrepare() {
|
2016-04-21 05:39:08 +00:00
|
|
|
$form = $this->newInstance();
|
2016-04-27 10:28:55 +00:00
|
|
|
$form->getHTML( false );
|
|
|
|
|
}
|
2016-04-21 05:39:08 +00:00
|
|
|
|
|
|
|
|
public function testAutocompleteDefaultsToNull() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$this->assertNotContains( 'autocomplete', $form->wrapForm( '' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAutocompleteWhenSetToNull() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$form->setAutocomplete( null );
|
|
|
|
|
$this->assertNotContains( 'autocomplete', $form->wrapForm( '' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAutocompleteWhenSetToFalse() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
// Previously false was used instead of null to indicate the attribute should not be set
|
|
|
|
|
$form->setAutocomplete( false );
|
|
|
|
|
$this->assertNotContains( 'autocomplete', $form->wrapForm( '' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAutocompleteWhenSetToOff() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$form->setAutocomplete( 'off' );
|
|
|
|
|
$this->assertContains( ' autocomplete="off"', $form->wrapForm( '' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-09 14:30:06 +00:00
|
|
|
public function testGetPreText() {
|
|
|
|
|
$preText = 'TEST';
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$form->setPreText( $preText );
|
|
|
|
|
$this->assertSame( $preText, $form->getPreText() );
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-27 10:28:55 +00:00
|
|
|
}
|