Permalink
Browse files

ID#339: completely fixed form control finder issue with empty form gr…

…oups.
  • Loading branch information...
Christian Achatz
Christian Achatz committed Dec 22, 2018
1 parent 3262936 commit c36edeec60d2fc098bb4aa83f15fcf4bb0813476
Showing with 106 additions and 14 deletions.
  1. +103 −2 tests/suites/tools/form/taglib/HtmlFormTagTest.php
  2. +3 −12 tools/form/mixin/FormControlFinder.php
@@ -300,7 +300,7 @@ public function testTransform() {
}
/**
* Test interface complies for not-existing interface.
* Test interface complies for not-existing elements.
*/
public function testFindById1() {
$this->expectException(FormException::class);
@@ -392,7 +392,7 @@ public function testFindById4() {
}
/**
* Test interface complies for not-existing interface.
* Test interface complies for not-existing elements.
*/
public function testGetLabel1() {
$this->expectException(FormException::class);
@@ -459,6 +459,107 @@ public function testGetLabel3() {
}
public function testGetFormElementByName1() {
$this->expectException(FormException::class);
$form = new HtmlFormTag();
$doc = new Document();
$form->setParent($doc);
$form->getFormElementByName('not-existing');
}
/**
* Test simple name selection.
*/
public function testGetFormElementByName2() {
$form = new HtmlFormTag();
$doc = new Document();
$form->setParent($doc);
$form->setContent('<form:label name="foo1">Label</form:label>
<html:getstring
name="foo2"
namespace="APF\modules\usermanagement\pres"
config="labels.ini"
entry="frontend.proxy.add-users-to-proxy.intro.text"/>
<form:text name="foo3" />
<form:button name="submit" value="submit" />');
$form->onParseTime();
$form->onAfterAppend();
$actual = $form->getFormElementByName('foo2');
$this->assertNotNull($actual);
$this->assertInstanceOf(LanguageLabel::class, $actual);
$this->assertEquals('labels.ini', $actual->getAttribute('config'));
}
/**
* Test name selection within nested elements.
*/
public function testGetFormElementByName3() {
$form = new HtmlFormTag();
$doc = new Document();
$form->setParent($doc);
$form->setContent('<form:text name="bar1" />
<form:group>
<form:label name="bar2">Other Label</form:label>
<form:group>
<form:label name="foo1">Label</form:label>
<html:getstring
name="foo2"
namespace="APF\modules\usermanagement\pres"
config="labels.ini"
entry="frontend.proxy.add-users-to-proxy.intro.text"/>
</form:group>
</form:group>
<form:button name="submit" value="submit" />');
$form->onParseTime();
$form->onAfterAppend();
$actual = $form->getFormElementByName('foo2');
$this->assertNotNull($actual);
$this->assertInstanceOf(LanguageLabel::class, $actual);
$this->assertEquals('labels.ini', $actual->getAttribute('config'));
}
/**
* Test name selection within nested elements and element not in form group.
*/
public function testGetFormElementByName4() {
$form = new HtmlFormTag();
$doc = new Document();
$form->setParent($doc);
$form->setContent('<form:text name="bar1" />
<form:group>
<form:label name="bar2">Other Label</form:label>
<form:group>
<form:label name="foo1">Label</form:label>
<html:getstring
name="foo2"
namespace="APF\modules\usermanagement\pres"
config="labels.ini"
entry="frontend.proxy.add-users-to-proxy.intro.text"/>
</form:group>
</form:group>
<html:getstring
name="foo3"
namespace="APF\modules\usermanagement\pres"
config="labels.ini"
entry="frontend.proxy.add-users-to-proxy.intro.text"/>
<form:button name="submit" value="submit" />');
$form->onParseTime();
$form->onAfterAppend();
$actual = $form->getFormElementByName('foo3');
$this->assertNotNull($actual);
$this->assertInstanceOf(LanguageLabel::class, $actual);
$this->assertEquals('labels.ini', $actual->getAttribute('config'));
}
/**
* Tests API complies for non existing tags.
*/
@@ -74,11 +74,8 @@ public function getFormElementByID(string $id) {
} else {
$form = $this->getForm();
}
$parent = $form->getParent();
$docCon = $parent->getDocumentController() ? get_class($parent->getDocumentController()) : 'n/a';
throw new FormException('[' . get_class($this) . '::getFormElementByID()] No form element with id "'
. $id . '" composed in current form "' . $form->getAttribute('name')
. '" in document controller "' . $docCon . '". Please double-check your taglib definitions '
. $id . '" composed in form "' . $form->getAttribute('name') . '". Please double-check your taglib definitions '
. 'within this form (especially attributes, that are used for referencing other form '
. 'controls)!', E_USER_ERROR);
}
@@ -127,11 +124,8 @@ public function getFormElementByName(string $name) {
} else {
$form = $this->getForm();
}
$parent = $form->getParent();
$docCon = get_class($parent->getDocumentController());
throw new FormException('[' . get_class($this) . '::getFormElementByName()] No form element with name "'
. $name . '" composed in current form "' . $form->getAttribute('name')
. '" in document controller "' . $docCon . '". Please double-check your taglib definitions '
. $name . '" composed in form "' . $form->getAttribute('name') . '". Please double-check your taglib definitions '
. 'within this form (especially attributes, that are used for referencing other form '
. 'controls)!', E_USER_ERROR);
}
@@ -171,11 +165,8 @@ public function getLabel(string $name) {
} else {
$form = $this->getForm();
}
$parent = $form->getParent();
$docCon = get_class($parent->getDocumentController());
throw new FormException('[' . get_class($this) . '::getLabel()] No label found with name "' . $name
. '" composed in form with name "' . $form->getAttribute('name') . '" for document controller "'
. $docCon . '"!', E_USER_ERROR);
. '" composed in form "' . $form->getAttribute('name') . '"!', E_USER_ERROR);
}
/**

0 comments on commit c36edee

Please sign in to comment.