1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
require_once realpath(dirname(__FILE__) . '/../../../TestHelper.php');

class FormTest extends PHPUnit_Framework_TestCase
{
    public function testFrom()
    {
        //personal info (name, email, dob, etc)
        $person = new Zend_Form;
        $person->setName('Person');
        $person->addElement('text', 'name');
        //contact form
        $contact = new Zend_Form_SubForm;
        for ($i = 0; $i <= 3; $i++) {
            //for each contact, i created a subform and append it to contact form
            $contactItem = new Zend_Form_SubForm;
            $contactItem->addElement('text', 'Bar');
            $contact->addSubForm($contactItem, $i);
        }
        //so i added the contact form to the main form
        $person->addSubForm($contact, 'Contact');

        $html = $person->render(new Zend_View());
        var_dump($html);

        $this->assertContains('Contact[0][Bar]', $html);
        $this->assertNotContains('Contact[][Bar]', $html);
    }
}