diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index 2be5492693d4fdb1666b2e17e2aa559cf278ac7a..ad75c01a78b8aaa9c1b1207df8c09d63c7f04202 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -1693,7 +1693,7 @@ class DataHandler { if (!$itemC) { $itemC = 1; } - $maxV = pow(2, $itemC); + $maxV = pow(2, $itemC) - 1; if ($value < 0) { $value = 0; } diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php index 2db34a1def03d1575c44a40d2365604dcf6b4faf..5e1b05dac9c52b0075bbb02f325bc7fd13e1af55 100644 --- a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php +++ b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php @@ -542,4 +542,54 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $mockDataHandler->expects($this->never())->method('deleteAction'); $mockDataHandler->deleteRecord_procBasedOnFieldType($table, 42, 'foo', 'bar', $conf); } + + /** + * @return array + */ + public function checkValue_checkReturnsExpectedValuesDataProvider() { + return array( + 'None item selected' => array( + 0, + 0 + ), + 'All items selected' => array( + 7, + 7 + ), + 'Item 1 and 2 are selected' => array( + 3, + 3 + ), + 'Value is higher than allowed' => array( + 15, + 7 + ), + 'Negative value' => array( + -5, + 0 + ) + ); + } + + /** + * @param string $value + * @param string $expectedValue + * + * @dataProvider checkValue_checkReturnsExpectedValuesDataProvider + * @test + */ + public function checkValue_checkReturnsExpectedValues($value, $expectedValue) { + $expectedResult = array( + 'value' => $expectedValue + ); + $result = array(); + $tcaFieldConfiguration = array( + 'items' => array( + array('Item 1', 0), + array('Item 2', 0), + array('Item 3', 0) + ) + ); + $this->assertSame($expectedResult, $this->fixture->checkValue_check($result, $value, $tcaFieldConfiguration, array())); + } }