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
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class HTMLFormTest extends MediaWikiIntegrationTestCase {
|
2016-04-21 05:39:08 +00:00
|
|
|
|
|
|
|
|
private function newInstance() {
|
2020-02-09 17:06:12 +00:00
|
|
|
$context = new RequestContext();
|
|
|
|
|
$out = new OutputPage( $context );
|
|
|
|
|
$out->setTitle( Title::newMainPage() );
|
|
|
|
|
$context->setOutput( $out );
|
|
|
|
|
$form = new HTMLForm( [], $context );
|
2016-04-27 10:28:55 +00:00
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetHTML_noPrepare() {
|
2016-04-21 05:39:08 +00:00
|
|
|
$form = $this->newInstance();
|
2019-10-11 22:22:26 +00:00
|
|
|
$this->expectException( LogicException::class );
|
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();
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringNotContainsString( 'autocomplete', $form->wrapForm( '' ) );
|
2016-04-21 05:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAutocompleteWhenSetToNull() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$form->setAutocomplete( null );
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringNotContainsString( 'autocomplete', $form->wrapForm( '' ) );
|
2016-04-21 05:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAutocompleteWhenSetToFalse() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
// Previously false was used instead of null to indicate the attribute should not be set
|
|
|
|
|
$form->setAutocomplete( false );
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringNotContainsString( 'autocomplete', $form->wrapForm( '' ) );
|
2016-04-21 05:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAutocompleteWhenSetToOff() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$form->setAutocomplete( 'off' );
|
2019-12-14 10:27:56 +00:00
|
|
|
$this->assertStringContainsString( ' autocomplete="off"', $form->wrapForm( '' ) );
|
2016-04-21 05:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-09 14:30:06 +00:00
|
|
|
public function testGetPreText() {
|
|
|
|
|
$preText = 'TEST';
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$form->setPreText( $preText );
|
|
|
|
|
$this->assertSame( $preText, $form->getPreText() );
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-09 17:06:12 +00:00
|
|
|
public function testGetErrorsOrWarningsWithRawParams() {
|
|
|
|
|
$form = $this->newInstance();
|
|
|
|
|
$msg = new RawMessage( 'message with $1' );
|
|
|
|
|
$msg->rawParams( '<a href="raw">params</a>' );
|
|
|
|
|
$status = Status::newFatal( $msg );
|
|
|
|
|
|
|
|
|
|
$result = $form->getErrorsOrWarnings( $status, 'error' );
|
|
|
|
|
|
|
|
|
|
$this->assertStringContainsString( 'message with <a href="raw">params</a>', $result );
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-27 10:28:55 +00:00
|
|
|
}
|