fieldset.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * Fieldset class tests
  15. *
  16. * @group Core
  17. * @group Fieldset
  18. */
  19. class Test_Fieldset extends TestCase
  20. {
  21. public static function setUpBeforeClass()
  22. {
  23. // set Request::$main
  24. $request = \Request::forge('welcome/index');
  25. $rp = new \ReflectionProperty($request, 'main');
  26. $rp->setAccessible(true);
  27. $rp->setValue($request, $request);
  28. }
  29. public static function tearDownAfterClass()
  30. {
  31. // reset Request::$main
  32. $request = \Request::forge();
  33. $rp = new \ReflectionProperty($request, 'main');
  34. $rp->setAccessible(true);
  35. $rp->setValue($request, false);
  36. }
  37. /**
  38. * Test of "for" attribute in label tag
  39. */
  40. public function test_for_in_label()
  41. {
  42. $form = Fieldset::forge(__METHOD__);
  43. $ops = array('male', 'female');
  44. $form->add('gender', '', array(
  45. 'options' => $ops, 'type' => 'radio', 'value' => 1
  46. ));
  47. $output = $form->build();
  48. $output = str_replace(array("\n", "\t"), "", $output);
  49. $expected = '<form action="welcome/index" accept-charset="utf-8" method="post"><table><tr><td class=""></td><td class=""><input type="radio" value="0" id="form_gender_0" name="gender" /> <label for="form_gender_0">male</label><br /><input type="radio" value="1" id="form_gender_1" name="gender" checked="checked" /> <label for="form_gender_1">female</label><br /><span></span></td></tr></table></form>';
  50. $this->assertEquals($expected, $output);
  51. }
  52. }