From f1a7a7065444eb0e2d0b65ecde9da4d6d4f8f9c6 Mon Sep 17 00:00:00 2001 From: Carsten Rose Date: Sun, 10 Feb 2019 01:01:26 +0100 Subject: [PATCH 1/2] B7848 extraColumName 'paged' - easier handling in case 'r=0' or empty 'U:...' - fixes #7848 --- extension/Source/core/report/Link.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/extension/Source/core/report/Link.php b/extension/Source/core/report/Link.php index 3b5d2e29..64c2c0da 100644 --- a/extension/Source/core/report/Link.php +++ b/extension/Source/core/report/Link.php @@ -1600,15 +1600,20 @@ EOF; */ private function buildActionDelete($vars, $value) { + 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. NAME_URL typically implies class external. That does not match. + // no_class: By default a button will be rendered. $vars[NAME_LINK_CLASS_DEFAULT] = NO_CLASS; } @@ -1632,7 +1637,7 @@ EOF; // Fill array 'found' with every given token $found = KeyValueStringParser::parse($urlParam, '=', '&'); - $flagRecordId = isset($found[SIP_RECORD_ID]) && $found[SIP_RECORD_ID] != '' && $found[SIP_RECORD_ID] > 0; + $flagRecordId = isset($found[SIP_RECORD_ID]); $flagTable = isset($found[SIP_TABLE]) && $found[SIP_TABLE] != ''; $flagForm = isset($found[SIP_FORM]) && $found[SIP_FORM] != ''; -- GitLab From 3fe7f1fc2cec9306085ffd3ce381571d6a0d96a8 Mon Sep 17 00:00:00 2001 From: Carsten Rose Date: Sun, 10 Feb 2019 01:24:20 +0100 Subject: [PATCH 2/2] Update unit tests, refs #7848 --- extension/Source/core/report/Link.php | 23 ++++--- extension/Tests/unit/core/report/LinkTest.php | 12 ++-- .../Tests/unit/core/report/ReportTest.php | 66 ++++--------------- 3 files changed, 31 insertions(+), 70 deletions(-) diff --git a/extension/Source/core/report/Link.php b/extension/Source/core/report/Link.php index 64c2c0da..b24a3986 100644 --- a/extension/Source/core/report/Link.php +++ b/extension/Source/core/report/Link.php @@ -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 . ": " . diff --git a/extension/Tests/unit/core/report/LinkTest.php b/extension/Tests/unit/core/report/LinkTest.php index 7fa44b24..3b184e86 100644 --- a/extension/Tests/unit/core/report/LinkTest.php +++ b/extension/Tests/unit/core/report/LinkTest.php @@ -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'); +// } /** diff --git a/extension/Tests/unit/core/report/ReportTest.php b/extension/Tests/unit/core/report/ReportTest.php index 60a1fb6b..33ffc629 100644 --- a/extension/Tests/unit/core/report/ReportTest.php +++ b/extension/Tests/unit/core/report/ReportTest.php @@ -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(' click me', $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 * -- GitLab