FormLabelTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // Call Zend_View_Helper_FormLabelTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormLabelTest::main");
  5. }
  6. require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  7. require_once "PHPUnit/Framework/TestCase.php";
  8. require_once "PHPUnit/Framework/TestSuite.php";
  9. require_once 'Zend/View.php';
  10. require_once 'Zend/View/Helper/FormLabel.php';
  11. /**
  12. * Test class for Zend_View_Helper_FormLabel.
  13. * Generated by PHPUnit_Util_Skeleton on 2007-05-16 at 16:09:28.
  14. */
  15. class Zend_View_Helper_FormLabelTest extends PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * Runs the test methods of this class.
  19. *
  20. * @access public
  21. * @static
  22. */
  23. public static function main()
  24. {
  25. require_once "PHPUnit/TextUI/TestRunner.php";
  26. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormLabelTest");
  27. $result = PHPUnit_TextUI_TestRunner::run($suite);
  28. }
  29. /**
  30. * Sets up the fixture, for example, open a network connection.
  31. * This method is called before a test is executed.
  32. *
  33. * @access protected
  34. */
  35. protected function setUp()
  36. {
  37. $this->view = new Zend_View();
  38. $this->helper = new Zend_View_Helper_FormLabel();
  39. $this->helper->setView($this->view);
  40. }
  41. /**
  42. * Tears down the fixture, for example, close a network connection.
  43. * This method is called after a test is executed.
  44. *
  45. * @access protected
  46. */
  47. protected function tearDown()
  48. {
  49. }
  50. public function testFormLabelWithSaneInput()
  51. {
  52. $label = $this->helper->formLabel('foo', 'bar');
  53. $this->assertEquals('<label for="foo">bar</label>', $label);
  54. }
  55. public function testFormLabelWithInputNeedingEscapesUsesViewEscaping()
  56. {
  57. $label = $this->helper->formLabel('<&foo', '</bar>');
  58. $expected = '<label for="' . $this->view->escape('<&foo') . '">' . $this->view->escape('</bar>') . '</label>';
  59. $this->assertEquals($expected, $label);
  60. }
  61. public function testViewIsSetAndSameAsCallingViewObject()
  62. {
  63. $this->assertTrue(isset($this->helper->view));
  64. $this->assertTrue($this->helper->view instanceof Zend_View_Interface);
  65. $this->assertSame($this->view, $this->helper->view);
  66. }
  67. public function testAttribsAreSet()
  68. {
  69. $label = $this->helper->formLabel('foo', 'bar', array('class' => 'baz'));
  70. $this->assertEquals('<label for="foo" class="baz">bar</label>', $label);
  71. }
  72. public function testNameAndIdForZF2154()
  73. {
  74. $label = $this->helper->formLabel('name', 'value', array('id' => 'id'));
  75. $this->assertEquals('<label for="id">value</label>', $label);
  76. }
  77. /**
  78. * ZF-2473
  79. */
  80. public function testCanDisableEscapingLabelValue()
  81. {
  82. $label = $this->helper->formLabel('foo', '<b>Label This!</b>', array('escape' => false));
  83. $this->assertContains('<b>Label This!</b>', $label);
  84. $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'escape' => false));
  85. $this->assertContains('<b>Label This!</b>', $label);
  86. $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'attribs' => array('escape' => false)));
  87. $this->assertContains('<b>Label This!</b>', $label);
  88. }
  89. }
  90. // Call Zend_View_Helper_FormLabelTest::main() if this source file is executed directly.
  91. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormLabelTest::main") {
  92. Zend_View_Helper_FormLabelTest::main();
  93. }