Commit a0fbbf86 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Report.php: refactored: TOKEN_* moved to Constants.php. New Alias ...

Report.php: refactored: TOKEN_* moved to Constants.php. New Alias  TOKEN_VALID_LIST. $this->tokenList remplaced by TOKEN_VALID_LIST. Lines with less than 2 elements are ignored. Every token is checked if it is known. Exceptions got a error number.
BodyTextParser.php: valid token checked against TOKEN_VALID_LIST.
parent 3db71cad
......@@ -87,8 +87,7 @@ class BodytextParser {
$full = '';
foreach ($bodytextArray as $row) {
// Valid 'new line' starts indicators: form, <level>, <level.sublevel>, <level>.<keyword>, {, <level> {, }
if ((1 === preg_match('/^\s*(\d*(\.)?)*\s*(head|althead|tail|sql|rbeg|rend|renr|rsep|fbeg|fend|fsep|' .
TYPO3_FORM . '|' . TYPO3_DEBUG_SHOW_BODY_TEXT . '|' . TYPO3_RECORD_ID . ') *=/', $row))
if ((1 === preg_match('/^\s*(\d*(\.)?)*\s*(' . TOKEN_VALID_LIST . ') *=/', $row))
|| (1 === preg_match('/^\s*(\d*(\.)?)*\s*({|})\s*/', $row))
|| (1 === preg_match('/^\s*(\d+(\.)?)+/', $row))
) {
......
......@@ -163,6 +163,9 @@ const ERROR_MISSING_VALUE = 1302;
const ERROR_INVALID_VALUE = 1303;
const ERROR_MULTIPLE_DEFINITION = 1304;
const ERROR_MULTIPLE_URL_PAGE_MAILTO_DEFINITION = 1305;
const ERROR_UNKNOWN_TOKEN = 1306;
const ERROR_TOO_FEW_PARAMETER_FOR_SENDMAIL = 1307;
const ERROR_TOO_MANY_PARAMETER = 1308;
// Upload
const ERROR_UPLOAD = 1400;
......@@ -310,6 +313,25 @@ const VAR_RANDOM = 'random';
const RANDOM_LENGTH = 32;
// Report, BodyText
const TOKEN_SQL = 'sql';
const TOKEN_HEAD = 'head';
const TOKEN_ALT_HEAD = 'althead';
const TOKEN_TAIL = 'tail';
const TOKEN_RBEG = 'rbeg';
const TOKEN_REND = 'rend';
const TOKEN_RENR = 'renr';
const TOKEN_RSEP = 'rsep';
const TOKEN_FBEG = 'fbeg';
const TOKEN_FEND = 'fend';
const TOKEN_FSEP = 'fsep';
const TOKEN_RBGD = 'rbgd';
const TOKEN_DEBUG = 'debug';
const TOKEN_FORM = CLIENT_FORM;
const TOKEN_RECORD_ID = CLIENT_RECORD_ID;
const TOKEN_DEBUG_BODYTEXT = TYPO3_DEBUG_SHOW_BODY_TEXT;
const TOKEN_VALID_LIST = 'sql|head|althead|tail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText';
// FORM - copy from table 'form' of processed form
//const DEF_FORM_NAME = CLIENT_FORM;
......
......@@ -22,21 +22,6 @@ require_once(__DIR__ . '/Sendmail.php');
require_once(__DIR__ . '/../exceptions/UserReportExtension.php');
require_once(__DIR__ . '/../Evaluate.php');
const TOKEN_SQL = 'sql';
const TOKEN_HEAD = 'head';
const TOKEN_ALT_HEAD = 'althead';
const TOKEN_TAIL = 'tail';
const TOKEN_RBEG = 'rbeg';
const TOKEN_REND = 'rend';
const TOKEN_RENR = 'renr';
const TOKEN_RSEP = 'rsep';
const TOKEN_FBEG = 'fbeg';
const TOKEN_FEND = 'fend';
const TOKEN_FSEP = 'fsep';
const TOKEN_RBGD = 'rbgd';
const TOKEN_DEBUG = 'debug';
const TOKEN_FORM = 'form';
const DEFAULT_QUESTION = 'question';
const DEFAULT_ICON = 'icon';
......@@ -111,8 +96,6 @@ class Report {
private $showDebugInfo = false;
private $tokenList = array();
/**
* Report constructor.
*
......@@ -171,20 +154,6 @@ class Report {
// Create sendmail Class. Take care to prepare a fr_log instance.
$this->sendmail = new Sendmail($this->log);
$this->tokenList[] = TOKEN_SQL;
$this->tokenList[] = TOKEN_HEAD;
$this->tokenList[] = TOKEN_ALT_HEAD;
$this->tokenList[] = TOKEN_TAIL;
$this->tokenList[] = TOKEN_RBEG;
$this->tokenList[] = TOKEN_REND;
$this->tokenList[] = TOKEN_RENR;
$this->tokenList[] = TOKEN_RSEP;
$this->tokenList[] = TOKEN_FBEG;
$this->tokenList[] = TOKEN_FEND;
$this->tokenList[] = TOKEN_FSEP;
$this->tokenList[] = TOKEN_RBGD;
$this->tokenList[] = TOKEN_DEBUG;
}
/**
......@@ -230,6 +199,10 @@ class Report {
// 10.50.5.sql = select ...
$arr = explode("=", trim($ttLine), 2);
// no elements or only one: do nothing
if (count($arr) < 2)
return;
// 10.50.5.sql
$key = strtolower(trim($arr[0]));
......@@ -246,6 +219,10 @@ class Report {
// frCmd = "sql"
$frCmd = $arrKey[count($arrKey) - 1];
if (strpos('|' . strtolower(TOKEN_VALID_LIST) . '|', '|' . $frCmd . '|') === false) {
throw new SyntaxReportException ("Unknown token: $frCmd in Line '$ttLine''", ERROR_UNKNOWN_TOKEN, null, __FILE__, __LINE__, $this->fr_error);
}
// remove last item (cmd)
unset($arrKey[count($arrKey) - 1]);
......@@ -281,7 +258,8 @@ class Report {
// set defaults
if ($frCmd === TOKEN_SQL) {
foreach ($this->tokenList as $key) {
$arr = explode('|', TOKEN_VALID_LIST);
foreach ($arr as $key) {
if (!isset($this->frArray[$level . "." . $key]))
$this->frArray[$level . "." . $key] = '';
}
......@@ -709,7 +687,7 @@ class Report {
// 'Absender|Empfaenger, mehrere mit Komma getrennt|Betreff|Mailinhalt'
$tmp = explode("|", $columnValue, 4);
if (count($tmp) < 4) {
throw new SyntaxReportException ("Too few parameter for sendmail: $columnValue", "", null, __FILE__, __LINE__, $this->fr_error);
throw new SyntaxReportException ("Too few parameter for sendmail: $columnValue", ERROR_TOO_FEW_PARAMETER_FOR_SENDMAIL, null, __FILE__, __LINE__, $this->fr_error);
}
$mail['receiver'] = $tmp[0];
......@@ -826,7 +804,7 @@ class Report {
// Split definition
$allParam = explode('|', $columnValue);
if (count($allParam) > 8)
throw new SyntaxReportException ("Too many parameter (max=8): $columnValue", "", null, __FILE__, __LINE__, $this->fr_error);
throw new SyntaxReportException ("Too many parameter (max=8): $columnValue", ERROR_TOO_MANY_PARAMETER, null, __FILE__, __LINE__, $this->fr_error);
// First Parameter: Split PageId|PageAlias and URL Params
$firstParam = explode('&', $allParam[0], 2);
......
......@@ -40,6 +40,10 @@ class ReportTest extends AbstractDatabaseTest {
$result = $this->report->process('# 10.sql = SELECT "Hello World"');
$this->assertEquals('', $result);
// empty (missing '=')
$result = $this->report->process('10.sql SELECT "Hello World"');
$this->assertEquals('', $result);
// sql
$result = $this->report->process('10.sql = SELECT "Hello World"');
$this->assertEquals('Hello World', $result);
......@@ -93,6 +97,15 @@ class ReportTest extends AbstractDatabaseTest {
$this->assertEquals('<table><tr><td>Doe</td>$$<td>John</td>++</tr>@<tr><td>Smith</td>$$<td>Jane</td>++</tr></table>', $result);
}
/**
* @expectedException \qfq\SyntaxReportException
*/
public function testUnknownTokenException() {
// empty (missing '=')
$result = $this->report->process('10.sql SELECT "Hello = World"');
}
/**
*
*/
......@@ -842,6 +855,47 @@ EOF;
$this->assertEquals('<a href="index.php?id=form&type=4&s=badcaffee1234" class="btn btn-default" title="Details" ><span class="glyphicon glyphicon glyphicon-search" ></span> click me</a>', $result);
}
/**
*
*/
public function testReportBullet() {
$arr = ['blue', 'gray', 'green', 'pink', 'red', 'yellow', 'fake'];
foreach ($arr as $color) {
// bullet $color
$result = $this->report->process("10.sql = SELECT '$color' AS _bullet FROM Person ORDER BY id LIMIT 1");
$this->assertEquals("<img alt=\"Bullet $color\" src=\"typo3conf/ext/qfq/Resources/Public/icons/bullet-$color.gif\" title=\"$color\" >", $result);
}
}
/**
*
*/
public function testReportCheck() {
$arr = ['blue', 'gray', 'green', 'pink', 'red', 'yellow', 'fake'];
foreach ($arr as $color) {
// check $color
$result = $this->report->process("10.sql = SELECT '$color' AS _check FROM Person ORDER BY id LIMIT 1");
$this->assertEquals("<img alt=\"Checked $color\" src=\"typo3conf/ext/qfq/Resources/Public/icons/checked-$color.gif\" title=\"$color\" >", $result);
}
}
/**
*
*/
public function testReportSurpress() {
$result = $this->report->process("10.sql = SELECT 'normal', 'hidden' AS _hidden, 'text' FROM Person ORDER BY id LIMIT 1");
$this->assertEquals("normaltext", $result);
$result = $this->report->process("10.sql = SELECT 'normal', 'hidden' AS _hidden, 'text' FROM Person ORDER BY id LIMIT 1\n10.10.sql = SELECT '{{10.hidden}}'");
$this->assertEquals("normaltexthidden", $result);
$result = $this->report->process("10.sql = SELECT 'normal', 'hidden' AS _hidden, 'text' FROM Person ORDER BY id LIMIT 1\n10.10.sql = SELECT '{{10.unknown}}'");
$this->assertEquals("normaltext{{10.unknown}}", $result);
}
/**
*
......
......@@ -14,6 +14,10 @@ require_once(__DIR__ . '/../../qfq/exceptions/CodeException.php');
class SanitizeTest extends \PHPUnit_Framework_TestCase {
/**
* @throws CodeException
* @throws UserFormException
*/
public function testSanitize() {
# Violates SANITIZE class: SANITIZE string is always an empty string.
......@@ -71,6 +75,10 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_ALL), "SANITIZE_ALL fails");
}
/**
* @throws CodeException
* @throws UserFormException
*/
public function testSanitizeMinMax() {
# Check min|max
......@@ -84,6 +92,10 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($val, Sanitize::sanitize($val, SANITIZE_ALLOW_MIN_MAX, '-100|200'), "SANITIZE_MIN_MAX fails");
}
/**
* @throws CodeException
* @throws UserFormException
*/
public function testSanitizeMinMaxDate() {
# Check min|max
......@@ -112,6 +124,10 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
}
/**
* @throws CodeException
* @throws UserFormException
*/
public function testSanitizeEmail() {
# Check
......@@ -152,6 +168,10 @@ class SanitizeTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals('jo%hn@doe.com', Sanitize::sanitize($val, SANITIZE_ALLOW_EMAIL), "SANITIZE_ALLOW_EMAIL fails");
}
/**
* @throws CodeException
* @throws UserFormException
*/
public function testSanitizePattern() {
# Check
......
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