Project

General

Profile

Bug #19601 » 0009779_followup.patch

Administrator Admin, 2009-10-20 12:25

View differences:

tests/t3lib/t3lib_div_testcase.php (Arbeitskopie)
/**
* @test
*/
public function checkTrimExplodeLimitsResultsToFirstXElementsWithPositiveParameter() {
public function checkTrimExplodeKeepsRemainingResultsWithEmptyItemsAfterReachingLimitWithPositiveParameter() {
$testString = ' a , b , c , , d,, ,e ';
$expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
$expectedArray = array('a', 'b', 'c,,d,,,e'); // limiting returns the rest of the string as the last element
$actualArray = t3lib_div::trimExplode(',', $testString, false, 3);
$this->assertEquals($expectedArray, $actualArray);
......
/**
* @test
*/
public function checkTrimExplodeLimitsResultsToLastXElementsWithNegativeParameter() {
public function checkTrimExplodeKeepsRemainingResultsWithoutEmptyItemsAfterReachingLimitWithPositiveParameter() {
$testString = ' a , b , c , , d,, ,e ';
$expectedArray = array('a', 'b', 'c,d,e'); // limiting returns the rest of the string as the last element
$actualArray = t3lib_div::trimExplode(',', $testString, true, 3);
$this->assertEquals($expectedArray, $actualArray);
}
/**
* @test
*/
public function checkTrimExplodeKeepsRamainingResultsWithEmptyItemsAfterReachingLimitWithNegativeParameter() {
$testString = ' a , b , c , d, ,e, f , , ';
$expectedArray = array('a', 'b', 'c', 'd', '', 'e'); // limiting returns the rest of the string as the last element
$actualArray = t3lib_div::trimExplode(',', $testString, false, -3);
$this->assertEquals($expectedArray, $actualArray);
}
/**
* @test
*/
public function checkTrimExplodeKeepsRamainingResultsWithoutEmptyItemsAfterReachingLimitWithNegativeParameter() {
$testString = ' a , b , c , d, ,e, f , , ';
$expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
$actualArray = t3lib_div::trimExplode(',', $testString, true, -3);
......
/**
* @test
*/
public function checkTrimExplodeReturnsExactResultsWithoutReachingLimitWithPositiveParameter() {
$testString = ' a , b , , c , , , ';
$expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
$actualArray = t3lib_div::trimExplode(',', $testString, true, 4);
$this->assertEquals($expectedArray, $actualArray);
}
/**
* @test
*/
public function checkTrimExplodeKeepsZeroAsString() {
$testString = 'a , b , c , ,d ,, ,e,f, 0 ,';
$expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0');
t3lib/class.t3lib_div.php (Arbeitskopie)
}
if ($limit != 0) {
$result = array_slice($result, 0, $limit);
if ($limit < 0) {
$result = array_slice($result, 0, $limit);
} elseif (count($result) > $limit) {
$lastElements = array_slice($result, $limit - 1);
$result = array_slice($result, 0, $limit - 1);
$result[] = implode($delim, $lastElements);
}
}
return $result;
(3-3/3)