Commit 72f9e06e authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fix and extend PHP Unit Tests

parent 0a7e2917
Pipeline #800 passed with stage
in 1 minute and 49 seconds
......@@ -107,6 +107,7 @@ const NAME_MONITOR = 'monitor';
const FINAL_HREF = 'finalHref';
const FINAL_ANCHOR = 'finalAnchor';
const FINAL_CONTENT = 'finalContent';
const FINAL_CONTENT_PURE = 'finalContentPure';
const FINAL_SYMBOL = 'finalSymbol';
const FINAL_TOOL_TIP = 'finalToolTip';
const FINAL_CLASS = 'finalClass';
......@@ -335,7 +336,6 @@ class Link {
$this->renderControl[8][0][1] = 0;
$this->renderControl[8][1][0] = 8;
$this->renderControl[8][1][1] = 8;
}
/**
......@@ -587,12 +587,12 @@ class Link {
}
// Download Link needs some extra work
if ($rcTokenGiven[TOKEN_DOWNLOAD]) {
if (isset($rcTokenGiven[TOKEN_DOWNLOAD]) && $rcTokenGiven[TOKEN_DOWNLOAD]) {
$vars = $this->buildDownloadLate($vars);
}
// CopyToClipboard (Download) Link needs some extra work
if ($rcTokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
if (isset($rcTokenGiven[TOKEN_COPY_TO_CLIPBOARD]) && $rcTokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
$vars = $this->buildCopyToClipboardLate($vars);
}
......@@ -763,7 +763,7 @@ class Link {
$vars[FINAL_CLASS] = $this->doCssClass($vars);
$vars[FINAL_SYMBOL] = $this->doSymbol($vars);
$vars[FINAL_THUMBNAIL] = $this->doThumbnail($vars);
$vars[FINAL_CONTENT] = $this->doContent($vars); // must be called after doSymbol()
$vars[FINAL_CONTENT] = $this->doContent($vars, $vars[FINAL_CONTENT_PURE]); // must be called after doSymbol()
$vars[FINAL_QUESTION] = $this->doQuestion($vars);
$vars[FINAL_ANCHOR] = $this->doAnchor($vars);
......@@ -1030,7 +1030,7 @@ class Link {
* @throws UserFormException
* @throws UserReportException
*/
private function doContent(array $vars) {
private function doContent(array $vars, &$contentPure) {
$arr = array();
if ($vars[NAME_MONITOR] == '1') {
......@@ -1044,13 +1044,9 @@ class Link {
$arr[] = $vars[$key];
}
}
$content = implode(' ', $arr);
if ($vars[NAME_EXTRA_CONTENT_WRAP] != '') {
$content = Support::wrapTag($vars[NAME_EXTRA_CONTENT_WRAP], $content);
}
return $content;
$contentPure = implode(' ', $arr);
return Support::wrapTag($vars[NAME_EXTRA_CONTENT_WRAP], $contentPure);
}
/**
......@@ -1168,7 +1164,7 @@ EOF;
*/
private function getModeRender(array $vars, array $tokenGiven) {
if ($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
if (isset($tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) && $tokenGiven[TOKEN_COPY_TO_CLIPBOARD]) {
if ($vars[NAME_RENDER] == '0') {
$vars[NAME_RENDER] = RENDER_MODE_1;
}
......
......@@ -36,6 +36,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testUnknownTokenException1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -45,6 +49,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testUnknownTokenException2() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -53,6 +61,9 @@ class LinkTest extends TestCase {
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testLinkUrlBasic() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -81,6 +92,9 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testLinkUrlBasicExceptionDouble() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -89,26 +103,9 @@ class LinkTest extends TestCase {
}
/**
* @expectedException \qfq\UserReportException
*
*/
public function testLinkUrlBasicExceptionEmpty1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
$link->renderLink('u');
}
/**
* @expectedException \qfq\UserReportException
*
*/
public function testLinkUrlBasicExceptionEmpty2() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
$link->renderLink('u:');
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testLinkPageBasic() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -134,6 +131,9 @@ class LinkTest extends TestCase {
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testLinkMailBasic() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -145,27 +145,11 @@ class LinkTest extends TestCase {
$this->assertEquals('<a href="mailto:john@doe.com" >John Doe</a>', $result);
}
/**
* @expectedException \qfq\UserReportException
*
*/
public function testLinkMailBasicExceptionMissing1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
$link->renderLink('m');
}
/**
* @expectedException \qfq\UserReportException
*
*/
public function testLinkMailBasicExceptionMissing2() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
$link->renderLink('m:');
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testMailEncryption() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -398,6 +382,10 @@ class LinkTest extends TestCase {
}
/**
* @throws UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testRenderModeMail() {
......@@ -482,6 +470,10 @@ class LinkTest extends TestCase {
}
/**
* @throws UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testRenderModeUrlPicture() {
......@@ -567,6 +559,10 @@ class LinkTest extends TestCase {
}
/**
* @throws UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testRenderModeUrlButton() {
......@@ -650,6 +646,10 @@ class LinkTest extends TestCase {
}
/**
* @throws UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testIcons() {
......@@ -678,6 +678,10 @@ class LinkTest extends TestCase {
}
/**
* @throws UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testBullet() {
......@@ -709,6 +713,8 @@ class LinkTest extends TestCase {
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testChecked() {
......@@ -740,6 +746,8 @@ class LinkTest extends TestCase {
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyph() {
......@@ -751,6 +759,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyphException() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -761,6 +773,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testPictureException1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -771,6 +787,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testPictureException2() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -781,6 +801,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testPictureException3() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -791,6 +815,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testPictureException4() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -801,6 +829,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyphExceptionDouble1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -811,6 +843,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyphExceptionDouble2() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -821,6 +857,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyphExceptionDouble3() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -831,6 +871,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyphExceptionDouble4() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -841,6 +885,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyphExceptionDouble5() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -851,6 +899,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testGlyphExceptionDouble6() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -860,6 +912,9 @@ class LinkTest extends TestCase {
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testLinkUrlParam() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -902,6 +957,10 @@ class LinkTest extends TestCase {
}
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testTooltip() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -932,6 +991,10 @@ class LinkTest extends TestCase {
}
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testAltText() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -952,6 +1015,10 @@ class LinkTest extends TestCase {
}
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testClass() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -978,6 +1045,10 @@ class LinkTest extends TestCase {
}
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testTarget() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1004,6 +1075,10 @@ class LinkTest extends TestCase {
}
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testRight() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1039,6 +1114,10 @@ class LinkTest extends TestCase {
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testSip() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1070,6 +1149,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testSipException1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1080,6 +1163,10 @@ class LinkTest extends TestCase {
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testSipException2() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1089,6 +1176,10 @@ class LinkTest extends TestCase {
}
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testQuestion() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1161,7 +1252,9 @@ EOF;
}
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testDelete() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1202,8 +1295,121 @@ EOF;
$this->assertEquals('__dbIndexData=1&_modeAnswer=html&_targetUrl=localhost&form=PersonC&r=1236', $result);
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testBootstrapButton() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
// Empty
$result = $link->renderLink('b');
$this->assertEquals('', $result);
// Just a page
$result = $link->renderLink('b|p:id=fake');
$this->assertEquals('<a href="?id=fake" class="btn btn-default" >?id=fake</a>', $result);
// Just a page
$result = $link->renderLink('b:0|p:id=fake');
$this->assertEquals('<a href="?id=fake" class="0" >?id=fake</a>', $result);
// Just a page
$result = $link->renderLink('b:1|p:id=fake');
$this->assertEquals('<a href="?id=fake" class="btn btn-default" >?id=fake</a>', $result);
// Just a page
$result = $link->renderLink('b:primary|p:id=fake');
$this->assertEquals('<a href="?id=fake" class="btn btn-primary" >?id=fake</a>', $result);
// Just a page
$result = $link->renderLink('b:btn-primary|p:id=fake');
$this->assertEquals('<a href="?id=fake" class="btn btn-primary" >?id=fake</a>', $result);
// Button Text
$result = $link->renderLink('b|p:id=fake|t:Button text');
$this->assertEquals('<a href="?id=fake" class="btn btn-default" >Button text</a>', $result);
// Button Text with Glyph Icon
$result = $link->renderLink('b|p:id=fake|t:Button text|E');
$this->assertEquals('<a href="?id=fake" class="btn btn-default" title="Edit" ><span class="glyphicon glyphicon-pencil" ></span> Button text</a>', $result);
// Button Text with Tooltip
$result = $link->renderLink('b|p:id=fake|t:Button text|o:Tooltip');
$this->assertEquals('<a href="?id=fake" class="btn btn-default" title="Tooltip" >Button text</a>', $result);
// Button Text with render mode r:0
$result = $link->renderLink('b|p:id=fake|t:Button text|r:3');
$this->assertEquals('<span class="btn btn-default disabled" >Button text</span>', $result);
// Button Text with render mode r:1
$result = $link->renderLink('b|p:id=fake|t:Button text|r:5');
$this->assertEquals('', $result);
}
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testDownloadException() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
// Empty
$result = $link->renderLink('d');
}
/**
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testDownload() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
// Single file
$result = $link->renderLink('d|F:file.pdf');
$this->assertEquals('<a href="typo3conf/ext/qfq/qfq/api/download.php?mode=pdf&_exportFilename=&_b64_download=RjpmaWxlLnBkZg==" class="0" title="Download" ><span class="btn btn-default" data-toggle="modal" data-target="#qfqModal101" data-title="Download: " data-text="Please wait" data-backdrop="static" data-keyboard="false" onclick="$(\'#qfqModalTitle101\').text($(this).data(\'title\')); $(\'#qfqModalText101\').text($(this).data(\'text\'));"><span class="glyphicon glyphicon-file" ></span></span></a>', $result);
// With download filename
$result = $link->renderLink('d:download.pdf|F:file.pdf');
$this->assertEquals('<a href="typo3conf/ext/qfq/qfq/api/download.php?mode=pdf&_exportFilename=download.pdf&_b64_download=RjpmaWxlLnBkZg==" class="0" title="Download" ><span class="btn btn-default" data-toggle="modal" data-target="#qfqModal101" data-title="Download: download.pdf" data-text="Please wait" data-backdrop="static" data-keyboard="false" onclick="$(\'#qfqModalTitle101\').text($(this).data(\'title\')); $(\'#qfqModalText101\').text($(this).data(\'text\'));"><span class="glyphicon glyphicon-file" ></span></span></a>', $result);
// Two files
$result = $link->renderLink('d|F:file.pdf|F:file2.pdf');
$this->assertEquals('<a href="typo3conf/ext/qfq/qfq/api/download.php?mode=pdf&_exportFilename=&_b64_download=RjpmaWxlLnBkZnxGOmZpbGUyLnBkZg==" class="0" title="Download" ><span class="btn btn-default" data-toggle="modal" data-target="#qfqModal101" data-title="Download: " data-text="Please wait" data-backdrop="static" data-keyboard="false" onclick="$(\'#qfqModalTitle101\').text($(this).data(\'title\')); $(\'#qfqModalText101\').text($(this).data(\'text\'));"><span class="glyphicon glyphicon-file" ></span></span></a>', $result);
// Mode: PDF
$result = $link->renderLink('d|F:file.pdf|M:pdf');
$this->assertEquals('<a href="typo3conf/ext/qfq/qfq/api/download.php?mode=pdf&_exportFilename=&_b64_download=RjpmaWxlLnBkZg==" class="0" title="Download" ><span class="btn btn-default" data-toggle="modal" data-target="#qfqModal101" data-title="Download: " data-text="Please wait" data-backdrop="static" data-keyboard="false" onclick="$(\'#qfqModalTitle101\').text($(this).data(\'title\')); $(\'#qfqModalText101\').text($(this).data(\'text\'));"><span class="glyphicon glyphicon-file" ></span></span></a>', $result);
// Download with Tooltip
$result = $link->renderLink('d|F:file.pdf|o:Tooltip');
$this->assertEquals('<a href="typo3conf/ext/qfq/qfq/api/download.php?mode=pdf&_exportFilename=&_b64_download=RjpmaWxlLnBkZg==" class="0" title="Tooltip" ><span class="btn btn-default" data-toggle="modal" data-target="#qfqModal101" data-title="Download: " data-text="Please wait" data-backdrop="static" data-keyboard="false" onclick="$(\'#qfqModalTitle101\').text($(this).data(\'title\')); $(\'#qfqModalText101\').text($(this).data(\'text\'));"><span class="glyphicon glyphicon-file" ></span></span></a>', $result);
// Download & Button Text
$result = $link->renderLink('d|F:file.pdf|t:Button text');
$this->assertEquals('<a href="typo3conf/ext/qfq/qfq/api/download.php?mode=pdf&_exportFilename=&_b64_download=RjpmaWxlLnBkZg==" class="0" title="Download" ><span class="btn btn-default" data-toggle="modal" data-target="#qfqModal101" data-title="Download: " data-text="Please wait" data-backdrop="static" data-keyboard="false" onclick="$(\'#qfqModalTitle101\').text($(this).data(\'title\')); $(\'#qfqModalText101\').text($(this).data(\'text\'));"><span class="glyphicon glyphicon-file" ></span> Button text</span></a>', $result);
// Download, r:3
$result = $link->renderLink('d|F:file.pdf|r:3');
$this->assertEquals('<span title="Download" class="btn btn-default disabled"> </span>', $result);
// Download, r:5
$result = $link->renderLink('d|F:file.pdf|r:5');
$this->assertEquals('', $result);
}
/**
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public function testDeleteException1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
......@@ -1214,13 +1420,15 @@ EOF;
/**
*
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
protected function setUp() {
parent::setUp();
$this->store = Store::getInstance('', true);
$this->sip = new Sip('fakesessionname', true);
$this->sip = new Sip(true);
$this->sip->sipUniqId('badcaffee1234');
}
......
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