Commit 6c0c64f5 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixed a lot of unit tests, which did not passed on webwork16/crose/qfq. In...

Fixed a lot of unit tests, which did not passed on webwork16/crose/qfq. In test hardcoded 'http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx/qfq/' makes trouble. CR did not find the place (qfq.json baseUrl tried) to adjust for phpUnit Tests.
parent a0002094
Pipeline #5232 failed with stages
in 2 minutes and 10 seconds
......@@ -1121,6 +1121,7 @@ const FE_BS_INPUT_COLUMNS = F_BS_INPUT_COLUMNS;
const FE_BS_NOTE_COLUMNS = F_BS_NOTE_COLUMNS;
const FE_WRAP_ROW_LABEL_INPUT_NOTE = 'rowLabelInputNote';
const FE_MAX_LENGTH = 'maxLength';
const FE_MAX_LENGTH_COLUMN = 'maxLengthColumn';
const FE_PARAMETER = 'parameter';
const FE_ENCODE = 'encode';
const FE_CHECK_TYPE = 'checkType';
......@@ -2062,3 +2063,6 @@ const I_UNCHECKED = 'unchecked';
// Rest Client
const HTTP_STATUS = 'http-status';
const ERROR_MESSAGE = 'error-message';
// Misc
const BASE_DIR_FAKE = 'http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx/qfq/';
......@@ -25,8 +25,7 @@ namespace IMATHUZH\Qfq\Core\Helper;
use IMATHUZH\Qfq\Core\Exception\Thrower;
use IMATHUZH\Qfq\Core\Store\Config;
class Path
{
class Path {
// App
private static $absoluteApp = null; // This is manually set in self::setMainPaths()
private static $urlApp = null;
......@@ -100,8 +99,7 @@ class Path
* @throws \CodeException
* @throws \UserFormException
*/
public static function setMainPaths(string $absoluteApp = null)
{
public static function setMainPaths(string $absoluteApp = null) {
if (is_null($absoluteApp)) {
$absoluteApp = self::findAbsoluteApp();
}
......@@ -117,8 +115,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteApp(...$pathPartsToAppend): string
{
public static function absoluteApp(...$pathPartsToAppend): string {
self::enforcePathIsSet(self::$absoluteApp);
return self::join(self::$absoluteApp, $pathPartsToAppend);
}
......@@ -128,8 +125,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteExt(...$pathPartsToAppend): string
{
public static function absoluteExt(...$pathPartsToAppend): string {
return self::absoluteApp(self::appToExt(), $pathPartsToAppend);
}
......@@ -138,8 +134,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteLog(...$pathPartsToAppend): string
{
public static function absoluteLog(...$pathPartsToAppend): string {
if (is_null(self::$absoluteLog)) {
self::findAbsoluteLog();
}
......@@ -151,8 +146,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteSqlLogFile(): string
{
public static function absoluteSqlLogFile(): string {
if (is_null(self::$overloadAbsoluteSqlLogFile)) {
return self::absoluteLog(self::LOG_TO_SQL_LOG_FILE_DEFAULT);
}
......@@ -163,8 +157,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteQfqLogFile(): string
{
public static function absoluteQfqLogFile(): string {
if (is_null(self::$overloadAbsoluteQfqLogFile)) {
return self::absoluteLog(self::LOG_TO_QFQ_LOG_FILE_DEFAULT);
}
......@@ -175,8 +168,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteMailLogFile(): string
{
public static function absoluteMailLogFile(): string {
if (is_null(self::$overloadAbsoluteMailLogFile)) {
return self::absoluteLog(self::LOG_TO_MAIL_LOG_FILE_DEFAULT);
}
......@@ -188,8 +180,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function appToProject(...$pathPartsToAppend): string
{
public static function appToProject(...$pathPartsToAppend): string {
self::enforcePathIsSet(self::$appToProject);
return self::join(self::$appToProject, $pathPartsToAppend);
}
......@@ -199,8 +190,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteProject(...$pathPartsToAppend): string
{
public static function absoluteProject(...$pathPartsToAppend): string {
return self::absoluteApp(self::appToProject($pathPartsToAppend));
}
......@@ -209,8 +199,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function absoluteConf(...$pathPartsToAppend): string
{
public static function absoluteConf(...$pathPartsToAppend): string {
return self::absoluteProject(self::PROJECT_TO_CONF, $pathPartsToAppend);
}
......@@ -219,8 +208,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function appToExt(...$pathPartsToAppend): string
{
public static function appToExt(...$pathPartsToAppend): string {
return self::join(self::APP_TO_EXT, $pathPartsToAppend);
}
......@@ -229,8 +217,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function urlApp(...$pathPartsToAppend): string
{
public static function urlApp(...$pathPartsToAppend): string {
// ensure base url is configured
if (is_null(self::$urlApp) || self::$urlApp === '') {
Thrower::userFormException('Base url not configured.', 'Go to QFQ extension configuration in the Typo3 backend and fill in a value for config.baseUrl');
......@@ -243,8 +230,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function urlExt(...$pathPartsToAppend): string
{
public static function urlExt(...$pathPartsToAppend): string {
return self::urlApp(self::appToExt($pathPartsToAppend));
}
......@@ -253,8 +239,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function appToApi(...$pathPartsToAppend): string
{
public static function appToApi(...$pathPartsToAppend): string {
return self::join(self::APP_TO_EXT, self::EXT_TO_API, $pathPartsToAppend);
}
......@@ -263,8 +248,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function urlApi(...$pathPartsToAppend): string
{
public static function urlApi(...$pathPartsToAppend): string {
return self::urlApp(self::appToApi($pathPartsToAppend));
}
......@@ -272,8 +256,7 @@ class Path
* @param mixed ...$pathPartsToAppend
* @return string
*/
public static function projectToForm(...$pathPartsToAppend) : string
{
public static function projectToForm(...$pathPartsToAppend): string {
$projectToForm = is_null(self::$projectToForm) ? self::PROJECT_TO_FORM_DEFAULT : self::$projectToForm;
return self::join($projectToForm, $pathPartsToAppend);
}
......@@ -282,8 +265,7 @@ class Path
* @param mixed ...$pathPartsToAppend
* @return string
*/
public static function projectToReport(...$pathPartsToAppend) : string
{
public static function projectToReport(...$pathPartsToAppend): string {
$projectToReport = is_null(self::$projectToReport) ? self::PROJECT_TO_REPORT_DEFAULT : self::$projectToReport;
return self::join($projectToReport, $pathPartsToAppend);
}
......@@ -291,16 +273,14 @@ class Path
/**
* @param string $newPath
*/
public static function setProjectToForm(string $newPath)
{
public static function setProjectToForm(string $newPath) {
self::$projectToForm = $newPath;
}
/**
* @param string $newPath
*/
public static function setProjectToReport(string $newPath)
{
public static function setProjectToReport(string $newPath) {
self::$projectToReport = $newPath;
}
......@@ -308,8 +288,7 @@ class Path
* @param string $newPath
* @throws \UserFormException
*/
public static function setAbsoluteSqlLogFile(string $newPath)
{
public static function setAbsoluteSqlLogFile(string $newPath) {
self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteSqlLogFile = $newPath;
}
......@@ -318,8 +297,7 @@ class Path
* @param string $newPath
* @throws \UserFormException
*/
public static function setAbsoluteQfqLogFile(string $newPath)
{
public static function setAbsoluteQfqLogFile(string $newPath) {
self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteQfqLogFile = $newPath;
}
......@@ -328,8 +306,7 @@ class Path
* @param string $newPath
* @throws \UserFormException
*/
public static function setAbsoluteMailLogFile(string $newPath)
{
public static function setAbsoluteMailLogFile(string $newPath) {
self::enforcePathIsAbsolute($newPath);
self::$overloadAbsoluteMailLogFile = $newPath;
}
......@@ -337,8 +314,7 @@ class Path
/**
* @param $urlApp
*/
public static function setUrlApp($urlApp)
{
public static function setUrlApp($urlApp) {
self::$urlApp = $urlApp;
}
......@@ -349,8 +325,7 @@ class Path
* @throws \UserFormException
* @throws \UserReportException
*/
public static function overrideLogPathsFromConfig()
{
public static function overrideLogPathsFromConfig() {
// QFQ log
$absoluteQfqLogFile = Config::get(SYSTEM_QFQ_LOG_PATHFILENAME);
if (!empty($absoluteQfqLogFile)) {
......@@ -378,8 +353,7 @@ class Path
* @return string
* @throws \UserFormException
*/
public static function joinIfNotAbsolute (string $path1, string $path2): string
{
public static function joinIfNotAbsolute(string $path1, string $path2): string {
if ($path2 !== '' && $path2[0] === '/') {
return $path2;
}
......@@ -395,8 +369,7 @@ class Path
* @param array $pathPartsToAppend
* @return string
*/
public static function join(...$pathPartsToAppend): string
{
public static function join(...$pathPartsToAppend): string {
$parts = $pathPartsToAppend;
// concatenate all parts (arrays are flattened)
......@@ -426,13 +399,13 @@ class Path
});
// remove multiple occurrences of '/' (but keep http://)
if (preg_match('/^\w*:\/\//', $path, $match) ) {
if (preg_match('/^\w*:\/\//', $path, $match)) {
$protocol = $match[0];
$path = substr($path, strlen($protocol));
} else {
$protocol = '';
}
$path = preg_replace('/\/{2,}/','/', $path);
$path = preg_replace('/\/{2,}/', '/', $path);
return $protocol . $path;
}
......@@ -442,24 +415,21 @@ class Path
/**
* @param string $newPath
*/
private static function setAbsoluteApp(string $newPath)
{
private static function setAbsoluteApp(string $newPath) {
self::$absoluteApp = $newPath;
}
/**
* @param string $newPath
*/
private static function setAppToProject(string $newPath)
{
private static function setAppToProject(string $newPath) {
self::$appToProject = $newPath;
}
/**
* @param string $newPath
*/
private static function setAbsoluteLog(string $newPath)
{
private static function setAbsoluteLog(string $newPath) {
self::$absoluteLog = $newPath;
}
......@@ -471,8 +441,7 @@ class Path
*
* @throws \UserFormException
*/
private static function findAbsoluteLog()
{
private static function findAbsoluteLog() {
if (!is_null(self::$absoluteLog)) {
// only execute once
return;
......@@ -483,11 +452,11 @@ class Path
if (file_exists($absoluteLog)) {
self::setAbsoluteLog($absoluteLog);
// search log dir fileadmin/protected/log
// search log dir fileadmin/protected/log
} elseif (file_exists(self::absoluteApp(self::APP_TO_LOG_IN_PROTECTED))) {
self::setAbsoluteLog(self::absoluteApp(self::APP_TO_LOG_IN_PROTECTED));
// create default log dir qfqProject/log
// create default log dir qfqProject/log
} else {
HelperFile::createPathRecursive($absoluteLog);
self::setAbsoluteLog($absoluteLog);
......@@ -500,8 +469,7 @@ class Path
* @throws \CodeException
* @throws \UserFormException
*/
private static function findAppToProject()
{
private static function findAppToProject() {
if (!is_null(self::$appToProject)) {
// only execute once
return;
......@@ -512,20 +480,20 @@ class Path
if (HelperFile::isReadableException($absoluteProjectPathFile)) {
self::setAppToProject(HelperFile::include($absoluteProjectPathFile));
// does the deprecated config.qfq.php exist? => fileadmin/protected/qfqProject & migrate to qfq.json
// does the deprecated config.qfq.php exist? => fileadmin/protected/qfqProject & migrate to qfq.json
} elseif (HelperFile::isReadableException(self::absoluteApp(self::APP_TO_TYPO3_CONF, CONFIG_QFQ_PHP))) {
HelperFile::createPathRecursive(self::absoluteApp(self::APP_TO_PROJECT_IN_PROTECTED));
self::setAppToProject(self::APP_TO_PROJECT_IN_PROTECTED);
Config::migrateConfigPhpToJson();
self::writeProjectPathPhp();
// does fileadmin exist? => fileadmin/protected/qfqProject
// does fileadmin exist? => fileadmin/protected/qfqProject
} elseif (file_exists(self::absoluteApp(self::APP_TO_FILEADMIN))) {
HelperFile::createPathRecursive(self::absoluteApp(self::APP_TO_PROJECT_IN_PROTECTED));
self::setAppToProject(self::APP_TO_PROJECT_IN_PROTECTED);
self::writeProjectPathPhp();
// else => folder above APP
// else => folder above APP
} else {
self::setAppToProject(self::APP_TO_PROJECT_DEFAULT);
self::writeProjectPathPhp();
......@@ -538,12 +506,10 @@ class Path
*
* @throws \UserFormException
*/
private static function findAbsoluteApp()
{
private static function findAbsoluteApp() {
// look for typo3conf directory
$absoluteApp = self::realpath(self::join(__DIR__, '../../../../../../'));
if (!file_exists(self::join($absoluteApp, self::APP_TO_TYPO3_CONF)))
{
if (!file_exists(self::join($absoluteApp, self::APP_TO_TYPO3_CONF))) {
Thrower::userFormException('App path seems to be wrong: Directory "typo3conf" not found in app path.'
, "Current app path: $absoluteApp");
}
......@@ -556,8 +522,7 @@ class Path
*
* @throws \UserFormException
*/
private static function writeProjectPathPhp()
{
private static function writeProjectPathPhp() {
$appToProject = self::appToProject();
$fileContent = <<<EOF
<?php
......@@ -580,7 +545,7 @@ EOF;
* @throws \UserFormException
*/
private static function enforcePathIsSet($path) {
if(is_null($path)) {
if (is_null($path)) {
Thrower::userFormException('Path accessed before set.', 'Make sure Path::setMainPaths(...) is called before this code is executed..');
}
}
......@@ -592,7 +557,7 @@ EOF;
* @throws \UserFormException
*/
private static function enforcePathIsAbsolute(string $path) {
if($path !== '' && $path[0] === '/') {
if ($path !== '' && $path[0] === '/') {
return;
}
Thrower::userFormException('Path is not absolute', "Path does not start with '/' : $path");
......@@ -607,8 +572,7 @@ EOF;
* @return string
* @throws \UserFormException
*/
private static function realpath(string $pathToSomethingThatExists, ...$pathPartsToAppend): string
{
private static function realpath(string $pathToSomethingThatExists, ...$pathPartsToAppend): string {
$absolutePath = realpath($pathToSomethingThatExists);
if ($absolutePath === false) {
Thrower::userFormException('Path not found.', "Either path does not exist or access not permitted. Make sure the whole path is executable by the current user. Path: $pathToSomethingThatExists.");
......@@ -623,8 +587,7 @@ EOF;
* @param string $path
* @return bool
*/
private static function containsDoubleDot(string $path)
{
return $path === '..' || OnString::strStartsWith($path, '../') || OnString::strEndsWith($path, '/..' ) || OnString::strContains($path, '/../');
private static function containsDoubleDot(string $path) {
return $path === '..' || OnString::strStartsWith($path, '../') || OnString::strEndsWith($path, '/..') || OnString::strContains($path, '/../');
}
}
\ No newline at end of file
......@@ -8,12 +8,10 @@
namespace IMATHUZH\Qfq\Tests\Unit\Core\Helper;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\Path;
use PHPUnit\Framework\TestCase;
/**
* Class HelperFileTest
* @package qfq
......@@ -25,29 +23,29 @@ class HelperFileTest extends TestCase {
*/
public function testGetFileTypeHighlight() {
$this->assertEquals('', HelperFile::getFileTypeHighlight('',''));
$this->assertEquals('', HelperFile::getFileTypeHighlight('','fileadmin/test.js'));
$this->assertEquals('', HelperFile::getFileTypeHighlight('', ''));
$this->assertEquals('', HelperFile::getFileTypeHighlight('', 'fileadmin/test.js'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,''));
$this->assertEquals('' , HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,'fileadmin/test.js'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF, ''));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF, 'fileadmin/test.js'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,''));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, ''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT, ''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ, ''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON, ''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB, ''));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.php.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.php'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.qfq'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.py'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.m'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.js'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.php.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.php'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.qfq'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.py'));
$this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', BASE_DIR_FAKE . HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.m'));
}
public function testJoinPathFilename() {
......@@ -68,5 +66,14 @@ class HelperFileTest extends TestCase {
$this->assertEquals('/b', HelperFile::joinPathFilename('a', '/b'));
}
/**
*
*/
protected function setUp() {
parent::setUp();
Path::setUrlApp(BASE_DIR_FAKE);
}
}
......@@ -10,6 +10,7 @@ namespace IMATHUZH\Qfq\Tests\Unit\Core\Helper;
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Store\Store;
use PHPUnit\Framework\TestCase;
......@@ -947,6 +948,7 @@ class SupportTest extends TestCase {
$expected[FE_INPUT_TYPE] = 'number';
$expected[FE_MIN] = -2147483648;
$expected[FE_MAX] = 2147483647;
$expected[FE_MAX_LENGTH_COLUMN] = 11;
$this->assertEquals($expected, $formElement, "CheckType Auto should switch to numerical for signed int");
$formElement = $formElementTemplate;
......@@ -956,12 +958,14 @@ class SupportTest extends TestCase {
$expected[FE_INPUT_TYPE] = 'number';
$expected[FE_MIN] = 0;
$expected[FE_MAX] = 4294967295;
$expected[FE_MAX_LENGTH_COLUMN] = 11;
$this->assertEquals($expected, $formElement, "CheckType Auto should switch to digit for unsigned int");
$formElement = $formElementTemplate;
$expected = $formElement;
Support::adjustFeToColumnDefinition($formElement, 'decimal(10,2) not null');
$expected[FE_CHECK_TYPE] = SANITIZE_ALLOW_NUMERICAL;
$expected[FE_MAX_LENGTH_COLUMN] = 13;
$this->assertEquals($expected, $formElement, "CheckType Auto should switch to numerical for decimal");
$formElement = $formElementTemplate;
......@@ -973,7 +977,9 @@ class SupportTest extends TestCase {
$expected = $formElement;
Support::adjustFeToColumnDefinition($formElement, 'varchar(255)');
$expected[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
$expected[FE_MAX_LENGTH] = 255;
// $expected[FE_MAX_LENGTH] = 255;
$expected[FE_MAX_LENGTH] = '';
$expected[FE_MAX_LENGTH_COLUMN] = 255;
$this->assertEquals($expected, $formElement, "Checktype Auto should switch to all for text with encode=specialchars");
$formElement = $formElementTemplate;
......@@ -981,7 +987,9 @@ class SupportTest extends TestCase {
$expected = $formElement;
Support::adjustFeToColumnDefinition($formElement, 'varchar(64)');
$expected[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
$expected[FE_MAX_LENGTH] = 64;
// $expected[FE_MAX_LENGTH] = 64;
$expected[FE_MAX_LENGTH] = '';
$expected[FE_MAX_LENGTH_COLUMN] = 64;
$this->assertEquals($expected, $formElement, "Checktype Auto should switch to alnumx for text with encode=none");
$formElement = $formElementTemplate;
......@@ -991,13 +999,14 @@ class SupportTest extends TestCase {
$expected[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
$expected[FE_MIN] = -2147483648;
$expected[FE_MAX] = 2147483647;
$expected[FE_MAX_LENGTH_COLUMN] = 11;
$this->assertEquals($expected, $formElement, "Checktype Auto should switch to alnumx if typeAhead is defined");
$formElement = $formElementTemplate;
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
$expected = $formElement;
Support::adjustFeToColumnDefinition($formElement, 'datetime');
$expected[FE_MAX_LENGTH] = strlen('0000/00/00 00:00:00');
$expected[FE_MAX_LENGTH_COLUMN] = strlen('0000/00/00 00:00:00');
$this->assertEquals($expected, $formElement, "maxLength for datetime should be correct");
}
......@@ -1253,6 +1262,7 @@ class SupportTest extends TestCase {
protected function setUp() {
parent::setUp();
Path::setUrlApp(BASE_DIR_FAKE);
$GLOBALS["TSFE"] = new FakeTSFE();
$this->store = Store::getInstance('', true);
}
......
......@@ -3,7 +3,6 @@
namespace IMATHUZH\Qfq\Tests\Unit\Core\Report;
use IMATHUZH\Qfq\Core\Evaluate;
use IMATHUZH\Qfq\Core\Helper\Path;
use IMATHUZH\Qfq\Core\Report\Report;
use IMATHUZH\Qfq\Core\Store\Session;
......@@ -177,19 +176,20 @@ class ReportTest extends AbstractDatabaseTest {
// link
$result = $this->report->process("10.sql = SELECT 'u:http://www.example.com' AS _link FROM Person ORDER BY id LIMIT 1");
$base = (strpos($result, BASE_DIR_FAKE) === false) ? '' : BASE_DIR_FAKE;
$this->assertEquals('<a href="http://www.example.com" >http://www.example.com</a>', $result);
// link, checked
$result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|C' AS _link FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="http://www.example.com" ><img alt="Checked green" src="http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx/qfq/typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" ></a>', $result);
$this->assertEquals('<a href="http://www.example.com" ><img alt="Checked green" src="' . $base . 'typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" ></a>', $result);
// linck, checked, text
$result = $this->report->process("10.sql = SELECT 'u:http://www.example.com|C|t:Hello World' AS _link FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="http://www.example.com" ><img alt="Checked green" src="http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx/qfq/typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" > Hello World</a>', $result);
$this->assertEquals(