Commit c1c9cf69 authored by Carsten  Rose's avatar Carsten Rose
Browse files

BuildFormPlainTest.php: fixed some test to respect new input elements definitions.

parent fbdad4cf
......@@ -53,7 +53,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$result = $build->buildLabel('myLabel:123', "Hello World");
$this->assertEquals('<label for="myLabel:123">Hello World</label>', $result);
$this->assertEquals('<label for="myLabel:123" class="control-label" >Hello World</label>', $result);
}
public function testBuildInput() {
......@@ -97,32 +97,32 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// Defaults
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" type="input" maxlength="255" value="" >', $result);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $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" type="input" maxlength="255" value="" min="1" max="10" >', $result);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" min="1" max="10" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_PATTERN;
$formElement['checkPattern'] = '^[a-z]*$';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" type="input" maxlength="255" value="" pattern="^[a-z]*$" >', $result);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[a-z]*$" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_DIGIT;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" type="input" maxlength="255" value="" pattern="^[\d]*$" >', $result);
$this->assertEquals('<input name="name:1" class="form-control" type="input" maxlength="255" value="" pattern="^[\d]*$" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$formElement['checkType'] = SANITIZE_ALLOW_EMAIL;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" type="input" maxlength="255" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" >', $result);
$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,}$" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
$formElement['checkType'] = '';
......@@ -133,31 +133,31 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement['size'] = 40;
$formElement['maxLength'] = 40;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" type="input" size="40" maxlength="40" value="" >', $result);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="40" value="" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
// maxlength bigger than physical spec:
$formElement['maxLength'] = 1000;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input name="name:1" type="input" size="40" maxlength="255" value="" >', $result);
$this->assertEquals('<input name="name:1" class="form-control" type="input" size="40" maxlength="255" value="" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => '', 'disabled' => false, 'readonly' => false], $json);
// 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" type="input" size="40" maxlength="255" value="Hello World" placeholder="Please type a name" title="Nice Tooltip" >', $result);
$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" ><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, 'readonly' => false], $json);
// textarea
$formElement['size'] = '40,10';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea name="name:1" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" >Hello World</textarea>', $result);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" >Hello World</textarea><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, 'readonly' => false], $json);
$formElement['size'] = ' 40 , 10 ';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea name="name:1" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" >Hello World</textarea>', $result);
$this->assertEquals('<textarea name="name:1" class="form-control" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" >Hello World</textarea><div class="help-block with-errors"></div>', $result);
$this->assertEquals(['form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, 'readonly' => false], $json);
}
......
Supports Markdown
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