| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Form
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Zend_Form_SubFormTest::main');
- }
- // error_reporting(E_ALL);
- require_once 'Zend/Form/SubForm.php';
- require_once 'Zend/View.php';
- require_once 'Zend/Version.php';
- /**
- * @category Zend
- * @package Zend_Form
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Form
- */
- class Zend_Form_SubFormTest extends PHPUnit_Framework_TestCase
- {
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite('Zend_Form_SubFormTest');
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- public function setUp()
- {
- Zend_Form::setDefaultTranslator(null);
- $this->form = new Zend_Form_SubForm();
- }
- public function tearDown()
- {
- }
- // General
- public function testSubFormUtilizesDefaultDecorators()
- {
- $decorators = $this->form->getDecorators();
- $this->assertTrue(array_key_exists('Zend_Form_Decorator_FormElements', $decorators));
- $this->assertTrue(array_key_exists('Zend_Form_Decorator_HtmlTag', $decorators));
- $this->assertTrue(array_key_exists('Zend_Form_Decorator_Fieldset', $decorators));
- $this->assertTrue(array_key_exists('Zend_Form_Decorator_DtDdWrapper', $decorators));
- $htmlTag = $decorators['Zend_Form_Decorator_HtmlTag'];
- $tag = $htmlTag->getOption('tag');
- $this->assertEquals('dl', $tag);
- }
- public function testSubFormIsArrayByDefault()
- {
- $this->assertTrue($this->form->isArray());
- }
- public function testElementsBelongToSubFormNameByDefault()
- {
- $this->testSubFormIsArrayByDefault();
- $this->form->setName('foo');
- $this->assertEquals($this->form->getName(), $this->form->getElementsBelongTo());
- }
- // Extensions
- public function testInitCalledBeforeLoadDecorators()
- {
- $form = new Zend_Form_SubFormTest_SubForm();
- $decorators = $form->getDecorators();
- $this->assertTrue(empty($decorators));
- }
- // Bugfixes
- /**
- * @group ZF-2883
- */
- public function testDisplayGroupsShouldInheritSubFormNamespace()
- {
- $this->form->addElement('text', 'foo')
- ->addElement('text', 'bar')
- ->addDisplayGroup(array('foo', 'bar'), 'foobar');
- $form = new Zend_Form();
- $form->addSubForm($this->form, 'attributes');
- $html = $form->render(new Zend_View());
- $this->assertContains('name="attributes[foo]"', $html);
- $this->assertContains('name="attributes[bar]"', $html);
- }
- /**
- * @group ZF-3272
- */
- public function testRenderedSubFormDtShouldContainNoBreakSpace()
- {
- $subForm = new Zend_Form_SubForm(array(
- 'elements' => array(
- 'foo' => 'text',
- 'bar' => 'text',
- ),
- ));
- $form = new Zend_Form();
- $form->addSubForm($subForm, 'foobar')
- ->setView(new Zend_View);
- $html = $form->render();
- $this->assertContains('> </dt>', $html );
- }
- /**
- * Prove the fluent interface on Zend_Form_Subform::loadDefaultDecorators
- *
- * @link http://framework.zend.com/issues/browse/ZF-9913
- * @return void
- */
- public function testFluentInterfaceOnLoadDefaultDecorators()
- {
- $this->assertSame($this->form, $this->form->loadDefaultDecorators());
- }
- /**
- * @see ZF-11504
- */
- public function testSubFormWithNumericName()
- {
- $subForm = new Zend_Form_SubForm(array(
- 'elements' => array(
- 'foo' => 'text',
- 'bar' => 'text',
- ),
- ));
- $form = new Zend_Form();
- $form->addSubForm($subForm, 0);
- $form->addSubForm($subForm, 234);
- $form2 = clone $form;
- $this->assertEquals($form2->getSubForm(234)->getName(),234);
- $this->assertEquals($form2->getSubForm(0)->getName(),0);
- }
- }
- class Zend_Form_SubFormTest_SubForm extends Zend_Form_SubForm
- {
- public function init()
- {
- $this->setDisableLoadDefaultDecorators(true);
- }
- }
- if (PHPUnit_MAIN_METHOD == 'Zend_Form_SubFormTest::main') {
- Zend_Form_SubFormTest::main();
- }
|