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

Weitere Details implementiert fuer _page & _Page.

Unittests fuer _page und _Page.
Link.php: add checkEmptyValue(), checkValue() - code becomes cleaner.
Report.php: diverse Stellen empty() entfernt und durch isset() && ==='' ersetzt. empty() nimmt auch '0' als leeren Wert.
parent e1c2111d
......@@ -160,8 +160,9 @@ const ERROR_IO_CHDIR = 1210;
const ERROR_UNKNOWN_LINK_QUALIFIER = 1300;
const ERROR_UNDEFINED_RENDER_CONTROL_COMBINATION = 1301;
const ERROR_MISSING_VALUE = 1302;
const ERROR_MULTIPLE_DEFINITION = 1303;
const ERROR_MULTIPLE_URL_PAGE_MAILTO_DEFINITION = 1304;
const ERROR_INVALID_VALUE = 1303;
const ERROR_MULTIPLE_DEFINITION = 1304;
const ERROR_MULTIPLE_URL_PAGE_MAILTO_DEFINITION = 1305;
// Upload
const ERROR_UPLOAD = 1400;
......
......@@ -403,28 +403,9 @@ class Link {
$keyName = $this->tableVarName[$key]; // convert token to name
if ($value === '') {
switch ($key) {
case TOKEN_URL:
throw new UserReportException ("Missing value for token '$key'", ERROR_MISSING_VALUE);
break;
case TOKEN_MAIL:
throw new UserReportException ("Missing value for token '$key'", ERROR_MISSING_VALUE);
break;
case TOKEN_PAGE:
$value = $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3); // If no pageid|pagealias is defined, take current page
break;
case TOKEN_RIGHT:
$value = 'r';
break;
case TOKEN_SIP:
$value = '1';
break;
case TOKEN_RENDER:
$value = DEFAULT_RENDER_MODE;
break;
default:
}
$value = $this->checkEmptyValue($key, $value);
}
$value = $this->checkValue($key, $value);
// Store value
$vars[$keyName] = $value;
......@@ -501,6 +482,61 @@ class Link {
}
/**
* @param $key
* @param $value
* @return string
* @throws UserReportException
*/
private function checkEmptyValue($key, $value) {
switch ($key) {
case TOKEN_URL:
throw new UserReportException ("Missing value for token '$key'", ERROR_MISSING_VALUE);
break;
case TOKEN_MAIL:
throw new UserReportException ("Missing value for token '$key'", ERROR_MISSING_VALUE);
break;
case TOKEN_PAGE:
$value = $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3); // If no pageid|pagealias is defined, take current page
break;
case TOKEN_RIGHT:
$value = 'r';
break;
case TOKEN_ENCRYPTION:
$value = '1';
break;
case TOKEN_SIP:
$value = '1';
break;
case TOKEN_RENDER:
$value = DEFAULT_RENDER_MODE;
break;
default:
}
return $value;
}
/**
* @param $key
* @param $value
* @return mixed
* @throws UserReportException
*/
private function checkValue($key, $value) {
switch ($key) {
case TOKEN_ENCRYPTION:
case TOKEN_SIP:
if ($value !== '0' && $value !== '1') {
throw new UserReportException ("Invalied value for token '$key': '$value''", ERROR_INVALID_VALUE);
}
break;
default:
}
return $value;
}
/**
* Check for double definition.
*
......
......@@ -622,7 +622,9 @@ class Report {
case "Pagei":
case "Pagen":
case "Pages":
$linkValue = $this->doFixColPosPage($columnName, $columnValue);
$pageColumnName = strtolower($columnName);
$tokenizedValue = $this->doFixColPosPage($columnName, $columnValue);
$linkValue = $this->doPage($pageColumnName, $tokenizedValue);
$link = new Link($this->fr_error, $this->sip);
$content .= $link->renderLink($linkValue);
break;
......@@ -822,8 +824,6 @@ class Report {
if (count($allParam) > 8)
throw new SyntaxReportException ("Too many parameter (max=8): $columnValue", "", null, __FILE__, __LINE__, $this->fr_error);
$columnName[0] = 'p'; // make first 'P' lowercase
// First Parameter: Split PageId|PageAlias and URL Params
$firstParam = explode('&', $allParam[0], 2);
if (empty($firstParam[1])) {
......@@ -833,31 +833,40 @@ class Report {
$link .= $this->composeLinkPart(TOKEN_PAGE, $firstParam[0]); // -- PageID --
$link .= $this->composeLinkPart(TOKEN_URL_PARAM, $firstParam[1]);
if (!empty($allParam[1]))
if (isset($allParam[1]) && $allParam[1] !== '') {
$link .= $this->composeLinkPart(TOKEN_TEXT, $allParam[1]); // -- Text --
}
if (!empty($allParam[2]))
if (isset($allParam[2]) && $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 (isset($allParam[3]) && $allParam[3] !== '') {
$text = isset($this->pageDefaults["msgbox"][$columnName]) ? $this->pageDefaults["msgbox"][$columnName] : '';
$link .= $this->composeLinkPart(TOKEN_QUESTION, $allParam[3], $text); // -- msgbox
}
if (!empty($allParam[4]))
if (isset($allParam[4]) && $allParam[4] !== '') {
$link .= $this->composeLinkPart(TOKEN_CLASS, $allParam[4]); // -- class --
}
if (!empty($allParam[5]))
if (isset($allParam[5]) && $allParam[5] !== '') {
$link .= $this->composeLinkPart(TOKEN_TARGET, $allParam[5]); // -- target --
}
if (!empty($allParam[6]))
if (isset($allParam[6]) && $allParam[6] !== '') {
$link .= $this->composeLinkPart(TOKEN_RENDER, $allParam[6]); // -- render mode --
}
if (empty($allParam[7]))
if (!isset($allParam[7])) {
$allParam[7] = '1'; // if no SIP behaviour defined: sip is set
}
$link .= $this->composeLinkPart(TOKEN_SIP, $allParam[7]); // -- SIP --
if ($this->pageDefaults["icon"][$columnName])
if (isset($this->pageDefaults["icon"][$columnName])) {
$link .= $this->pageDefaults["icon"][$columnName] . "|";
}
return ($link);
}
......@@ -873,10 +882,10 @@ class Report {
*/
private function composeLinkPart($qualifier, $value, $defaultValue = "") {
if (empty($value))
if ($value === '')
$value = $defaultValue;
if (!empty($value))
if ($value !== '')
return ($qualifier . ":" . $value . "|");
return '';
......
......@@ -25,6 +25,24 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
*/
private $store = null;
/**
* @expectedException \qfq\UserReportException
*/
public function testUnknownTokenException1() {
$link = new Link(null, $this->sip, true);
$link->renderLink('b:hello world');
}
/**
* @expectedException \qfq\UserReportException
*/
public function testUnknownTokenException2() {
$link = new Link(null, $this->sip, true);
$link->renderLink('abc:hello world');
}
/**
* @throws SyntaxReportException
*/
......@@ -147,16 +165,16 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
public function testMailEncryption() {
$link = new Link(null, $this->sip, true);
$result = $link->renderLink('m:john@doe.com|e');
$this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
$result = $link->renderLink('m:john@doe.com|e:');
$this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
//TODO: aktivieren sobald encrypted Mails implemented.
// $result = $link->renderLink('m:john@doe.com|e');
// $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
//
// $result = $link->renderLink('m:john@doe.com|e:');
// $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
$result = $link->renderLink('m:john@doe.com|e:0');
$this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
//TODO: aktivieren sobald encrypted Mails implemented.
// $result = $link->renderLink('m:john@doe.com|e:1');
// $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);
}
......@@ -613,7 +631,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$link = new Link(null, $this->sip, true);
// r: default (0)
$result = $link->renderLink('u:http://www.example.com|P:picture.gif|B');
$link->renderLink('u:http://www.example.com|P:picture.gif|B');
}
/**
......@@ -623,7 +641,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$link = new Link(null, $this->sip, true);
// r: default (0)
$result = $link->renderLink('u:http://www.example.com|C|B');
$link->renderLink('u:http://www.example.com|C|B');
}
/**
......@@ -633,7 +651,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$link = new Link(null, $this->sip, true);
// r: default (0)
$result = $link->renderLink('u:http://www.example.com|B:green|B:red');
$link->renderLink('u:http://www.example.com|B:green|B:red');
}
/**
......@@ -643,7 +661,7 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$link = new Link(null, $this->sip, true);
// r: default (0)
$result = $link->renderLink('u:http://www.example.com|C:green|C:red');
$link->renderLink('u:http://www.example.com|C:green|C:red');
}
/**
......@@ -874,6 +892,27 @@ class LinkTest extends \PHPUnit_Framework_TestCase {
$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);
}
/**
* @expectedException \qfq\UserReportException
*/
public function testSipException1() {
$link = new Link(null, $this->sip, true);
// r: default (0)
$link->renderLink('u:http://www.example.com|s:s');
}
/**
* @expectedException \qfq\UserReportException
*/
public function testSipException2() {
$link = new Link(null, $this->sip, true);
// r: default (0)
$link->renderLink('u:http://www.example.com|s:2');
}
/**
*
......
......@@ -435,11 +435,46 @@ class ReportTest extends AbstractDatabaseTest {
*
*/
public function testReportPageFix() {
// TODO: implement
//
// $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");
// _Page: only pagealias
$result = $this->report->process("10.sql = SELECT 'form' AS _Page FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="index.php?id=form&s=badcaffee1234" class="internal" >index.php?id=form&s=badcaffee1234</a>', $result);
// _Page: pagealias, param
$result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world' AS _Page FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="index.php?id=form&type=5&L=3&s=badcaffee1234" class="internal" >index.php?id=form&type=5&L=3&s=badcaffee1234</a>', $result);
// _Page: pagealias, param, Text
$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('<a href="index.php?id=form&type=5&L=3&s=badcaffee1234" class="internal" >Person</a>', $result);
// _Page: pagealias, param, Text, Tooltip
$result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world|Person|This is a tooltip' AS _Page FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="index.php?id=form&type=5&L=3&s=badcaffee1234" class="internal" title="This is a tooltip" >Person</a>', $result);
// _Page: pagealias, param, Text, Tooltip, Question
// $result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world|Person|This is a tooltip|My Question' AS _Page FROM Person ORDER BY id LIMIT 1");
// $this->assertEquals('', $result);
// _Page: pagealias, param, Text, Tooltip, Question, Class
// $result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world|Person|This is a tooltip|My Question|myclass' AS _Page FROM Person ORDER BY id LIMIT 1");
// $this->assertEquals('', $result);
// _Page: pagealias, param, Text, Tooltip, Question, Class, Target
$result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world|Person|This is a tooltip|My Question|myclass|mytarget' AS _Page FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="index.php?id=form&type=5&L=3&s=badcaffee1234" class="myclass" target="mytarget" title="This is a tooltip" onclick="confirm(\'My Question\')" >Person</a>', $result);
// _Page: pagealias, param, Text, Tooltip, Question, Class, Target, Rendermode
// $result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world|Person|This is a tooltip|My Question|myclass|mytarget|0' AS _Page FROM Person ORDER BY id LIMIT 1");
// $this->assertEquals('', $result);
// _Page: pagealias, param, Text, Tooltip, Question, Class, Target, Rendermode, Sip ON 1
$result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world|Person|This is a tooltip||myclass|mytarget|0|1' AS _Page FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="index.php?id=form&type=5&L=3&s=badcaffee1234" class="myclass" target="mytarget" title="This is a tooltip" >Person</a>', $result);
// _Page: pagealias, param, Text, Tooltip, Question, Class, Target, Rendermode, Sip OFF
$result = $this->report->process("10.sql = SELECT 'form&r=123&a=hello&type=5&L=3&final=world|Person|This is a tooltip||myclass|mytarget|0|0' AS _Page FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="?id=form&r=123&a=hello&type=5&L=3&final=world" class="myclass" target="mytarget" title="This is a tooltip" >Person</a>', $result);
}
......
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