Commit 50b7267a authored by Carsten  Rose's avatar Carsten Rose
Browse files

BuildFormPlainTest.php: Update UNIT Tests.

parent 1d995d96
......@@ -81,32 +81,32 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => ''], $json);
// CheckType
$formElement['checkType'] = SANITIZE_ALLOW_MIN_MAX;
$formElement['checkPattern'] = '1|10';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" min="1" max="10" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" min="1" max="10" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_PATTERN;
$formElement['checkPattern'] = '^[a-z]*$';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-z]*$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-z]*$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_DIGIT;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[\d]*$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[\d]*$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_EMAIL;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
$formElement['checkType'] = '';
......@@ -117,13 +117,13 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement['size'] = 40;
$formElement['maxLength'] = 40;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="40" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" size="40" maxlength="40" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
// maxlength bigger than physical spec:
$formElement['maxLength'] = 1000;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" size="40" maxlength="255" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false], $json);
// no size, no maxlength and column not in primary table
......@@ -132,42 +132,42 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement2['size'] = '';
$formElement2['name'] = 'specialname';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input name="specialname:1" class="form-control" type="input" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// no size, given maxlength and column not in primary table
$formElement2['maxLength'] = '10';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input name="specialname:1" class="form-control" type="input" maxlength="10" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" maxlength="10" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// size given, no maxlength and column not in primary table
$formElement2['maxLength'] = '';
$formElement2['size'] = '10';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input name="specialname:1" class="form-control" type="input" size="10" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" size="10" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// size given, maxlength given and column not in primary table
$formElement2['maxLength'] = '20';
$formElement2['size'] = '10';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input name="specialname:1" class="form-control" type="input" size="10" maxlength="20" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" type="input" size="10" maxlength="20" value="" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
// Explicit: further
$formElement['tooltip'] = 'Nice Tooltip';
$formElement['placeholder'] = 'Please type a name';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="255" value="Hello World" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" size="40" maxlength="255" value="Hello World" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false], $json);
// textarea
$formElement['size'] = '40,10';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false], $json);
$formElement['size'] = ' 40 , 10 ';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-disabled="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false], $json);
}
......@@ -220,6 +220,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
'placeholder' => '',
'checkType' => '',
'checkPattern' => '',
FE_HTML_ID => '123',
'tabindex' => 0
];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment