Commit 2ba7b197 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Refs #7783: Add unit test

parent fe4c8072
Pipeline #1447 passed with stage
in 2 minutes and 21 seconds
......@@ -7434,6 +7434,8 @@ AutoCron Jobs of type 'website' needs the php.ini setting: ::
allow_url_fopen = On
Remember: if a cron job fails for whatever reason, the cron daemon will send a mail to the userid who started the cron
job. E.g. www-data. Setup a email forward of such account to a frequently read email account.
Create / edit `AutoCron` jobs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -9,6 +9,7 @@
namespace qfq;
use qfq;
use Symfony\Component\Console\Helper\Helper;
//use qfq\Store;
//use qfq\OnArray;
......@@ -3180,6 +3181,9 @@ abstract class AbstractBuildForm {
Support::setIfNotSet($formElement, FE_ANNOTATE_USER_NAME);
Support::setIfNotSet($formElement, FE_ANNOTATE_USER_NAME);
$dataHighlight=HelperFile::getFileTypeHighlight($formElement[FE_HIGHLIGHT]??'',$formElement[FE_TEXT_SOURCE] );
// <div class="codeCorrection" data-uid='{"uid": 1, "name": "Reginald Commenter", "avatar": "http://www"}' data-file="../javascript/src/CodeCorrection.js" data-target="codeCorrection-output1">
// </div>
// <input id="codeCorrection-output1" name="correction-data" type="hidden"
......@@ -3193,6 +3197,7 @@ abstract class AbstractBuildForm {
// $attributeDiv .= Support::doAttribute('data-uid', $jsonDataUid, true,ESCAPE_WITH_BACKSLASH);
$attributeDiv .= Support::doAttribute('data-file', $this->fileToSipUrl($formElement[FE_TEXT_SOURCE]));
$attributeDiv .= Support::doAttribute('data-target', $formElement[FE_HTML_ID]);
$attributeDiv .= Support::doAttribute('data-highlight', $dataHighlight);
$attributeDiv .= $this->getAttributeFeMode($formElement[FE_MODE]);
$htmlAnnotate = Support::wrapTag('<div ' . $attributeDiv . ' data-uid=\''. $jsonDataUid . '\' >', '', false);
// $htmlAnnotate = Support::wrapTag('<div ' . $attributeDiv .'>', '', false);
......
......@@ -1080,6 +1080,13 @@ const FE_ANNOTATE_TYPE_TEXT = 'text';
const FE_ANNOTATE_USER_NAME = 'annotateUserName';
const FE_ANNOTATE_USER_UID = 'annotateUserUid';
const FE_ANNOTATE_USER_AVATAR = 'annotateUserAvatar';
const FE_HIGHLIGHT = 'highlight';
const FE_HIGHLIGHT_OFF = 'off';
const FE_HIGHLIGHT_AUTO = 'auto';
const FE_HIGHLIGHT_JAVASCRIPT = 'javascript';
const FE_HIGHLIGHT_QFQ = 'qfq';
const FE_HIGHLIGHT_PYTHON = 'python';
const FE_HIGHLIGHT_MATLAB = 'matlab';
const FE_SQL_VALIDATE = 'sqlValidate'; // Action: Query to validate form load
const FE_EXPECT_RECORDS = 'expectRecords'; // Action: expected number of rows of FE_SQL_VALIDATE
......@@ -1665,6 +1672,7 @@ const AUTOCRON_COUNT = 'count';
// Annotate
const ANNOTATE_GRAPHIC_CSS_CLASS = 'annotate-graphic'; // Ex 'fabric'
const ANNOTATE_TEXT_CSS_CLASS = 'annotate-text'; // Ex 'codeCorrection
const DIR_HIGHLIGHT_JSON = 'typo3conf/ext/qfq/Resources/Public/Json';
// DataImport
const IMPORT_MODE_APPEND = 'append';
......
......@@ -105,13 +105,13 @@ class HelperFile {
public static function getFileStat($pathFileName) {
$vars = array();
if (empty($pathFileName) ) {
if (empty($pathFileName)) {
return array();
}
$pathFileName = self::correctRelativPathFileName($pathFileName);
if(!file_exists ($pathFileName)){
if (!file_exists($pathFileName)) {
return array();
}
......@@ -386,7 +386,7 @@ class HelperFile {
// Wenn nicht, lege sie an.
foreach ($arr as $part) {
if($part==''){// Happens with '/...'
if ($part == '') {// Happens with '/...'
continue;
}
......@@ -411,5 +411,55 @@ class HelperFile {
}
}
/**
* Determine highlight name, based on the given $highlight or provided filename (the extension will be used)
*
* @param $highlight
* @param $fileName
* @return string
* @throws UserFormException
*/
public static function getFileTypeHighlight($highlight, $fileName) {
$extToFileType = [
'js' => 'javascript.json'
, 'javascript' => 'javascript.json'
, 'qfq' => 'highlight.qfq.json'
, 'php' => 'highlight.php.json'
, 'py' => 'highlight.py.json'
, 'python' => 'highlight.py.json'
, 'matlab' => 'highlight.m.json'
, 'm' => 'highlight.m.json'
];
switch ($highlight) {
case FE_HIGHLIGHT_AUTO:
$arr = explode('.', $fileName);
$ext = strtolower(end($arr));
$highlight = (isset($extToFileType[$ext])) ? $extToFileType[$ext] : '';
break;
case FE_HIGHLIGHT_JAVASCRIPT:
case FE_HIGHLIGHT_QFQ:
case FE_HIGHLIGHT_PYTHON:
case FE_HIGHLIGHT_MATLAB:
$ext = $highlight;
break;
case FE_HIGHLIGHT_OFF:
case '':
$ext = '';
break;
default:
throw new UserFormException("Unknown highlight type: " . $highlight, ERROR_UNKNOWN_MODE);
break;
}
if (isset($extToFileType[$ext])) {
return DIR_HIGHLIGHT_JSON . '/' . $extToFileType[$ext];
}
return '';
}
}
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 11/02/18
* Time: 9:16 PM
*/
namespace qfq;
use PHPUnit\Framework\TestCase;
/**
* Class HelperFileTest
* @package qfq
*/
class HelperFileTest extends TestCase {
/**
* @throws UserFormException
*/
public function testGetFileTypeHighlight() {
$this->assertEquals('', HelperFile::getFileTypeHighlight('',''));
$this->assertEquals('', HelperFile::getFileTypeHighlight('','fileadmin/test.js'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,''));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,''));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,''));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,''));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,''));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,''));
$this->assertEquals('' , HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,'fileadmin/test.js'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,'fileadmin/test.js'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,'fileadmin/test.js'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,'fileadmin/test.js'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,'fileadmin/test.js'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,'fileadmin/test.js'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,'fileadmin/test.php'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.php.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,'fileadmin/test.php'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,'fileadmin/test.php'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,'fileadmin/test.php'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,'fileadmin/test.php'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,'fileadmin/test.php'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,'fileadmin/test.qfq'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,'fileadmin/test.qfq'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,'fileadmin/test.qfq'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,'fileadmin/test.qfq'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,'fileadmin/test.qfq'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,'fileadmin/test.qfq'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,'fileadmin/test.py'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,'fileadmin/test.py'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,'fileadmin/test.py'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,'fileadmin/test.py'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,'fileadmin/test.py'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,'fileadmin/test.py'));
$this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,'fileadmin/test.m'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,'fileadmin/test.m'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,'fileadmin/test.m'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,'fileadmin/test.m'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,'fileadmin/test.m'));
$this->assertEquals(DIR_HIGHLIGHT_JSON . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,'fileadmin/test.m'));
}
}
......@@ -10,8 +10,6 @@ namespace qfq;
use PHPUnit\Framework\TestCase;
//class SanitizeTest extends \PHPUnit_Framework_TestCase {
/**
* Class SanitizeTest
* @package qfq
......
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