Commit 3fe7f1fc authored by Carsten  Rose's avatar Carsten Rose
Browse files

Update unit tests, refs #7848

parent f1a7a706
Pipeline #1504 passed with stage
in 2 minutes and 16 seconds
......@@ -1600,17 +1600,17 @@ EOF;
*/
private function buildActionDelete($vars, $value) {
// Minimal check for required parameter.
$vars[NAME_URL_PARAM] = $this->checkDeleteParam($vars[NAME_URL_PARAM]);
if ($vars[NAME_URL_PARAM] == '') {
$vars[NAME_RENDER] = RENDER_MODE_5;
return $vars;
}
// Minimal check for required parameter.
$this->checkDeleteParam($vars[NAME_URL_PARAM]);
// if ($vars[NAME_URL] == '') {
// $vars[NAME_URL] = API_DIR . '/' . API_DELETE_PHP;
// }
if ($vars[NAME_URL] == '') {
$vars[NAME_URL] = API_DIR . '/' . API_DELETE_PHP;
}
if (!isset($vars[NAME_LINK_CLASS])) {
// no_class: By default a button will be rendered.
......@@ -1628,21 +1628,26 @@ EOF;
* In case of missing parameter, throw an exception.
*
* @param $urlParam
*
* @return string
* @throws UserFormException
* @throws UserReportException in case parameter is missing.
* @throws UserReportException
*/
private function checkDeleteParam($urlParam) {
// Fill array 'found' with every given token
$found = KeyValueStringParser::parse($urlParam, '=', '&');
// If there is no 'r' or 'r'=0: no delete button will be rendered
if (!isset($found[SIP_RECORD_ID]) || $found[SIP_RECORD_ID] == '' || $found[SIP_RECORD_ID] == 0) {
return '';
}
$flagRecordId = isset($found[SIP_RECORD_ID]);
$flagTable = isset($found[SIP_TABLE]) && $found[SIP_TABLE] != '';
$flagForm = isset($found[SIP_FORM]) && $found[SIP_FORM] != '';
if ($flagRecordId && ($flagTable || $flagForm)) {
return;
return $urlParam;
}
throw new UserReportException ("Missing some qualifier/value for column " . COLUMN_PAGED . '/' . COLUMN_PPAGED . ": " .
......
......@@ -1466,12 +1466,12 @@ EOF;
* @throws UserFormException
* @throws UserReportException
*/
public function testDeleteException1() {
$link = new Link($this->sip, DB_INDEX_DEFAULT, true);
// Missing recordId
$link->renderLink('U:form=Person&r=|x');
}
// public function testDeleteException1() {
// $link = new Link($this->sip, DB_INDEX_DEFAULT, true);
//
// // Missing recordId
// $link->renderLink('U:form=Person&r=|x');
// }
/**
......
......@@ -872,46 +872,19 @@ EOF;
$result = $this->report->process("10.sql = SELECT 'table=Person&r=123|click me||Move to trash?:success:yes:no:10:0' AS _Paged FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('<a href="' . API_DIR . '/' . API_DELETE_PHP . '?s=badcaffee1234" class="btn btn-default" title="Delete" ' . $js . ' ><span class="glyphicon glyphicon-trash" ></span> click me</a>', $result);
}
/**
* Missing r, missing form or table
*
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws DbException
* @throws DownloadException
* @throws UserFormException
* @throws UserReportException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function testMissingPagedParameterException1() {
$this->report->process("10.sql = SELECT '' AS _Paged FROM Person ORDER BY id LIMIT 1");
}
// Empty string is ok
$result = $this->report->process("10.sql = SELECT '' AS _Paged FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('', $result);
// r=0 is ok
$result = $this->report->process("10.sql = SELECT 'table=Person&r=0' AS _Paged FROM Person ORDER BY id LIMIT 1");
$this->assertEquals('', $result);
/**
* Missing r, given table
*
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws DbException
* @throws DownloadException
* @throws UserFormException
* @throws UserReportException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function testMissingPagedParameterException2() {
$this->report->process("10.sql = SELECT 'table=Person' AS _Paged FROM Person ORDER BY id LIMIT 1");
}
/**
* Missing r, given form
* Missing missing form or table
*
* @expectedException \qfq\UserReportException
*
......@@ -924,10 +897,11 @@ EOF;
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function testMissingPagedParameterException3() {
$this->report->process("10.sql = SELECT 'form=Person' AS _Paged FROM Person ORDER BY id LIMIT 1");
public function testMissingPagedParameterException1() {
$this->report->process("10.sql = SELECT 'something&r=1' AS _Paged FROM Person ORDER BY id LIMIT 1");
}
/**
* missing form, missing table
*
......@@ -946,24 +920,6 @@ EOF;
$this->report->process("10.sql = SELECT 'r=123' AS _Paged FROM Person ORDER BY id LIMIT 1");
}
/**
* missing r, given table
*
* @expectedException \qfq\UserReportException
*
* @throws CodeException
* @throws DbException
* @throws DownloadException
* @throws UserFormException
* @throws UserReportException
* @throws \PhpOffice\PhpSpreadsheet\Exception
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
*/
public function testMissingPagedParameterException5() {
$this->report->process("10.sql = SELECT 'table=Person&r' AS _Paged FROM Person ORDER BY id LIMIT 1");
}
/**
* @expectedException \qfq\UserReportException
*
......
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