Exemple #1
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testGetName()
 {
     $element = new Element('test[]');
     $this->assertEquals('test', $element->getInputName());
     $this->assertEquals('test[]', $element->setMultiple(true)->getInputName());
     $element = new Element('test', array(), new \ArrayObject(array('opt1' => 'value')));
     $this->assertEquals('test', $element->getName());
     $this->assertEquals('test', $element->getNameFromMixed(array('name' => 'test')));
     $this->assertEquals('test', $element->getNameFromMixed('test'));
     $this->assertEquals('test', $element->getNameFromMixed($element));
     $element = new Element();
     $this->assertEquals(null, $element->getName());
     $element->setName('name');
     $this->assertEquals('name', $element->getName());
     $element = new Element();
     $this->assertEquals(null, $element->getInputName());
     $this->assertEquals(null, $element->setMultiple(true)->getInputName());
     $element->setName('test_name');
     $this->assertEquals('test_name[]', $element->setMultiple(true)->getInputName());
     $this->assertEquals('test_name', $element->setMultiple(false)->getInputName());
     $fieldset = new Fieldset('fieldset');
     $fieldset->add($element);
     $form = new Fieldset('form[]');
     $form->add($fieldset);
     $this->assertEquals('fieldset[test_name]', $element->setMultiple(false)->getInputName());
     $this->assertEquals('fieldset[test_name][]', $element->setMultiple(true)->getInputName());
     $form->setMultiple(true);
     $this->assertEquals('form[][fieldset][test_name]', $element->setMultiple(false)->getInputName());
     $this->assertEquals('form[][fieldset][test_name][]', $element->setMultiple(true)->getInputName());
     $form->setMultiple(false);
     $fieldset->setMultiple(true);
     $this->assertEquals('fieldset[][test_name]', $element->setMultiple(false)->getInputName());
     $this->assertEquals('fieldset[][test_name][]', $element->setMultiple(true)->getInputName());
     $form->setMultiple(true);
     $this->assertEquals('form[][fieldset][][test_name]', $element->setMultiple(false)->getInputName());
     $this->assertEquals('form[][fieldset][][test_name][]', $element->setMultiple(true)->getInputName());
     // exception
     $this->assertEquals('test', $element->getNameFromMixed(new \stdClass()));
 }