Пример #1
0
 /**
  * Ensures that name does not contain brackets [] to be able to address it
  * via plain name
  *
  * @throws FormException In case the name of the control contains brackets.
  *
  * @author Ralf Schubert
  * @version
  * Version 0.1, 24.01.2014<br />
  */
 public function onParseTime()
 {
     $name = $this->getAttribute('name');
     if (substr($name, -2) === '[]') {
         $form = $this->getForm();
         $doc = $form->getParentObject();
         $docCon = get_class($doc->getDocumentController());
         throw new FormException('[FileUploadTag::onParseTime()] The attribute "name" of the ' . '&lt;form:file /&gt; tag with name "' . $name . '" in form "' . $form->getAttribute('name') . '" and document ' . 'controller "' . $docCon . '" must not contain brackets! Please ensure, that the ' . 'appropriate form control has a suitable name. The brackets are automatically ' . 'generated by the taglib if needed!', E_USER_ERROR);
     }
     parent::onParseTime();
 }
Пример #2
0
 /**
  * @return TextFieldTag
  */
 protected function getTextField()
 {
     $field = new TextFieldTag();
     $field->setAttribute('name', self::FIELD_NAME);
     return $field;
 }
Пример #3
0
 public function onAfterAppend()
 {
     parent::onAfterAppend();
     $this->onAfterAppendExecuted = true;
 }
Пример #4
0
 /**
  * Tests form transformation with a simple and a more sophisticated example.
  */
 public function testTransform()
 {
     $form = new HtmlFormTag();
     $form->setParentObject(new Document());
     $form->setAction('/some-url');
     // setup reflection property to be able to inject the DOM structure to test
     $children = new ReflectionProperty(Document::class, 'children');
     $children->setAccessible(true);
     // set up group
     $group = new FormGroupTag();
     $group->setObjectId(XmlParser::generateUniqID());
     $group->setParentObject($form);
     // set up fields
     $user = new TextFieldTag();
     $user->setObjectId(XmlParser::generateUniqID());
     $user->setAttributes(['name' => 'user', 'value' => 'some user']);
     $user->setParentObject($form);
     $pass = new TextFieldTag();
     $pass->setObjectId(XmlParser::generateUniqID());
     $pass->setAttributes(['name' => 'pass', 'value' => 'some pass']);
     $pass->setParentObject($group);
     $button = new ButtonTag();
     $button->setObjectId(XmlParser::generateUniqID());
     $button->setAttributes(['name' => 'submit', 'value' => 'submit']);
     $button->setParentObject($form);
     // assemble group
     $children->setValue($group, array_merge($children->getValue($group), [$pass->getObjectId() => $pass]));
     $group->setContent('<div class="pass"><' . $pass->getObjectId() . ' /></div>');
     // assemble form
     $children->setValue($form, [$user->getObjectId() => $user, $group->getObjectId() => $group, $button->getObjectId() => $button]);
     $form->setContent('<p><' . $user->getObjectId() . ' /></p><' . $group->getObjectId() . ' /><' . $button->getObjectId() . ' />');
     // build children explicitly up and then check for HTML code...
     $actual = $form->transformForm();
     // general structure
     $this->assertContains('<form ', $actual);
     $this->assertContains('</form>', $actual);
     $this->assertContains('action="/some-url"', $actual);
     $this->assertContains('<input type="text" name="user" value="some user" />', $actual);
     $this->assertContains('<input type="text" name="pass" value="some pass" />', $actual);
     $this->assertContains('<input type="submit" name="submit" value="submit" />', $actual);
     $this->assertContains('<p>', $actual);
     $this->assertContains('</p>', $actual);
     $this->assertContains('<div class="pass">', $actual);
     $this->assertContains('</div>', $actual);
 }