Commit 016d0b08 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Misc: add central getLastErrorAsString(). Refactor from exec() to qfqExec()

parent 682bc904
Pipeline #1038 passed with stage
in 2 minutes and 11 seconds
...@@ -1434,6 +1434,7 @@ class QuickFormQuery { ...@@ -1434,6 +1434,7 @@ class QuickFormQuery {
* @throws CodeException * @throws CodeException
* @throws DbException * @throws DbException
* @throws UserFormException * @throws UserFormException
* @throws UserReportException
*/ */
public function saveReport() { public function saveReport() {
$uid = $this->store->getVar(T3DATA_UID, STORE_SIP . STORE_ZERO, SANITIZE_ALLOW_DIGIT); $uid = $this->store->getVar(T3DATA_UID, STORE_SIP . STORE_ZERO, SANITIZE_ALLOW_DIGIT);
......
...@@ -797,7 +797,7 @@ class Save { ...@@ -797,7 +797,7 @@ class Save {
$overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS; $overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS;
Support::moveFile($srcFile, $pathFileName, $overwrite, $chmodDir); Support::moveFile($srcFile, $pathFileName, $overwrite, $chmodDir);
// If given, get chmodFile. Needs to be prefixed with a 0 (=octal) - it should not be quoted! Symbolic mode is not allowed. E.g.: 0660, or 01777 // get chmodFile
if (empty($formElement[FE_FILE_CHMOD_FILE])) { if (empty($formElement[FE_FILE_CHMOD_FILE])) {
$chmodFile = false; $chmodFile = false;
} else { } else {
...@@ -841,7 +841,10 @@ class Save { ...@@ -841,7 +841,10 @@ class Save {
$cmd = $this->evaluate->parse($cmd); $cmd = $this->evaluate->parse($cmd);
// Do 'autoOrient' command // Do 'autoOrient' command
$rc = exec($cmd); $output = Support::qfqExec($cmd, $rc);
if ($rc != 0) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'copy failed', ERROR_MESSAGE_SUPPORT => "[cmd=$cmd]$output"]), ERROR_IO_COPY);
}
} }
/** /**
...@@ -906,9 +909,15 @@ class Save { ...@@ -906,9 +909,15 @@ class Save {
// Create temporary directory // Create temporary directory
$tempDir = Support::createTempDir(); $tempDir = Support::createTempDir();
$newSrc = $tempDir . DIRECTORY_SEPARATOR . QFQ_TEMP_SOURCE; $newSrc = $tempDir . DIRECTORY_SEPARATOR . QFQ_TEMP_SOURCE;
$rc = copy($pathFileNameSrc, $newSrc); if (false === copy($pathFileNameSrc, $newSrc)) {
$msg = HelperFile::getLastErrorAsString() . " - copy $pathFileNameSrc $newSrc";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'copy failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_COPY);
}
$rc = chdir($tempDir); if (false === chdir($tempDir)) {
$msg = HelperFile::getLastErrorAsString() . " - chdir($tempDir)";
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'copy failed', ERROR_MESSAGE_SUPPORT => $msg]), ERROR_IO_COPY);
}
// Split destination. // Split destination.
$pathParts = pathinfo($fileDestinationSplit); $pathParts = pathinfo($fileDestinationSplit);
...@@ -920,7 +929,11 @@ class Save { ...@@ -920,7 +929,11 @@ class Save {
$fileNameDest = $pathParts['basename']; $fileNameDest = $pathParts['basename'];
// Split PDF // Split PDF
$rc = exec('pdf2svg "' . $newSrc . '" "' . $fileNameDest . '" all'); $cmd = 'pdf2svg "' . $newSrc . '" "' . $fileNameDest . '" all';
$output = Support::qfqExec($cmd, $rc);
if ($rc != 0) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'copy failed', ERROR_MESSAGE_SUPPORT => "[$cwd][cmd=$cmd]$output"]), ERROR_IO_COPY);
}
// Array of created filenames. // Array of created filenames.
$files = scandir('.'); $files = scandir('.');
......
...@@ -238,4 +238,17 @@ class HelperFile { ...@@ -238,4 +238,17 @@ class HelperFile {
} }
} }
/**
* @return string
*/
public static function getLastErrorAsString() {
if (NULL === ($errors = error_get_last())) {
return '';
}
return $errors['type'] . ' - ' . $errors['message'];
}
} }
\ No newline at end of file
...@@ -44,7 +44,8 @@ class Logger { ...@@ -44,7 +44,8 @@ class Logger {
if (!$handle = fopen($filename, $mode)) { if (!$handle = fopen($filename, $mode)) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot open file', json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot open file',
ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename . " ( CWD: " . getcwd() . ") - " . error_get_last()]), ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename .
" ( CWD: " . getcwd() . ") - " . HelperFile::getLastErrorAsString()]),
ERROR_IO_OPEN); ERROR_IO_OPEN);
} }
} }
...@@ -52,7 +53,8 @@ class Logger { ...@@ -52,7 +53,8 @@ class Logger {
if (fwrite($handle, $msg . PHP_EOL) === false) { if (fwrite($handle, $msg . PHP_EOL) === false) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot write file', json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot write file',
ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename . " ( CWD: " . getcwd() . ") - " . error_get_last()]), ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename .
" ( CWD: " . getcwd() . ") - " . HelperFile::getLastErrorAsString()]),
ERROR_IO_WRITE); ERROR_IO_WRITE);
} }
......
...@@ -1310,8 +1310,7 @@ class Support { ...@@ -1310,8 +1310,7 @@ class Support {
/** /**
* *
*/ */
public public static function createTempDir() {
static function createTempDir() {
return exec("mktemp -d --tmpdir " . QFQ_TEMP_FILE_PATTERN); return exec("mktemp -d --tmpdir " . QFQ_TEMP_FILE_PATTERN);
...@@ -1324,8 +1323,7 @@ class Support { ...@@ -1324,8 +1323,7 @@ class Support {
* *
* @return string * @return string
*/ */
public public static function falseEmptyToZero($val) {
static function falseEmptyToZero($val) {
return ($val == '' || $val == false) ? '0' : $val; return ($val == '' || $val == false) ? '0' : $val;
} }
...@@ -1336,8 +1334,7 @@ class Support { ...@@ -1336,8 +1334,7 @@ class Support {
* @param string $key * @param string $key
* @return bool true: if $key exists and a) is empty or b) =='1' * @return bool true: if $key exists and a) is empty or b) =='1'
*/ */
public public static function isEnabled(array $arr, $key) {
static function isEnabled(array $arr, $key) {
if (!array_key_exists($key, $arr)) { if (!array_key_exists($key, $arr)) {
return false; return false;
} }
...@@ -1358,8 +1355,7 @@ class Support { ...@@ -1358,8 +1355,7 @@ class Support {
* *
* @return string * @return string
*/ */
public public static function handleEscapeSpaceComment($str) {
static function handleEscapeSpaceComment($str) {
$str = trim($str); $str = trim($str);
if ($str == '') { if ($str == '') {
...@@ -1397,8 +1393,7 @@ class Support { ...@@ -1397,8 +1393,7 @@ class Support {
* *
* @return string * @return string
**/ **/
public public static function ldap_escape($subject, $ignore = '', $flags = 0) {
static function ldap_escape($subject, $ignore = '', $flags = 0) {
if (function_exists('ldap_escape')) { if (function_exists('ldap_escape')) {
...@@ -1470,8 +1465,7 @@ class Support { ...@@ -1470,8 +1465,7 @@ class Support {
* @return string * @return string
* @throws UserFormException * @throws UserFormException
*/ */
public public static function htmlEntityEncodeDecode($mode, $data) {
static function htmlEntityEncodeDecode($mode, $data) {
switch ($mode) { switch ($mode) {
case MODE_ENCODE: case MODE_ENCODE:
...@@ -1522,16 +1516,15 @@ class Support { ...@@ -1522,16 +1516,15 @@ class Support {
* @param int $rc * @param int $rc
* @return string The content that is displayed on the website * @return string The content that is displayed on the website
*/ */
public public static function qfqExec($cmd, &$rc = 0) {
static function qfqExec($cmd, &$rc = 0) {
exec($cmd, $arr, $rc); exec($cmd, $arr, $rc);
$output = implode('<br>', $arr); $output = implode('<br>', $arr);
if ($rc != 0) { if ($rc != 0) {
$output = $rc . " - " . $output; $output = "[rc=$rc] $output";
} }
return ($output); return $output;
} }
} }
\ No newline at end of file
...@@ -506,6 +506,7 @@ class Download { ...@@ -506,6 +506,7 @@ class Download {
* *
* @return string * @return string
* @throws CodeException * @throws CodeException
* @throws DbException
* @throws DownloadException * @throws DownloadException
* @throws UserFormException * @throws UserFormException
* @throws UserReportException * @throws UserReportException
......
...@@ -966,18 +966,18 @@ class Report { ...@@ -966,18 +966,18 @@ class Report {
default : default :
if ($flagControl) { if ($flagControl) {
$flagOutput = false; $flagOutput = false;
$token= isset($columnName[0])? $columnName[0]:''; $token = isset($columnName[0]) ? $columnName[0] : '';
switch($token){ switch ($token) {
case COLUMN_WRAP_TOKEN: case COLUMN_WRAP_TOKEN:
if(isset($columnName[1])){ if (isset($columnName[1])) {
$content = Support::wrapTag('<' . substr($columnName, 1) . '>', $columnValue); $content = Support::wrapTag('<' . substr($columnName, 1) . '>', $columnValue);
$flagOutput = true; $flagOutput = true;
} }
break; break;
case COLUMN_STORE_USER: case COLUMN_STORE_USER:
if(isset($columnName[1])) { if (isset($columnName[1])) {
$this->store::setVar(substr($columnName, 1),$columnValue, STORE_USER); $this->store::setVar(substr($columnName, 1), $columnValue, STORE_USER);
} }
break; break;
...@@ -986,7 +986,6 @@ class Report { ...@@ -986,7 +986,6 @@ class Report {
} }
} else { } else {
// No special Columnname: just add the column value. // No special Columnname: just add the column value.
$content .= $columnValue; $content .= $columnValue;
......
...@@ -225,19 +225,18 @@ class SendMail { ...@@ -225,19 +225,18 @@ class SendMail {
$cmd = $sendEmail . ' ' . implode(' ', $args); $cmd = $sendEmail . ' ' . implode(' ', $args);
$cmd = str_replace('`', '\`', $cmd); // escape backticks (escapeshellcmd would be too thorough) $cmd = str_replace('`', '\`', $cmd); // escape backticks (escapeshellcmd would be too thorough)
exec($cmd, $arr, $rc); $output = Support::qfqExec($cmd, $rc);
if ($rc != 0) { if ($rc != 0) {
// After first installation of QFQ extension, the PERL script is not executable: is this the problem here? // After first installation of QFQ extension, the PERL script is not executable: is this the problem here?
$perms = fileperms($sendEmail); $perms = fileperms($sendEmail);
if (!($perms & 0x0040)) { if (!($perms & 0x0040)) {
chmod($sendEmail, 0755); chmod($sendEmail, 0755);
exec($cmd, $arr, $rc); // Give it a second try. // exec($cmd, $arr, $rc); // Give it a second try.
$output = Support::qfqExec($cmd, $rc);
} }
if ($rc != 0) { if ($rc != 0) {
$output = $rc . " - " . implode('<br>', $arr) . " - " . $cmd; throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => '"Error sendmail failed', ERROR_MESSAGE_SUPPORT => "[cmd=$cmd]$output"]), ERROR_SENDMAIL);
throw new UserFormException("Error sendmail failed: " . $output, ERROR_SENDMAIL);
} }
} }
......
...@@ -447,7 +447,7 @@ class Store { ...@@ -447,7 +447,7 @@ class Store {
* @param string $foundInStore Returns the name of the store where $key has been found. If $key is not found, * @param string $foundInStore Returns the name of the store where $key has been found. If $key is not found,
* return ''. * return ''.
* *
* @return string a) if found: value, b) false * @return string|array a) if found: value, b) false. STORE_EXTRA returns an array for the given key.
* @throws CodeException * @throws CodeException
* @throws UserFormException * @throws UserFormException
*/ */
......
...@@ -93,19 +93,19 @@ class BuildFormPlainTest extends AbstractDatabaseTest { ...@@ -93,19 +93,19 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_MAX] = 10; $formElement[FE_MAX] = 10;
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = 1; $formElement[FE_MIN] = 1;
$formElement[FE_MAX] = ''; $formElement[FE_MAX] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_MIN] = ''; $formElement[FE_MIN] = '';
$formElement[FE_MAX] = 10; $formElement[FE_MAX] = 10;
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// reset so they don't interfere with next tests // reset so they don't interfere with next tests
$formElement[FE_MIN] = ''; $formElement[FE_MIN] = '';
$formElement[FE_MAX] = ''; $formElement[FE_MAX] = '';
...@@ -115,19 +115,19 @@ class BuildFormPlainTest extends AbstractDatabaseTest { ...@@ -115,19 +115,19 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_CHECK_PATTERN] = '^[a-z]*$'; $formElement[FE_CHECK_PATTERN] = '^[a-z]*$';
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT; $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
$formElement[FE_CHECK_PATTERN] = ''; $formElement[FE_CHECK_PATTERN] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL; $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
$formElement[FE_CHECK_PATTERN] = ''; $formElement[FE_CHECK_PATTERN] = '';
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL; $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
$formElement[FE_CHECK_PATTERN] = ''; $formElement[FE_CHECK_PATTERN] = '';
...@@ -137,7 +137,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest { ...@@ -137,7 +137,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_DECIMAL_FORMAT] = '5,2'; $formElement[FE_DECIMAL_FORMAT] = '5,2';
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
$formElement[FE_DECIMAL_FORMAT] = ''; $formElement[FE_DECIMAL_FORMAT] = '';
...@@ -147,13 +147,13 @@ class BuildFormPlainTest extends AbstractDatabaseTest { ...@@ -147,13 +147,13 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement['maxLength'] = 40; $formElement['maxLength'] = 40;
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$this->assertEquals('<input id="123" name="name:1" class="form-control" maxlength="40" 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="40" 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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// maxlength bigger than physical spec: // maxlength bigger than physical spec:
$formElement['maxLength'] = 1000; $formElement['maxLength'] = 1000;
$result = $build->buildInput($formElement, 'name:1', '', $json); $result = $build->buildInput($formElement, 'name:1', '', $json);
$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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
// no size, no maxlength and column not in primary table // no size, no maxlength and column not in primary table
$formElement2 = $formElement; $formElement2 = $formElement;
...@@ -188,19 +188,19 @@ class BuildFormPlainTest extends AbstractDatabaseTest { ...@@ -188,19 +188,19 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json); $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); $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']; $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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
// textarea // textarea
$formElement2['size'] = '40,10'; $formElement2['size'] = '40,10';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json); $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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
$formElement2['size'] = ' 40 , 10 '; $formElement2['size'] = ' 40 , 10 ';
$result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json); $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('<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); $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
} }
/** /**
......
...@@ -238,9 +238,6 @@ class StoreTest extends TestCase { ...@@ -238,9 +238,6 @@ class StoreTest extends TestCase {
$this->store->appendToStore(null, STORE_RECORD); $this->store->appendToStore(null, STORE_RECORD);
$this->assertEquals($param, $this->store->getStore(STORE_RECORD)); $this->assertEquals($param, $this->store->getStore(STORE_RECORD));
$this->store->appendToStore('', STORE_RECORD);
$this->assertEquals($param, $this->store->getStore(STORE_RECORD));
$this->store->appendToStore(array(), STORE_RECORD); $this->store->appendToStore(array(), STORE_RECORD);
$this->assertEquals($param, $this->store->getStore(STORE_RECORD)); $this->assertEquals($param, $this->store->getStore(STORE_RECORD));
......
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