Commit 2ae2ecb6 authored by Elias Villiger's avatar Elias Villiger
Browse files

Feature #5414 - Fix unit tests

parent 345454f4
......@@ -715,8 +715,10 @@ class Support {
* Set Defaults for the current formElement.
*
* @param array $formElement
*
* @param array $formSpec
* @return array
*
* @throws CodeException
*/
public static function setFeDefaults(array $formElement, array $formSpec = array()) {
......@@ -773,13 +775,12 @@ class Support {
self::setIfNotSet($formElement, FE_MIN);
self::setIfNotSet($formElement, FE_MAX);
self::setIfNotSet($formElement, FE_DECIMAL_FORMAT);
self::setIfNotSet($formElement, F_FE_DATA_PATTERN_ERROR);
$fieldTypeDefinition = $store->getVar($formElement[FE_NAME], STORE_TABLE_COLUMN_TYPES);
self::adjustFeToColumnDefinition($formElement, $fieldTypeDefinition);
$typeSpec = $store->getVar($formElement[FE_NAME], STORE_TABLE_COLUMN_TYPES);
self::adjustFeToColumnDefinition($formElement, $typeSpec);
return $formElement;
}
......
......@@ -82,26 +82,26 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" value="" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// Min/Max
$formElement[FE_MIN] = 1;
$formElement[FE_MAX] = 10;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="number" value="" min="1" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="number" value="" min="1" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = 1;
$formElement[FE_MAX] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" value="" min="1" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" min="1" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = '';
$formElement[FE_MAX] = 10;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" value="" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" max="10" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
// reset so they don't interfere with next tests
$formElement[FE_MIN] = '';
......@@ -111,19 +111,19 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
$formElement[FE_CHECK_PATTERN] = '^[a-z]*$';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" value="" pattern="^[a-z]*$" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[a-z]*$" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
$formElement[FE_CHECK_PATTERN] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" value="" pattern="^[\d]*$" data-pattern-error="Allowed characters: 0...9" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[\d]*$" data-pattern-error="Allowed characters: 0...9" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
$formElement[FE_CHECK_PATTERN] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-pattern-error="Requested format: string@domain" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" data-pattern-error="Requested format: string@domain" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
......@@ -133,7 +133,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// Decimal format
$formElement[FE_DECIMAL_FORMAT] = '5,2';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" value="" pattern="^-?[0-9]{0,3}(\.[0-9]{0,2})?$" data-pattern-error="Requested decimal format (mantis,decimal): 5,2" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="255" type="input" value="" pattern="^-?[0-9]{0,3}(\.[0-9]{0,2})?$" data-pattern-error="Requested decimal format (mantis,decimal): 5,2" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_DECIMAL_FORMAT] = '';
......@@ -147,9 +147,9 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
// maxlength bigger than physical spec:
$formElement['maxLength'] = 2000;
$formElement['maxLength'] = 1000;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="2000" type="input" size="40" value="" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" size="40" value="" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
// no size, no maxlength and column not in primary table
......@@ -176,25 +176,27 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement2['size'] = '10';
$result = $build->buildInput($formElement2, 'specialname:1', '', $json);
$this->assertEquals('<input id="123" name="specialname:1" class="form-control" maxlength="20" type="input" size="10" value="" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement2['maxLength'] = '';
$formElement2['size'] = '';
// Explicit: further
$formElement['tooltip'] = 'Nice Tooltip';
$formElement['placeholder'] = 'Please type a name';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="1000" type="input" size="40" value="Hello World" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$formElement2['tooltip'] = 'Nice Tooltip';
$formElement2['placeholder'] = 'Please type a name';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" type="input" value="Hello World" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-required="no" ><div class="help-block with-errors hidden"></div>', $result);
$label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => 'Hello World'];
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
// textarea
$formElement['size'] = '40,10';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" maxlength="1000" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$formElement2['size'] = '40,10';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
$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-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement['size'] = ' 40 , 10 ';
$result = $build->buildInput($formElement, 'name:1', 'Hello World', $json);
$this->assertEquals('<textarea id="123" name="name:1" class="form-control" maxlength="1000" cols="40" rows="10" placeholder="Please type a name" title="Nice Tooltip" data-hidden="no" data-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$formElement2['size'] = ' 40 , 10 ';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
$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-required="no" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, API_ELEMENT_UPDATE => $label], $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