2
0

FormLabelTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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-2009 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 dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
  27. require_once "PHPUnit/Framework/TestCase.php";
  28. require_once "PHPUnit/Framework/TestSuite.php";
  29. require_once 'Zend/View.php';
  30. require_once 'Zend/View/Helper/FormLabel.php';
  31. /**
  32. * Test class for Zend_View_Helper_FormLabel.
  33. * Generated by PHPUnit_Util_Skeleton on 2007-05-16 at 16:09:28.
  34. *
  35. * @category Zend
  36. * @package Zend_View
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_View
  41. * @group Zend_View_Helper
  42. */
  43. class Zend_View_Helper_FormLabelTest extends PHPUnit_Framework_TestCase
  44. {
  45. /**
  46. * Runs the test methods of this class.
  47. *
  48. * @access public
  49. * @static
  50. */
  51. public static function main()
  52. {
  53. require_once "PHPUnit/TextUI/TestRunner.php";
  54. $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormLabelTest");
  55. $result = PHPUnit_TextUI_TestRunner::run($suite);
  56. }
  57. /**
  58. * Sets up the fixture, for example, open a network connection.
  59. * This method is called before a test is executed.
  60. *
  61. * @access protected
  62. */
  63. protected function setUp()
  64. {
  65. $this->view = new Zend_View();
  66. $this->helper = new Zend_View_Helper_FormLabel();
  67. $this->helper->setView($this->view);
  68. }
  69. /**
  70. * Tears down the fixture, for example, close a network connection.
  71. * This method is called after a test is executed.
  72. *
  73. * @access protected
  74. */
  75. protected function tearDown()
  76. {
  77. }
  78. public function testFormLabelWithSaneInput()
  79. {
  80. $label = $this->helper->formLabel('foo', 'bar');
  81. $this->assertEquals('<label for="foo">bar</label>', $label);
  82. }
  83. public function testFormLabelWithInputNeedingEscapesUsesViewEscaping()
  84. {
  85. $label = $this->helper->formLabel('<&foo', '</bar>');
  86. $expected = '<label for="' . $this->view->escape('<&foo') . '">' . $this->view->escape('</bar>') . '</label>';
  87. $this->assertEquals($expected, $label);
  88. }
  89. public function testViewIsSetAndSameAsCallingViewObject()
  90. {
  91. $this->assertTrue(isset($this->helper->view));
  92. $this->assertTrue($this->helper->view instanceof Zend_View_Interface);
  93. $this->assertSame($this->view, $this->helper->view);
  94. }
  95. public function testAttribsAreSet()
  96. {
  97. $label = $this->helper->formLabel('foo', 'bar', array('class' => 'baz'));
  98. $this->assertEquals('<label for="foo" class="baz">bar</label>', $label);
  99. }
  100. public function testNameAndIdForZF2154()
  101. {
  102. $label = $this->helper->formLabel('name', 'value', array('id' => 'id'));
  103. $this->assertEquals('<label for="id">value</label>', $label);
  104. }
  105. /**
  106. * @group ZF-2473
  107. */
  108. public function testCanDisableEscapingLabelValue()
  109. {
  110. $label = $this->helper->formLabel('foo', '<b>Label This!</b>', array('escape' => false));
  111. $this->assertContains('<b>Label This!</b>', $label);
  112. $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'escape' => false));
  113. $this->assertContains('<b>Label This!</b>', $label);
  114. $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'attribs' => array('escape' => false)));
  115. $this->assertContains('<b>Label This!</b>', $label);
  116. }
  117. /**
  118. * @group ZF-6426
  119. */
  120. public function testHelperShouldAllowSuppressionOfForAttribute()
  121. {
  122. $label = $this->helper->formLabel('foo', 'bar', array('disableFor' => true));
  123. $this->assertNotContains('for="foo"', $label);
  124. }
  125. /**
  126. * @group ZF-8265
  127. */
  128. public function testShouldNotRenderDisableForAttributeIfForIsSuppressed()
  129. {
  130. $label = $this->helper->formLabel('foo', 'bar', array('disableFor' => true));
  131. $this->assertNotContains('disableFor=', $label, 'Output contains disableFor attribute!');
  132. }
  133. }
  134. // Call Zend_View_Helper_FormLabelTest::main() if this source file is executed directly.
  135. if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormLabelTest::main") {
  136. Zend_View_Helper_FormLabelTest::main();
  137. }