From f5b5585b24e417b3397bca7fc509c87e19fb71ab Mon Sep 17 00:00:00 2001 From: Nicole Cordes Date: Thu, 27 Sep 2018 15:56:11 +0200 Subject: [PATCH] [BUGFIX] Correctly resolve parameter for USER display condition According to the documentation there is no limit of the used additional parameters. However during parameter processing, there is a limit of 4 parameters applied. This limit needs to be unset when dealing with a USER display condition. Resolves: #85274 Releases: master, 8.7 Change-Id: Ieff6d089cbb5540ab1d3b389eb0511ef993b900d Reviewed-on: https://review.typo3.org/58412 Tested-by: TYPO3com Reviewed-by: Daniel Goerz Tested-by: Daniel Goerz Reviewed-by: Benni Mack Tested-by: Benni Mack --- .../EvaluateDisplayConditions.php | 8 +- .../EvaluateDisplayConditionsTest.php | 117 +++++++++++++----- 2 files changed, 90 insertions(+), 35 deletions(-) diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php index e6c72d6ae6eb..d1e55e666fd4 100644 --- a/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php +++ b/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php @@ -418,7 +418,13 @@ protected function parseSingleConditionString(string $conditionString, array $da $namedConditionArray['function'] = $conditionArray[1]; array_shift($conditionArray); array_shift($conditionArray); - $namedConditionArray['parameters'] = $conditionArray; + $parameters = count($conditionArray) < 2 + ? $conditionArray + : array_merge( + [$conditionArray[0]], + GeneralUtility::trimExplode(':', $conditionArray[1]) + ); + $namedConditionArray['parameters'] = $parameters; $namedConditionArray['record'] = $databaseRow; break; default: diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php index a33aeb84b8d4..337927db991f 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php @@ -541,6 +541,7 @@ public function addDataEvaluatesUserCondition() * Callback method of addDataEvaluatesUserCondition. A USER condition * Throws an exception if data is correct! * + * @param array $parameter * @throws \RuntimeException if data is ok */ public function addDataEvaluatesUserConditionCallback(array $parameter) @@ -551,13 +552,61 @@ public function addDataEvaluatesUserConditionCallback(array $parameter) 'conditionParameters' => [ 0 => 'more', 1 => 'arguments', - ] + ], ]; if ($expected === $parameter) { throw new \RuntimeException('testing', 1488130499); } } + /** + * @test + */ + public function addDataResolvesAllUserParameters() + { + $input = [ + 'databaseRow' => [], + 'processedTca' => [ + 'columns' => [ + 'field_1' => [ + 'displayCond' => 'USER:' . self::class . '->addDataResolvesAllUserParametersCallback:some:more:info', + 'config' => [ + 'type' => 'input', + ], + ], + ], + ], + ]; + + $expected = $input; + unset($expected['processedTca']['columns']['field_1']['displayCond']); + + $this->assertSame($expected, (new EvaluateDisplayConditions())->addData($input)); + } + + /** + * Callback method of addDataResolvesAllUserParameters. A USER condition + * receives all condition parameter! + * + * @param array $parameter + * @throws \RuntimeException if condition parameter not resolved correctly + * @return bool + */ + public function addDataResolvesAllUserParametersCallback(array $parameter) + { + $expected = [ + 0 => 'some', + 1 => 'more', + 2 => 'info', + ]; + + if ($expected !== $parameter['conditionParameters']) { + throw new \RuntimeException('testing', 1538055997); + } + + return true; + } + /** * @test */ @@ -789,7 +838,7 @@ public function addDataThrowsExceptionIfFlexSectionContainerFoundNoReferencedFie ], ], ], - ] + ], ]; $this->expectException(\RuntimeException::class); $this->expectExceptionCode(1481634649); @@ -1219,8 +1268,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro 'ROOT' => [ 'el' => [ 'flexField_1' => [], - ] - ] + ], + ], ], 'sheet_2' => [ 'ROOT' => [ @@ -1267,8 +1316,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro 'ROOT' => [ 'el' => [ 'flexField_1' => [], - ] - ] + ], + ], ], 'sheet_2' => [ 'ROOT' => [ @@ -1315,8 +1364,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro 'ROOT' => [ 'el' => [ 'flexField.1' => [], - ] - ] + ], + ], ], 'sheet_2' => [ 'ROOT' => [ @@ -1363,8 +1412,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro 'ROOT' => [ 'el' => [ 'flexField.1' => [], - ] - ] + ], + ], ], 'sheet_2' => [ 'ROOT' => [ @@ -3409,7 +3458,7 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro 'FIELD:sheet_1.field_1:=:LIST', 'FIELD:sheet_1.field_1:!=:foo', ], - ] , + ], ], ], ], @@ -3589,17 +3638,17 @@ public function conditionStringDataProvider() 'Field value comparison of 1 against multi-value field of 5 returns true' => [ 'FIELD:content:BIT:1', ['content' => '5'], - true + true, ], 'Field value comparison of 2 against multi-value field of 5 returns false' => [ 'FIELD:content:BIT:2', ['content' => '5'], - false + false, ], 'Field value of 5 negated comparison against multi-value field of 5 returns false' => [ 'FIELD:content:!BIT:5', ['content' => '5'], - false + false, ], 'Field value comparison for required value is false for different value' => [ 'FIELD:foo:REQ:FALSE', @@ -3655,7 +3704,7 @@ public function conditionStringDataProvider() 'VERSION:IS:TRUE', [ 'uid' => 42, - 'pid' => -1 + 'pid' => -1, ], true, ], @@ -3663,7 +3712,7 @@ public function conditionStringDataProvider() 'VERSION:IS:FALSE', [ 'uid' => 42, - 'pid' => 1 + 'pid' => 1, ], true, ], @@ -3683,7 +3732,7 @@ public function conditionStringDataProvider() ], ], [ - 'testField' => 10 + 'testField' => 10, ], true, ], @@ -3692,10 +3741,10 @@ public function conditionStringDataProvider() 'AND' => [ 'FIELD:testField:>:9', 'FIELD:testField:<:11', - ] + ], ], [ - 'testField' => 99 + 'testField' => 99, ], false, ], @@ -3707,7 +3756,7 @@ public function conditionStringDataProvider() ], ], [ - 'testField' => 10 + 'testField' => 10, ], true, ], @@ -3719,7 +3768,7 @@ public function conditionStringDataProvider() ], ], [ - 'testField' => 99 + 'testField' => 99, ], false, ], @@ -3734,7 +3783,7 @@ public function conditionStringDataProvider() ], ], [ - 'testField' => 10 + 'testField' => 10, ], true, ], @@ -3749,7 +3798,7 @@ public function conditionStringDataProvider() ], ], [ - 'testField' => -999 + 'testField' => -999, ], false, ], @@ -3773,10 +3822,10 @@ public function matchConditionStrings($condition, array $record, $expectedResult 'displayCond' => $condition, 'config' => [ 'type' => 'input', - ] + ], ], - ] - ] + ], + ], ]; $backendUserAuthenticationProphecy = $this->prophesize(BackendUserAuthentication::class); @@ -3818,8 +3867,8 @@ public function matchConditionStringsWithRecordTestFieldBeingArray($condition, a if (!empty($record['testField'])) { $input['databaseRow'] = [ 'testField' => [ - 'key' => $record['testField'] - ] + 'key' => $record['testField'], + ], ]; } @@ -3849,10 +3898,10 @@ public function matchHideForNonAdminsReturnsTrueIfBackendUserIsAdmin() 'displayCond' => 'HIDE_FOR_NON_ADMINS', 'config' => [ 'type' => 'input', - ] + ], ], - ] - ] + ], + ], ]; /** @var BackendUserAuthentication|ObjectProphecy backendUserProphecy */ @@ -3879,10 +3928,10 @@ public function matchHideForNonAdminsReturnsFalseIfBackendUserIsNotAdmin() 'displayCond' => 'HIDE_FOR_NON_ADMINS', 'config' => [ 'type' => 'input', - ] + ], ], - ] - ] + ], + ], ]; /** @var BackendUserAuthentication|ObjectProphecy backendUserProphecy */