FormLabelTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_View_Helper_FormLabelTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormLabelTest::main");
  25. }
  26. require_once 'Zend/View.php';
  27. require_once 'Zend/View/Helper/FormLabel.php';
  28. /**
  29. * Test class for Zend_View_Helper_FormLabel.
  30. * Generated by PHPUnit_Util_Skeleton on 2007-05-16 at 16:09:28.
  31. *
  32. * @category Zend
  33. * @package Zend_View
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_View
  38. * @group Zend_View_Helper
  39. */
  40. class Zend_View_Helper_FormLabelTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * Runs the test methods of this class.
  44. *
  45. * @access public
  46. * @static
  47. */
  48. public static function main()
  49. {
  50. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormLabelTest");
  51. $result = PHPUnit_TextUI_TestRunner::run($suite);
  52. }
  53. /**
  54. * Sets up the fixture, for example, open a network connection.
  55. * This method is called before a test is executed.
  56. *
  57. * @access protected
  58. */
  59. protected function setUp()
  60. {
  61. $this->view = new Zend_View();
  62. $this->helper = new Zend_View_Helper_FormLabel();
  63. $this->helper->setView($this->view);
  64. }
  65. /**
  66. * Tears down the fixture, for example, close a network connection.
  67. * This method is called after a test is executed.
  68. *
  69. * @access protected
  70. */
  71. protected function tearDown()
  72. {
  73. }
  74. public function testFormLabelWithSaneInput()
  75. {
  76. $label = $this->helper->formLabel('foo', 'bar');
  77. $this->assertEquals('<label for="foo">bar</label>', $label);
  78. }
  79. public function testFormLabelWithInputNeedingEscapesUsesViewEscaping()
  80. {
  81. $label = $this->helper->formLabel('<&foo', '</bar>');
  82. $expected = '<label for="' . $this->view->escape('<&foo') . '">' . $this->view->escape('</bar>') . '</label>';
  83. $this->assertEquals($expected, $label);
  84. }
  85. public function testViewIsSetAndSameAsCallingViewObject()
  86. {
  87. $this->assertTrue(isset($this->helper->view));
  88. $this->assertTrue($this->helper->view instanceof Zend_View_Interface);
  89. $this->assertSame($this->view, $this->helper->view);
  90. }
  91. public function testAttribsAreSet()
  92. {
  93. $label = $this->helper->formLabel('foo', 'bar', array('class' => 'baz'));
  94. $this->assertEquals('<label for="foo" class="baz">bar</label>', $label);
  95. }
  96. public function testNameAndIdForZF2154()
  97. {
  98. $label = $this->helper->formLabel('name', 'value', array('id' => 'id'));
  99. $this->assertEquals('<label for="id">value</label>', $label);
  100. }
  101. /**
  102. * @group ZF-2473
  103. */
  104. public function testCanDisableEscapingLabelValue()
  105. {
  106. $label = $this->helper->formLabel('foo', '<b>Label This!</b>', array('escape' => false));
  107. $this->assertContains('<b>Label This!</b>', $label);
  108. $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'escape' => false));
  109. $this->assertContains('<b>Label This!</b>', $label);
  110. $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'attribs' => array('escape' => false)));
  111. $this->assertContains('<b>Label This!</b>', $label);
  112. }
  113. /**
  114. * @group ZF-6426
  115. */
  116. public function testHelperShouldAllowSuppressionOfForAttribute()
  117. {
  118. $label = $this->helper->formLabel('foo', 'bar', array('disableFor' => true));
  119. $this->assertNotContains('for="foo"', $label);
  120. }
  121. /**
  122. * @group ZF-8265
  123. */
  124. public function testShouldNotRenderDisableForAttributeIfForIsSuppressed()
  125. {
  126. $label = $this->helper->formLabel('foo', 'bar', array('disableFor' => true));
  127. $this->assertNotContains('disableFor=', $label, 'Output contains disableFor attribute!');
  128. }
  129. }
  130. // Call Zend_View_Helper_FormLabelTest::main() if this source file is executed directly.
  131. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormLabelTest::main") {
  132. Zend_View_Helper_FormLabelTest::main();
  133. }