Commit 9a267b44 authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3180=#2081 dynamicUpdate, rearrange 'input hidden' elements from checkboxes,...

#3180=#2081 dynamicUpdate, rearrange 'input hidden' elements from checkboxes, radios to top of form.

CODING.md: add some doc about STORE_ADDITIONAL_FORM_ELEMENTS.
load.php (#2081): rearrange delivered JSON to fullfill client API.
AbstractBuildForm.php: rename getJsonElementUpdate() to getFormElemenForJson(). Extend getFormElementForJson() to support changes for label and note. Fill store STORE_ADDITIONAL_FORM_ELEMENTS with 'hidden input' elments.
QuickFormQuery.php: implement Client JOSN API update.
parent 7c66b42d
......@@ -65,6 +65,13 @@ LOAD
AbstractBuildForm.php: process() > prepareT3VarsForSave() > Store.php: copyT3VarsToSip();
* *Form save*: FillStoreForm.php: process() > Store: fillTypo3StoreFromSip()
* Store: STORE_ADDITIONAL_FORM_ELEMENTS
* HTML 'hidden' elements, inside of a checkbox or radio input definition, might disturb Bootstrap CSS classes.
* Therefore HTML elements like 'hidden' can be collected in STORE_ADDITIONAL_FORM_ELEMENTS.
* When the form will be composed of all single parts, the STORE_ADDITIONAL_FORM_ELEMENTS content will be arranged before
the regular INPUT Elements.
* Formular zusammenbauen
* QuickFormQuery: doForm > loadFormSpecification - laedt den Form Record alle Form Elemente die nicht genested sind:
native, pill, fieldset, templateGroup >> $his->formNative.
......
......@@ -65,6 +65,8 @@ try {
$answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
$answer[API_MESSAGE] = 'load: success';
$answer[API_FORM_UPDATE] = $data;
$answer[API_ELEMENT_UPDATE] = $data[API_ELEMENT_UPDATE];
unset($data[API_ELEMENT_UPDATE]);
} catch (qfq\UserFormException $e) {
$answer[API_MESSAGE] = $e->formatMessage();
......
......@@ -23,7 +23,6 @@ require_once(__DIR__ . '/../qfq/helper/Support.php');
require_once(__DIR__ . '/../qfq/helper/OnArray.php');
require_once(__DIR__ . '/../qfq/report/Link.php');
/**
* Class AbstractBuildForm
* @package qfq
......@@ -186,10 +185,11 @@ abstract class AbstractBuildForm {
$htmlTail = $this->tail();
$htmlSubrecords = $this->doSubrecords();
}
$htmlHidden = $this->buildAdditionalFormElements();
$htmlSip = $this->buildHiddenSip($json);
return ($mode === FORM_LOAD) ? $htmlHead . $htmlElements . $htmlSip . $htmlT3vars . $htmlTail . $htmlSubrecords : $json;
return ($mode === FORM_LOAD) ? $htmlHead . $htmlHidden . $htmlElements . $htmlSip . $htmlT3vars . $htmlTail . $htmlSubrecords : $json;
}
/**
......@@ -330,7 +330,7 @@ abstract class AbstractBuildForm {
abstract public function getProcessFilter();
/**
* Process all FormElements: build corresponding HTML code. Collect and return all HTML code & JSON.
* Process all FormElements: Collect and return all HTML code & JSON.
*
* @param $recordId
* @param string $filter FORM_ELEMENTS_NATIVE | FORM_ELEMENTS_SUBRECORD | FORM_ELEMENTS_NATIVE_SUBRECORD
......@@ -351,7 +351,7 @@ abstract class AbstractBuildForm {
$html = '';
$flagOutput = false;
// The following 'FormElement.parameter' will never be used during load (fe.type='upload').
// The following 'FormElement.parameter' will never be used during load (fe.type='upload'). FE_PARAMETER has been already expanded.
$skip = [FE_SQL_UPDATE, FE_SQL_INSERT, FE_SQL_DELETE, FE_SQL_AFTER, FE_SQL_BEFORE, FE_PARAMETER];
// get current data record
......@@ -420,6 +420,7 @@ abstract class AbstractBuildForm {
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement[FE_TYPE]];
$jsonElement = array();
$elementExtra = '';
// Render pure element
$elementHtml = $this->$buildElementFunctionName($formElement, $htmlFormElementName, $value, $jsonElement, $mode);
......@@ -539,6 +540,20 @@ abstract class AbstractBuildForm {
abstract public function doSubrecords();
/**
* Get all elements from STORE_ADDITIONAL_FORM_ELEMENTS and return them as a string.
*
* @return string
* @throws CodeException
* @throws \qfq\UserFormException
*/
private function buildAdditionalFormElements() {
$data = $this->store->getStore(STORE_ADDITIONAL_FORM_ELEMENTS);
return is_array($data) ? implode('', $data) : '';
}
/**
* Create a hidden sip, based on latest STORE_SIP Values. Return complete HTML 'hidden' element.
*
......@@ -560,26 +575,38 @@ abstract class AbstractBuildForm {
$sipValue = $sip->queryStringToSip($queryString, RETURN_SIP);
$json[] = $this->getJsonElementUpdate(CLIENT_SIP, $sipValue, FE_MODE_SHOW);
$json[] = $this->getFormElementForJson(CLIENT_SIP, $sipValue, [FE_MODE => FE_MODE_SHOW]);
return $this->buildNativeHidden(CLIENT_SIP, $sipValue);
}
/**
* Create an array with standard elements and add 'form-element', 'value'.
* Create an array with standard elements for 'mode' (hidden, disabled, required) and add 'form-element', 'value'.
* 'Generic Element Update': add via API_ELEMENT_UPDATE 'label' and 'note'.
* All collected data as array - will be later converted to JSON.
*
* @param $htmlFormElementName
* @param string $htmlFormElementName
* @param string|array $value
* @param string $feMode disabled|readonly|''
* @param array $formElement
* @return array
*/
private function getJsonElementUpdate($htmlFormElementName, $value, $feMode) {
private function getFormElementForJson($htmlFormElementName, $value, array $formElement) {
$json = $this->getJsonFeMode($feMode);
$json = $this->getJsonFeMode($formElement[FE_MODE]);
$json['form-element'] = $htmlFormElementName;
$json['value'] = $value;
if (isset($formElement[FE_LABEL])) {
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_LABEL;
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $formElement[FE_LABEL];
}
if (isset($formElement[FE_NOTE])) {
$key = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE;
$json[API_ELEMENT_UPDATE][$key][API_ELEMENT_CONTENT] = $formElement[FE_NOTE];
}
return $json;
}
......@@ -741,7 +768,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return "$htmlTag $attribute>$textarea" . $this->getHelpBlock();
......@@ -1234,7 +1261,9 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']);
$htmlHidden = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$htmlElement = '<input ' . $attribute . '>';
if (isset($formElement['label2'])) {
......@@ -1247,7 +1276,7 @@ abstract class AbstractBuildForm {
$htmlElement, true);
$html = Support::wrapTag('<div class="btn-group" data-toggle="buttons">', $html);
$json = $this->getJsonElementUpdate($htmlFormElementName, $valueJson, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $valueJson, $formElement);
return $html;
}
......@@ -1286,7 +1315,9 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']);
$htmlHidden = $this->buildNativeHidden($htmlFormElementName, $formElement['unchecked']);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$html .= '<input ' . $attribute . '>';
if (isset($formElement['label2'])) {
......@@ -1296,7 +1327,7 @@ abstract class AbstractBuildForm {
$html = Support::wrapTag("<label>", $html, true);
$html = Support::wrapTag("<div class='checkbox'>", $html, true);
$json = $this->getJsonElementUpdate($htmlFormElementName, $valueJson, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $valueJson, $formElement);
return $html;
}
......@@ -1351,7 +1382,11 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden(HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h'), '');
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$attribute = $attributeBase;
if (isset($formElement['autofocus'])) {
......@@ -1382,7 +1417,7 @@ abstract class AbstractBuildForm {
$html .= Support::wrapTag("<label class='btn " . $formElement[FE_BUTTON_CLASS] . "$classActive'>",
$htmlElement, true);
$json[] = $this->getJsonElementUpdate($htmlFormElementNameUniq, $jsonValue, $formElement[FE_MODE]);
$json[] = $this->getFormElementForJson($htmlFormElementNameUniq, $jsonValue, $formElement);
// Init for the next checkbox
$attribute = $attributeBase;
......@@ -1417,7 +1452,11 @@ abstract class AbstractBuildForm {
$attributeBase .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attributeBase .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$html = $this->buildNativeHidden(HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h'), '');
$key = HelperFormElement::prependFormElementNameCheckBoxMulti($htmlFormElementName, 'h');
$htmlHidden = $this->buildNativeHidden($key, '');
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
$orientation = ($formElement[FE_MAX_LENGTH] > 1) ? ALIGN_HORIZONTAL : ALIGN_VERTICAL;
$checkboxClass = ($orientation === ALIGN_HORIZONTAL) ? 'checkbox-inline' : 'checkbox';
......@@ -1470,7 +1509,7 @@ abstract class AbstractBuildForm {
}
$html .= $htmlElement . $br;
$json[] = $this->getJsonElementUpdate($htmlFormElementNameUniq, $jsonValue, $formElement[FE_MODE]);
$json[] = $this->getFormElementForJson($htmlFormElementNameUniq, $jsonValue, $formElement);
}
......@@ -1582,8 +1621,10 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('autofocus', $formElement['autofocus']);
}
$html = $this->buildNativeHidden($htmlFormElementName, $value);
$htmlHidden = $this->buildNativeHidden($htmlFormElementName, $value);
$this->store->setVar($htmlFormElementName, $htmlHidden, STORE_ADDITIONAL_FORM_ELEMENTS, false);
$html = '';
for ($ii = 0; $ii < count($itemValue); $ii++) {
$classActive = '';
......@@ -1607,7 +1648,7 @@ abstract class AbstractBuildForm {
$html = Support::wrapTag('<div class="btn-group" data-toggle="buttons">', $html);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $html;
}
......@@ -1660,6 +1701,7 @@ abstract class AbstractBuildForm {
$attribute .= Support::doAttribute('autofocus', $formElement['autofocus']);
}
$html = $this->buildNativeHidden($htmlFormElementName, $value);
for ($ii = 0; $ii < count($itemValue); $ii++) {
......@@ -1699,7 +1741,7 @@ abstract class AbstractBuildForm {
$attribute = $attributeBase;
}
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $html;
}
......@@ -1760,7 +1802,7 @@ abstract class AbstractBuildForm {
$option .= '>' . $itemValue[$ii] . '</option>';
}
$json = $this->getJsonElementUpdate($htmlFormElementName, $jsonValues, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $jsonValues, $formElement);
return '<select ' . $attribute . '>' . $option . '</select>' . $this->getHelpBlock();
}
......@@ -2226,7 +2268,7 @@ abstract class AbstractBuildForm {
// <button type="button" class="file-delete" data-sip="571d1fc9e6974"><span class="glyphicon glyphicon-trash"></span></button>
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $htmlTextDelete . $htmlInputFile . $hiddenSipUpload;
}
......@@ -2329,7 +2371,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return "<input $attribute>" . $this->getHelpBlock();
......@@ -2461,7 +2503,7 @@ abstract class AbstractBuildForm {
$attribute .= $this->getAttributeFeMode($formElement[FE_MODE]);
$attribute .= $this->getAttributeList($formElement, [F_FE_DATA_PATTERN_ERROR, F_FE_DATA_REQUIRED_ERROR, F_FE_DATA_MATCH_ERROR, F_FE_DATA_ERROR]);
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
$element = Support::wrapTag("<textarea $attribute>", htmlentities($value), false);
......@@ -2642,7 +2684,7 @@ abstract class AbstractBuildForm {
// restore parent processed FE's
$this->feSpecNative = $tmpStore;
$json = $this->getJsonElementUpdate($htmlFormElementName, $value, $formElement[FE_MODE]);
$json = $this->getFormElementForJson($htmlFormElementName, $value, $formElement);
return $html;
}
......
......@@ -321,8 +321,8 @@ class BuildFormBootstrap extends AbstractBuildForm {
* @return string
*/
public function tail() {
$html = '';
// $html .= $this->buildNewSip();
$deleteUrl = '';
$formId = $this->getFormId();
......
......@@ -238,8 +238,10 @@ const STORE_ZERO = "0"; // value: 0, might helpfull if variable is empty but use
const STORE_EMPTY = "E"; // value: '', might helpfull if variable is not defined and should result in an empty string instead of {{...}} (cause not replaced)
const STORE_SYSTEM = "Y"; // various system values like db connection credentials
const STORE_EXTRA = 'X'; // Persistent Store: contains arrays! Not Usefull for user. Used by system.
const STORE_ADDITIONAL_FORM_ELEMENTS = 'A'; // Internal Store to collect FormElements. Typically for 'hidden' elements of radio and checkbox. Helps render those elements at the end of the whole form rendering.
const STORE_USE_DEFAULT = "FSRVD";
//
// Store: Definitions / Members
//
......@@ -419,6 +421,8 @@ const API_FIELD_NAME = 'field-name';
const API_FIELD_MESSAGE = 'field-message';
const API_FORM_UPDATE = 'form-update';
const API_ELEMENT_UPDATE = 'element-update';
const API_ELEMENT_ATTRIBUTE = 'attr';
const API_ELEMENT_CONTENT = 'content';
const API_JSON_HIDDEN = 'hidden';
const API_JSON_DISABLED = 'disabled';
......
......@@ -117,7 +117,6 @@ class QuickFormQuery {
* @param bool $phpUnit
* @throws CodeException
* @throws UserFormException
* @internal param string $bodytext
*/
public function __construct(array $t3data = array(), $phpUnit = false) {
......@@ -344,6 +343,9 @@ class QuickFormQuery {
throw new CodeException("This statement should never be reached", ERROR_CODE_SHOULD_NOT_HAPPEN);
}
if (is_array($data)) {
$data = $this->groupElementUpdateEntries($data);
}
return $data;
}
......@@ -697,6 +699,30 @@ class QuickFormQuery {
}
/**
* Searches the whole array $dataArray on the second level for API_ELEMENT_UPDATE.
* All found elements collect under $collect[API_ELEMENT_UPDATE]... . Leave the rest unchanged.
*
* @param array $dataArray
* @return array to build JSON
*/
private function groupElementUpdateEntries(array $dataArray) {
$collect = array();
foreach ($dataArray as $data) {
if (isset($data[API_ELEMENT_UPDATE])) {
foreach ($data[API_ELEMENT_UPDATE] as $key => $item) {
$collect[API_ELEMENT_UPDATE][$key] = $item;
}
unset($data[API_ELEMENT_UPDATE]);
}
$collect[] = $data;
}
return $collect;
}
/**
* Process the SQL Queries from bodytext. Return the output.
*
......
......@@ -163,7 +163,8 @@ class Store {
STORE_ZERO => false,
STORE_EMPTY => false,
STORE_SYSTEM => false,
STORE_EXTRA => false
STORE_EXTRA => false,
STORE_ADDITIONAL_FORM_ELEMENTS => false
];
self::fillSystemStore($fileConfigIni);
......
......@@ -80,34 +80,36 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$label['123-l'][API_ELEMENT_CONTENT] = 'Name';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$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);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// CheckType
$formElement['checkType'] = SANITIZE_ALLOW_MIN_MAX;
$formElement['checkPattern'] = '1|10';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$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);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement['checkType'] = SANITIZE_ALLOW_PATTERN;
$formElement['checkPattern'] = '^[a-z]*$';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$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);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement['checkType'] = SANITIZE_ALLOW_DIGIT;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$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);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement['checkType'] = SANITIZE_ALLOW_EMAIL;
$formElement['checkPattern'] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json);
$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);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
$formElement['checkType'] = '';
$formElement['checkPattern'] = '';
......@@ -118,13 +120,13 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement['maxLength'] = 40;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$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);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
// maxlength bigger than physical spec:
$formElement['maxLength'] = 1000;
$result = $build->buildInput($formElement, 'name:1', '', $json);
$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);
$this->assertEquals([FE_MODE_HIDDEN => '', '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
$formElement2 = $formElement;
......@@ -157,18 +159,18 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$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" 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);
$this->assertEquals([FE_MODE_HIDDEN => '', '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" 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);
$this->assertEquals([FE_MODE_HIDDEN => '', '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" 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);
$this->assertEquals([FE_MODE_HIDDEN => '', 'disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
}
/**
......@@ -493,6 +495,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
parent::setUp();
$this->store->unsetStore(STORE_ADDITIONAL_FORM_ELEMENTS);
$this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
// Defaults
......
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 1/2/16
* Time: 11:10 PM
*/
namespace qfq;
require_once(__DIR__ . '/../../qfq/store/FillStoreForm.php');
//require_once(__DIR__ . '/../../qfq/exceptions/CodeException.php');
class FillStoreFormTest extends \PHPUnit_Framework_TestCase {
/**
* @throws CodeException
* @throws UserFormException
*/
public function testFake() {
# Violates SANITIZE class: SANITIZE string is always an empty string.
# Access are cached: use new variables for every test.
# Check ''
// $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', '');
}
//
// /**
// * @expectedException \qfq\UserFormException
// */
// public function testSanitizeExceptionMinMaxMissingMin() {
// Sanitize::sanitize(56, SANITIZE_ALLOW_MIN_MAX, '|45');
// }
//
}
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