FormOptionsInitializationTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * This file host two test case classes for the MediaWiki FormOptions class:
  4. * - FormOptionsInitializationTest : tests initialization of the class.
  5. * - FormOptionsTest : tests methods an on instance
  6. *
  7. * The split let us take advantage of setting up a fixture for the methods
  8. * tests.
  9. */
  10. /**
  11. * Dummy class to makes FormOptions::$options public.
  12. * Used by FormOptionsInitializationTest which need to verify the $options
  13. * array is correctly set through the FormOptions::add() function.
  14. */
  15. class FormOptionsExposed extends FormOptions {
  16. public function getOptions() {
  17. return $this->options;
  18. }
  19. }
  20. /**
  21. * Test class for FormOptions initialization
  22. * Ensure the FormOptions::add() does what we want it to do.
  23. *
  24. * Copyright © 2011, Antoine Musso
  25. *
  26. * @author Antoine Musso
  27. */
  28. class FormOptionsInitializationTest extends MediaWikiTestCase {
  29. /**
  30. * @var FormOptions
  31. */
  32. protected $object;
  33. /**
  34. * A new fresh and empty FormOptions object to test initialization
  35. * with.
  36. */
  37. protected function setUp() {
  38. parent::setUp();
  39. $this->object = new FormOptionsExposed();
  40. }
  41. /**
  42. * @covers FormOptionsExposed::add
  43. */
  44. public function testAddStringOption() {
  45. $this->object->add( 'foo', 'string value' );
  46. $this->assertEquals(
  47. [
  48. 'foo' => [
  49. 'default' => 'string value',
  50. 'consumed' => false,
  51. 'type' => FormOptions::STRING,
  52. 'value' => null,
  53. ]
  54. ],
  55. $this->object->getOptions()
  56. );
  57. }
  58. /**
  59. * @covers FormOptionsExposed::add
  60. */
  61. public function testAddIntegers() {
  62. $this->object->add( 'one', 1 );
  63. $this->object->add( 'negone', -1 );
  64. $this->assertEquals(
  65. [
  66. 'negone' => [
  67. 'default' => -1,
  68. 'value' => null,
  69. 'consumed' => false,
  70. 'type' => FormOptions::INT,
  71. ],
  72. 'one' => [
  73. 'default' => 1,
  74. 'value' => null,
  75. 'consumed' => false,
  76. 'type' => FormOptions::INT,
  77. ]
  78. ],
  79. $this->object->getOptions()
  80. );
  81. }
  82. }