Skip to content

Commit

Permalink
ID#339: completely fixed form control finder issue with empty form gr…
Browse files Browse the repository at this point in the history
…oups.
  • Loading branch information
Christian Achatz committed Dec 22, 2018
1 parent 3262936 commit c36edee
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 14 deletions.
105 changes: 103 additions & 2 deletions tests/suites/tools/form/taglib/HtmlFormTagTest.php
Expand Up @@ -300,7 +300,7 @@ public function testTransform() {
} }


/** /**
* Test interface complies for not-existing interface. * Test interface complies for not-existing elements.
*/ */
public function testFindById1() { public function testFindById1() {
$this->expectException(FormException::class); $this->expectException(FormException::class);
Expand Down Expand Up @@ -392,7 +392,7 @@ public function testFindById4() {
} }


/** /**
* Test interface complies for not-existing interface. * Test interface complies for not-existing elements.
*/ */
public function testGetLabel1() { public function testGetLabel1() {
$this->expectException(FormException::class); $this->expectException(FormException::class);
Expand Down Expand Up @@ -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. * Tests API complies for non existing tags.
*/ */
Expand Down
15 changes: 3 additions & 12 deletions tools/form/mixin/FormControlFinder.php
Expand Up @@ -74,11 +74,8 @@ public function getFormElementByID(string $id) {
} else { } else {
$form = $this->getForm(); $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 "' throw new FormException('[' . get_class($this) . '::getFormElementByID()] No form element with id "'
. $id . '" composed in current form "' . $form->getAttribute('name') . $id . '" composed in form "' . $form->getAttribute('name') . '". Please double-check your taglib definitions '
. '" in document controller "' . $docCon . '". Please double-check your taglib definitions '
. 'within this form (especially attributes, that are used for referencing other form ' . 'within this form (especially attributes, that are used for referencing other form '
. 'controls)!', E_USER_ERROR); . 'controls)!', E_USER_ERROR);
} }
Expand Down Expand Up @@ -127,11 +124,8 @@ public function getFormElementByName(string $name) {
} else { } else {
$form = $this->getForm(); $form = $this->getForm();
} }
$parent = $form->getParent();
$docCon = get_class($parent->getDocumentController());
throw new FormException('[' . get_class($this) . '::getFormElementByName()] No form element with name "' throw new FormException('[' . get_class($this) . '::getFormElementByName()] No form element with name "'
. $name . '" composed in current form "' . $form->getAttribute('name') . $name . '" composed in form "' . $form->getAttribute('name') . '". Please double-check your taglib definitions '
. '" in document controller "' . $docCon . '". Please double-check your taglib definitions '
. 'within this form (especially attributes, that are used for referencing other form ' . 'within this form (especially attributes, that are used for referencing other form '
. 'controls)!', E_USER_ERROR); . 'controls)!', E_USER_ERROR);
} }
Expand Down Expand Up @@ -171,11 +165,8 @@ public function getLabel(string $name) {
} else { } else {
$form = $this->getForm(); $form = $this->getForm();
} }
$parent = $form->getParent();
$docCon = get_class($parent->getDocumentController());
throw new FormException('[' . get_class($this) . '::getLabel()] No label found with name "' . $name throw new FormException('[' . get_class($this) . '::getLabel()] No label found with name "' . $name
. '" composed in form with name "' . $form->getAttribute('name') . '" for document controller "' . '" composed in form "' . $form->getAttribute('name') . '"!', E_USER_ERROR);
. $docCon . '"!', E_USER_ERROR);
} }


/** /**
Expand Down

0 comments on commit c36edee

Please sign in to comment.