HTMLFormTest.php 1.6 KB

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