public function testCanGetMessagesOfNestedFormsWithMultiLevelElementsBelongingToArrays() { $form = new Form(); $form->setElementsBelongTo('foo[bar]'); $form->addElement('text', 'firstName')->getElement('firstName')->setRequired(false); $form->addElement('text', 'lastName')->getElement('lastName')->setRequired(true); $subForm = new \Zend\Form\SubForm(); $subForm->setElementsBelongTo('baz'); $subForm->addElement('text', 'email')->getElement('email')->setRequired(true)->addValidator('NotEmpty'); $subSubForm = new \Zend\Form\SubForm(); $subSubForm->setElementsBelongTo('bat[quux]'); $subSubForm->addElement('checkbox', 'home')->getElement('home')->setRequired(true)->addValidator('InArray', false, array(array('1'))); $subForm->addSubForm($subSubForm, 'subSub'); $form->addSubForm($subForm, 'sub')->addElement('submit', 'save', array('value' => 'submit')); $data = array('foo' => array('bar' => array('lastName' => 'Cow'))); $form->sub->subSub->home->addValidator('StringLength', false, array(4, 6)); $data['foo']['bar']['baz'] = array('bat' => array('quux' => array('home' => 'ab'))); $form->isValidPartial($data); $messages = $form->getMessages(); $this->assertFalse(empty($messages)); $this->assertTrue(isset($messages['foo']['bar']['baz']['bat']['quux']['home']), var_export($messages, 1)); $this->assertTrue(isset($messages['foo']['bar']['baz']['bat']['quux']['home']['notInArray']), var_export($messages, 1)); }
public function testEachSubFormShouldBePrepared() { $subForm = new SubForm(); $subSubForm = new SubForm(); $subForm->addSubForm($subSubForm, "subSubForm"); $this->form->addSubForm($subForm, "subForm"); $this->form->render(); $this->assertEquals("subForm[subSubForm]", $this->form->getSubForm("subForm")->getSubForm("subSubForm")->getElementsBelongTo()); }