Commit 191b063a authored by Carsten  Rose's avatar Carsten Rose
Browse files

Report.php: cleanup of Report class. Workaround to suppress 'undefined index'.

PHP Unit Tests: LinktTest.php, ReportTest.phh - more tests
parent aa267668
...@@ -70,6 +70,7 @@ class Report { ...@@ -70,6 +70,7 @@ class Report {
// private $resultArray = array(); // private $resultArray = array();
private $levelCount = 0; private $levelCount = 0;
//private $counter = 0; //private $counter = 0;
/** /**
* @var Variables * @var Variables
*/ */
...@@ -90,9 +91,14 @@ class Report { ...@@ -90,9 +91,14 @@ class Report {
*/ */
private $sendmail = null; private $sendmail = null;
private $page_control = array(); /**
* @var array
*/
private $pageDefaults = array();
// Emulate global variable: will be set much earlier in other functions. Will be shown in error messages. /**
* @var array - Emulate global variable: will be set much earlier in other functions. Will be shown in error messages.
*/
private $fr_error = array('uid' => '', 'pid' => '', 'row' => '', 'debug_level' => '0', 'full_level' => ''); private $fr_error = array('uid' => '', 'pid' => '', 'row' => '', 'debug_level' => '0', 'full_level' => '');
private $phpUnit = false; private $phpUnit = false;
...@@ -120,18 +126,18 @@ class Report { ...@@ -120,18 +126,18 @@ class Report {
$this->showDebugInfo = ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes'); $this->showDebugInfo = ($this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) === 'yes');
$this->page_control["msgbox"]["pagec"] = "Please confirm!"; $this->pageDefaults["msgbox"]["pagec"] = "Please confirm!";
$this->page_control["sip"]["paged"] = TOKEN_SIP; $this->pageDefaults["sip"]["paged"] = TOKEN_SIP;
$this->page_control["sip"]["pagee"] = TOKEN_SIP; $this->pageDefaults["sip"]["pagee"] = TOKEN_SIP;
$this->page_control["sip"]["pagen"] = TOKEN_SIP; $this->pageDefaults["sip"]["pagen"] = TOKEN_SIP;
$this->page_control["icon"]["paged"] = TOKEN_DELETE; $this->pageDefaults["icon"]["paged"] = TOKEN_DELETE;
$this->page_control["icon"]["pagee"] = TOKEN_EDIT; $this->pageDefaults["icon"]["pagee"] = TOKEN_EDIT;
$this->page_control["icon"]["pageh"] = TOKEN_HELP; $this->pageDefaults["icon"]["pageh"] = TOKEN_HELP;
$this->page_control["icon"]["pagei"] = TOKEN_INFO; $this->pageDefaults["icon"]["pagei"] = TOKEN_INFO;
$this->page_control["icon"]["pagen"] = TOKEN_NEW; $this->pageDefaults["icon"]["pagen"] = TOKEN_NEW;
$this->page_control["icon"]["pages"] = TOKEN_SHOW; $this->pageDefaults["icon"]["pages"] = TOKEN_SHOW;
$this->db = new Database(); $this->db = new Database();
$this->utils = new Utils(); $this->utils = new Utils();
...@@ -320,10 +326,15 @@ class Report { ...@@ -320,10 +326,15 @@ class Report {
} }
if ($fnBody) { if ($fnBody) {
error_reporting(error_reporting() & ~E_NOTICE);
$sortFn = create_function('$a,$b', $fnBody); $sortFn = create_function('$a,$b', $fnBody);
// TODO: at the moment, $sortFn() triggers some E_NOTICE warnings. We stop these here for a short time.
$errorSet = error_reporting();
error_reporting($errorSet & ~E_NOTICE);
usort($ary, $sortFn); usort($ary, $sortFn);
error_reporting(error_reporting() | E_NOTICE);
error_reporting($errorSet);
} }
} }
...@@ -784,52 +795,65 @@ class Report { ...@@ -784,52 +795,65 @@ class Report {
* *
* $columnValue: * $columnValue:
* ------------- * -------------
* [<page id|alias>[&param=value&...]] | [record id] | [text] | [tooltip] | [msgbox] | [class] | [target] | [render mode] | [create hash] * [<page id|alias>[&param=value&...]] | [text] | [tooltip] | [msgbox] | [class] | [target] | [render mode]
* *
* param[0]: <page id|alias>[&param=value&...] * param[0]: <page id|alias>[&param=value&...]
* param[1]: record id
* param[2]: text * param[2]: text
* param[3]: tooltip * param[3]: tooltip
* param[4]: msgbox * param[4]: msgbox
* param[5]: class * param[5]: class
* param[6]: target * param[6]: target
* param[7]: render mode * param[7]: render mode
* param[8]: create hash
* @throws SyntaxReportException * @throws SyntaxReportException
*/ */
private function doFixColPosPage($columnName, $columnValue) { private function doFixColPosPage($columnName, $columnValue) {
$link = ""; $link = "";
if (empty($columnName))
return '';
// Split definition // Split definition
$param = explode('|', $columnValue); $allParam = explode('|', $columnValue);
if (count($param) > 8) 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", "", null, __FILE__, __LINE__, $this->fr_error);
// make first 'P' lowercase $columnName[0] = 'p'; // make first 'P' lowercase
$columnName[0] = 'p';
// First Parameter: Split PageId|PageAlias and URL Params
$firstParam = explode('&', $allParam[0], 2);
if (empty($firstParam[1])) {
$firstParam[] = '';
}
$link .= $this->composeLinkPart(TOKEN_PAGE, $firstParam[0]); // -- PageID --
$link .= $this->composeLinkPart(TOKEN_URL_PARAM, $firstParam[1]);
if (!empty($allParam[1]))
$link .= $this->composeLinkPart(TOKEN_TEXT, $allParam[1]); // -- Text --
if (!empty($allParam[2]))
$link .= $this->composeLinkPart(TOKEN_TOOL_TIP, $allParam[2]); // -- tooltip --
if (!empty($allParam[3]))
$link .= $this->composeLinkPart(TOKEN_QUESTION, $allParam[3], $this->pageDefaults["msgbox"][$columnName]); // -- msgbox
if (!empty($allParam[4]))
$link .= $this->composeLinkPart(TOKEN_CLASS, $allParam[4]); // -- class --
// -- Page -- if (!empty($allParam[5]))
// Split PageId|PageAlias and URL Params $link .= $this->composeLinkPart(TOKEN_TARGET, $allParam[5]); // -- target --
$tmparr = explode('&', $param[0], 2);
$link .= $this->composeLinkPart(TOKEN_PAGE, $tmparr[0]); // -- PageID -- if (!empty($allParam[6]))
$link .= $this->composeLinkPart(TOKEN_URL_PARAM, $tmparr[1]); $link .= $this->composeLinkPart(TOKEN_RENDER, $allParam[6]); // -- render mode --
$link .= $this->composeLinkPart(TOKEN_TEXT, $param[1]); // -- Text --
$link .= $this->composeLinkPart(TOKEN_TOOL_TIP, $param[2]); // -- tooltip --
$link .= $this->composeLinkPart(TOKEN_QUESTION, $param[3], $this->page_control["msgbox"][$columnName]); // -- msgbox
$link .= $this->composeLinkPart(TOKEN_CLASS, $param[4]); // -- class --
$link .= $this->composeLinkPart(TOKEN_TARGET, $param[5]); // -- target --
$link .= $this->composeLinkPart(TOKEN_RENDER, $param[6]); // -- render mode --
if (!$param[7]) if (!empty($allParam[7]))
$param[7] = $this->page_control["sip"][$columnName]; // if no hash behaviour defined, use default $allParam[7] = $this->pageDefaults["sip"][$columnName]; // if no SIP behaviour defined, use default
if ($param[7] === TOKEN_SIP) $link .= TOKEN_SIP . "|"; // page always get a sip
$link .= TOKEN_SIP . "|";
if ($this->page_control["icon"][$columnName]) if ($this->pageDefaults["icon"][$columnName])
$link .= $this->page_control["icon"][$columnName] . "|"; $link .= $this->pageDefaults["icon"][$columnName] . "|";
return ($link); return ($link);
} }
...@@ -854,9 +878,10 @@ class Report { ...@@ -854,9 +878,10 @@ class Report {
*/ */
private function composeLinkPart($qualifier, $value, $defaultValue = "") { private function composeLinkPart($qualifier, $value, $defaultValue = "") {
if (!$value) $value = $defaultValue; if (empty($value))
$value = $defaultValue;
if ($value) if (!empty($value))
return ($qualifier . ":" . $value . "|"); return ($qualifier . ":" . $value . "|");
return ''; return '';
...@@ -877,11 +902,11 @@ class Report { ...@@ -877,11 +902,11 @@ class Report {
$param = explode('|', $columnValue); $param = explode('|', $columnValue);
# get all defaultvalues, depending on the columnname # get all defaultvalues, depending on the columnname
$defaultImage = $this->page_control["icon"][$columnName]; $defaultImage = $this->pageDefaults["icon"][$columnName];
$defaultHash = $this->page_control["sip"][$columnName]; $defaultHash = $this->pageDefaults["sip"][$columnName];
# define defaultquestion only, if pagetype needs a question # define defaultquestion only, if pagetype needs a question
if ($this->page_control["msgbox"][$columnName]) $defaultQuestion = 'q:' . $this->page_control["msgbox"][$columnName]; if ($this->pageDefaults["msgbox"][$columnName]) $defaultQuestion = 'q:' . $this->pageDefaults["msgbox"][$columnName];
foreach ($param as $key) { foreach ($param as $key) {
switch (substr($key, 0, 1)) { switch (substr($key, 0, 1)) {
......
...@@ -43,8 +43,17 @@ class LinkTest extends \PHPUnit_Framework_TestCase { ...@@ -43,8 +43,17 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$result = $link->renderLink('u:http://example.com'); $result = $link->renderLink('u:http://example.com');
$this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result); $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);
$result = $link->renderLink('u:http://example.com?id=100&t=2&param=hello');
$this->assertEquals('<a href="http://example.com?id=100&t=2&param=hello" class="external" >http://example.com?id=100&t=2&param=hello</a>', $result);
$result = $link->renderLink('u:example.com');
$this->assertEquals('<a href="example.com" class="external" >example.com</a>', $result);
$result = $link->renderLink('u:http://example.com|t:Hello world'); $result = $link->renderLink('u:http://example.com|t:Hello world');
$this->assertEquals('<a href="http://example.com" class="external" >Hello world</a>', $result); $this->assertEquals('<a href="http://example.com" class="external" >Hello world</a>', $result);
$result = $link->renderLink('u:http://example.com?id=100&t=2&param=hello|t:Hello world');
$this->assertEquals('<a href="http://example.com?id=100&t=2&param=hello" class="external" >Hello world</a>', $result);
} }
/** /**
...@@ -77,6 +86,9 @@ class LinkTest extends \PHPUnit_Framework_TestCase { ...@@ -77,6 +86,9 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$result = $link->renderLink('p:id=secondPage'); $result = $link->renderLink('p:id=secondPage');
$this->assertEquals('<a href="?id=secondPage" class="internal" >?id=secondPage</a>', $result); $this->assertEquals('<a href="?id=secondPage" class="internal" >?id=secondPage</a>', $result);
$result = $link->renderLink('p:id=secondPage&id=100&t=2&param=hello');
$this->assertEquals('<a href="?id=secondPage&id=100&t=2&param=hello" class="internal" >?id=secondPage&id=100&t=2&param=hello</a>', $result);
$result = $link->renderLink('p:secondPage|t:Hello world'); $result = $link->renderLink('p:secondPage|t:Hello world');
$this->assertEquals('<a href="?id=secondPage" class="internal" >Hello world</a>', $result); $this->assertEquals('<a href="?id=secondPage" class="internal" >Hello world</a>', $result);
} }
...@@ -888,12 +900,12 @@ class LinkTest extends \PHPUnit_Framework_TestCase { ...@@ -888,12 +900,12 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$link = new Link(null, $this->sip, true); $link = new Link(null, $this->sip, true);
// Sip: URL // Sip: URL
$result = $link->renderLink('u:?form&r=12&xId=2345|s'); $result = $link->renderLink('u:?form&r=12&xId=2345&L=1&type=99&gId=55|s');
$this->assertEquals('<a href="index.php?id=form&s=badcaffee1234" class="external" >index.php?id=form&s=badcaffee1234</a>', $result); $this->assertEquals('<a href="index.php?id=form&L=1&type=99&s=badcaffee1234" class="external" >index.php?id=form&L=1&type=99&s=badcaffee1234</a>', $result);
// Sip: Page // Sip: Page
$result = $link->renderLink('p:form&r=12&xId=2345|s'); $result = $link->renderLink('p:form&r=12&xId=2345&L=1&type=99&gId=55|s');
$this->assertEquals('<a href="index.php?id=form&s=badcaffee1234" class="internal" >index.php?id=form&s=badcaffee1234</a>', $result); $this->assertEquals('<a href="index.php?id=form&L=1&type=99&s=badcaffee1234" class="internal" >index.php?id=form&L=1&type=99&s=badcaffee1234</a>', $result);
} }
......
...@@ -182,6 +182,30 @@ class ReportTest extends AbstractDatabaseTest { ...@@ -182,6 +182,30 @@ class ReportTest extends AbstractDatabaseTest {
} }
/**
*
*/
public function testReportPageToken() {
//
// $result = $this->report->process("10.sql = SELECT 'p:form&r=123&a=hello&type=5&L=3&final=world|t:Person' AS _page FROM Person ORDER BY id LIMIT 1");
// $this->assertEquals('', $result);
}
/**
*
*/
public function testReportPageFix() {
//
// $result = $this->report->process("10.sql = SELECT 'form|r=123&a=hello&type=5&L=3&final=world|Person' AS _Page FROM Person ORDER BY id LIMIT 1");
// $this->assertEquals('', $result);
}
/** /**
* @throws Exception * @throws Exception
......
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