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.
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
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';
36 * Test class for Zend_View_Helper_FormLabel.
37 * Generated by PHPUnit_Util_Skeleton on 2007-05-16 at 16:09:28.
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
45 * @group Zend_View_Helper
47 class Zend_View_Helper_FormLabelTest
extends PHPUnit_Framework_TestCase
50 * Runs the test methods of this class.
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);
64 * Sets up the fixture, for example, open a network connection.
65 * This method is called before a test is executed.
69 protected function setUp()
71 $this->view
= new Zend_View();
72 $this->helper
= new Zend_View_Helper_FormLabel();
73 $this->helper
->setView($this->view
);
77 * Tears down the fixture, for example, close a network connection.
78 * This method is called after a test is executed.
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);
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);
134 public function testHelperShouldAllowSuppressionOfForAttribute()
136 $label = $this->helper
->formLabel('foo', 'bar', array('disableFor' => true));
137 $this->assertNotContains('for="foo"', $label);
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();