Skip to content

Commit

Permalink
[BUGFIX] Correctly resolve parameter for USER display condition
Browse files Browse the repository at this point in the history
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 <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
IchHabRecht authored and bmack committed Oct 28, 2018
1 parent f1d84ab commit f5b5585
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 35 deletions.
Expand Up @@ -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:
Expand Down
Expand Up @@ -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)
Expand All @@ -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
*/
Expand Down Expand Up @@ -789,7 +838,7 @@ public function addDataThrowsExceptionIfFlexSectionContainerFoundNoReferencedFie
],
],
],
]
],
];
$this->expectException(\RuntimeException::class);
$this->expectExceptionCode(1481634649);
Expand Down Expand Up @@ -1219,8 +1268,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro
'ROOT' => [
'el' => [
'flexField_1' => [],
]
]
],
],
],
'sheet_2' => [
'ROOT' => [
Expand Down Expand Up @@ -1267,8 +1316,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro
'ROOT' => [
'el' => [
'flexField_1' => [],
]
]
],
],
],
'sheet_2' => [
'ROOT' => [
Expand Down Expand Up @@ -1315,8 +1364,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro
'ROOT' => [
'el' => [
'flexField.1' => [],
]
]
],
],
],
'sheet_2' => [
'ROOT' => [
Expand Down Expand Up @@ -1363,8 +1412,8 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro
'ROOT' => [
'el' => [
'flexField.1' => [],
]
]
],
],
],
'sheet_2' => [
'ROOT' => [
Expand Down Expand Up @@ -3409,7 +3458,7 @@ public function addDataRemovesTcaReferencingOtherFieldsInDisplayConditionDataPro
'FIELD:sheet_1.field_1:=:LIST',
'FIELD:sheet_1.field_1:!=:foo',
],
] ,
],
],
],
],
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -3655,15 +3704,15 @@ public function conditionStringDataProvider()
'VERSION:IS:TRUE',
[
'uid' => 42,
'pid' => -1
'pid' => -1,
],
true,
],
'Version is TRUE for not versioned row compared with FALSE' => [
'VERSION:IS:FALSE',
[
'uid' => 42,
'pid' => 1
'pid' => 1,
],
true,
],
Expand All @@ -3683,7 +3732,7 @@ public function conditionStringDataProvider()
],
],
[
'testField' => 10
'testField' => 10,
],
true,
],
Expand All @@ -3692,10 +3741,10 @@ public function conditionStringDataProvider()
'AND' => [
'FIELD:testField:>:9',
'FIELD:testField:<:11',
]
],
],
[
'testField' => 99
'testField' => 99,
],
false,
],
Expand All @@ -3707,7 +3756,7 @@ public function conditionStringDataProvider()
],
],
[
'testField' => 10
'testField' => 10,
],
true,
],
Expand All @@ -3719,7 +3768,7 @@ public function conditionStringDataProvider()
],
],
[
'testField' => 99
'testField' => 99,
],
false,
],
Expand All @@ -3734,7 +3783,7 @@ public function conditionStringDataProvider()
],
],
[
'testField' => 10
'testField' => 10,
],
true,
],
Expand All @@ -3749,7 +3798,7 @@ public function conditionStringDataProvider()
],
],
[
'testField' => -999
'testField' => -999,
],
false,
],
Expand All @@ -3773,10 +3822,10 @@ public function matchConditionStrings($condition, array $record, $expectedResult
'displayCond' => $condition,
'config' => [
'type' => 'input',
]
],
],
]
]
],
],
];

$backendUserAuthenticationProphecy = $this->prophesize(BackendUserAuthentication::class);
Expand Down Expand Up @@ -3818,8 +3867,8 @@ public function matchConditionStringsWithRecordTestFieldBeingArray($condition, a
if (!empty($record['testField'])) {
$input['databaseRow'] = [
'testField' => [
'key' => $record['testField']
]
'key' => $record['testField'],
],
];
}

Expand Down Expand Up @@ -3849,10 +3898,10 @@ public function matchHideForNonAdminsReturnsTrueIfBackendUserIsAdmin()
'displayCond' => 'HIDE_FOR_NON_ADMINS',
'config' => [
'type' => 'input',
]
],
],
]
]
],
],
];

/** @var BackendUserAuthentication|ObjectProphecy backendUserProphecy */
Expand All @@ -3879,10 +3928,10 @@ public function matchHideForNonAdminsReturnsFalseIfBackendUserIsNotAdmin()
'displayCond' => 'HIDE_FOR_NON_ADMINS',
'config' => [
'type' => 'input',
]
],
],
]
]
],
],
];

/** @var BackendUserAuthentication|ObjectProphecy backendUserProphecy */
Expand Down

0 comments on commit f5b5585

Please sign in to comment.