ZF-8265: do not render disableFor key in attributes (patch courtesy Mon Zafra)
[zend/radio.git] / tests / Zend / View / Helper / FormLabelTest.php
blobde0f0c18e14a53feca1cc0c992d19bb3bbceb434
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
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$
23 // Call Zend_View_Helper_FormLabelTest::main() if this source file is executed directly.
24 if (!defined("PHPUnit_MAIN_METHOD")) {
25 define("PHPUnit_MAIN_METHOD", "Zend_View_Helper_FormLabelTest::main");
28 require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/TestHelper.php';
29 require_once "PHPUnit/Framework/TestCase.php";
30 require_once "PHPUnit/Framework/TestSuite.php";
32 require_once 'Zend/View.php';
33 require_once 'Zend/View/Helper/FormLabel.php';
35 /**
36 * Test class for Zend_View_Helper_FormLabel.
37 * Generated by PHPUnit_Util_Skeleton on 2007-05-16 at 16:09:28.
39 * @category Zend
40 * @package Zend_View
41 * @subpackage UnitTests
42 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
43 * @license http://framework.zend.com/license/new-bsd New BSD License
44 * @group Zend_View
45 * @group Zend_View_Helper
47 class Zend_View_Helper_FormLabelTest extends PHPUnit_Framework_TestCase
49 /**
50 * Runs the test methods of this class.
52 * @access public
53 * @static
55 public static function main()
57 require_once "PHPUnit/TextUI/TestRunner.php";
59 $suite = new PHPUnit_Framework_TestSuite("Zend_View_Helper_FormLabelTest");
60 $result = PHPUnit_TextUI_TestRunner::run($suite);
63 /**
64 * Sets up the fixture, for example, open a network connection.
65 * This method is called before a test is executed.
67 * @access protected
69 protected function setUp()
71 $this->view = new Zend_View();
72 $this->helper = new Zend_View_Helper_FormLabel();
73 $this->helper->setView($this->view);
76 /**
77 * Tears down the fixture, for example, close a network connection.
78 * This method is called after a test is executed.
80 * @access protected
82 protected function tearDown()
86 public function testFormLabelWithSaneInput()
88 $label = $this->helper->formLabel('foo', 'bar');
89 $this->assertEquals('<label for="foo">bar</label>', $label);
92 public function testFormLabelWithInputNeedingEscapesUsesViewEscaping()
94 $label = $this->helper->formLabel('<&foo', '</bar>');
95 $expected = '<label for="' . $this->view->escape('<&foo') . '">' . $this->view->escape('</bar>') . '</label>';
96 $this->assertEquals($expected, $label);
99 public function testViewIsSetAndSameAsCallingViewObject()
101 $this->assertTrue(isset($this->helper->view));
102 $this->assertTrue($this->helper->view instanceof Zend_View_Interface);
103 $this->assertSame($this->view, $this->helper->view);
106 public function testAttribsAreSet()
108 $label = $this->helper->formLabel('foo', 'bar', array('class' => 'baz'));
109 $this->assertEquals('<label for="foo" class="baz">bar</label>', $label);
112 public function testNameAndIdForZF2154()
114 $label = $this->helper->formLabel('name', 'value', array('id' => 'id'));
115 $this->assertEquals('<label for="id">value</label>', $label);
119 * @group ZF-2473
121 public function testCanDisableEscapingLabelValue()
123 $label = $this->helper->formLabel('foo', '<b>Label This!</b>', array('escape' => false));
124 $this->assertContains('<b>Label This!</b>', $label);
125 $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'escape' => false));
126 $this->assertContains('<b>Label This!</b>', $label);
127 $label = $this->helper->formLabel(array('name' => 'foo', 'value' => '<b>Label This!</b>', 'attribs' => array('escape' => false)));
128 $this->assertContains('<b>Label This!</b>', $label);
132 * @group ZF-6426
134 public function testHelperShouldAllowSuppressionOfForAttribute()
136 $label = $this->helper->formLabel('foo', 'bar', array('disableFor' => true));
137 $this->assertNotContains('for="foo"', $label);
141 * @group ZF-8265
143 public function testShouldNotRenderDisableForAttributeIfForIsSuppressed()
145 $label = $this->helper->formLabel('foo', 'bar', array('disableFor' => true));
146 $this->assertNotContains('disableFor=', $label, 'Output contains disableFor attribute!');
150 // Call Zend_View_Helper_FormLabelTest::main() if this source file is executed directly.
151 if (PHPUnit_MAIN_METHOD == "Zend_View_Helper_FormLabelTest::main") {
152 Zend_View_Helper_FormLabelTest::main();