Bug #21676 ยป 15382_01.diff
tests/t3lib/t3lib_divTest.php (working copy) | ||
---|---|---|
*/
|
||
class t3lib_divTest extends tx_phpunit_testcase {
|
||
/**
|
||
* backup of the global variables _GET, _POST, _SERVER
|
||
*
|
||
* @var array
|
||
* Enable backup of global and system variables
|
||
*/
|
||
private $backupGlobalVariables;
|
||
protected $backupGlobals = TRUE;
|
||
public function setUp() {
|
||
$this->backupGlobalVariables = array(
|
||
'_GET' => $_GET,
|
||
'_POST' => $_POST,
|
||
'_SERVER' => $_SERVER,
|
||
'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
|
||
);
|
||
}
|
||
public function tearDown() {
|
||
foreach ($this->backupGlobalVariables as $key => $data) {
|
||
$GLOBALS[$key] = $data;
|
||
}
|
||
}
|
||
///////////////////////////////
|
||
// Tests concerning validIP
|
||
///////////////////////////////
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::validIP() returns true for valid IPs
|
||
*
|
||
* @test
|
||
* @see t3lib_div::validIP()
|
||
* @dataProvider validIpDataProvider
|
||
*/
|
||
public function checkValidIpReturnsTrueForValidIp($ip) {
|
||
public function validIpReturnsTrueForValidIp($ip) {
|
||
$this->assertTrue(t3lib_div::validIP($ip));
|
||
}
|
||
... | ... | |
'string empty' => array(''),
|
||
'string null' => array('null'),
|
||
'out of bounds IPv4' => array('300.300.300.300'),
|
||
'wrong dotted decimal notation with only two dots' => array('127.0.1'),
|
||
'dotted decimal notation with only two dots' => array('127.0.1'),
|
||
);
|
||
}
|
||
/**
|
||
* Checks if t3lib_div::validIP() returns false for invalid IPs
|
||
*
|
||
* @test
|
||
* @see t3lib_div::validIP()
|
||
* @dataProvider invalidIpDataProvider
|
||
*/
|
||
public function checkValidIpReturnsFalseForInvalidIp($ip) {
|
||
public function validIpReturnsFalseForInvalidIp($ip) {
|
||
$this->assertFalse(t3lib_div::validIP($ip));
|
||
}
|
||
... | ... | |
///////////////////////////////
|
||
/**
|
||
* @test
|
||
* Data provider for splitCalc
|
||
*
|
||
* @return array expected values, arithmetic expression
|
||
*/
|
||
public function splitCalcForEmptyStringReturnsEmptyArray() {
|
||
$this->assertEquals(
|
||
array(),
|
||
t3lib_div::splitCalc('', '+-*/')
|
||
public function splitCalcDataProvider() {
|
||
return array(
|
||
'empty string returns empty array' => array(
|
||
array(),
|
||
'',
|
||
),
|
||
'number without operator returns array with plus and number' => array(
|
||
array(array('+', 42)),
|
||
'42',
|
||
),
|
||
'two numbers with asterisk return first number with plus and second number with asterisk' => array(
|
||
array(array('+', 42), array('*', 31)),
|
||
'42 * 31',
|
||
),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @dataProvider splitCalcDataProvider
|
||
*/
|
||
public function splitCalcForNumberWithoutOperatorReturnsArrayWithPlusAndNumber() {
|
||
$this->assertEquals(
|
||
array(array('+', 42)),
|
||
t3lib_div::splitCalc('42', '+-*/')
|
||
);
|
||
public function splitCalcCorrectlySplitsExpression($expected, $expression) {
|
||
$this->assertEquals($expected, t3lib_div::splitCalc($expression, '+-*/'));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function splitCalcForTwoNumbersWithAsterikReturnsFirstNumberWithPlusAndSecondNumberWithOperator() {
|
||
$this->assertEquals(
|
||
array(
|
||
array('+', 42),
|
||
array('*', 31),
|
||
),
|
||
t3lib_div::splitCalc('42 * 31', '+-*/')
|
||
);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning calcPriority
|
||
//////////////////////////////////
|
||
/**
|
||
* @see calcPriorityCalculatesBasicArithmeticOperation
|
||
* Data provider for calcPriority
|
||
*
|
||
* @return array expected values, arithmetic expression
|
||
*/
|
||
public function calcPriorityTwoOperandsDataProvider() {
|
||
public function calcPriorityDataProvider() {
|
||
return array(
|
||
'add' => array(9, '6 + 3'),
|
||
'substractWithPositiveResult' => array(3, '6 - 3'),
|
||
'substractWithNegativeResult' => array(-3, '3 - 6'),
|
||
'substract with positive result' => array(3, '6 - 3'),
|
||
'substract with negative result' => array(-3, '3 - 6'),
|
||
'multiply' => array(6, '2 * 3'),
|
||
'divide' => array(2.5, '5 / 2'),
|
||
'modulus' => array(1, '5 % 2'),
|
||
'power' => array(8, '2 ^ 3'),
|
||
'three operands with non integer result' => array(6.5, '5 + 3 / 2'),
|
||
'three operands with power' => array(14, '5 + 3 ^ 2'),
|
||
'three operads with modulus' => array(4, '5 % 2 + 3'),
|
||
'four operands' => array(3, '2 + 6 / 2 - 2'),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
*
|
||
* @dataProvider calcPriorityTwoOperandsDataProvider
|
||
*
|
||
* @param string $expected the expected value from calcPriority
|
||
* @param string $arithmeticExpression the string to feed to calcPriority
|
||
* @dataProvider calcPriorityDataProvider
|
||
*/
|
||
public function calcPriorityCalculatesBasicArithmeticOperation($expected, $arithmeticExpression) {
|
||
$this->assertEquals(
|
||
$expected,
|
||
t3lib_div::calcPriority($arithmeticExpression)
|
||
);
|
||
public function calcPriorityCorrectlyCalculatesExpression($expected, $expression) {
|
||
$this->assertEquals($expected, t3lib_div::calcPriority($expression));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function calcPriorityCalculatesArithmeticOperationWithMultipleOperands() {
|
||
$this->assertEquals(6.5, t3lib_div::calcPriority('5 + 3 / 2'));
|
||
$this->assertEquals(14, t3lib_div::calcPriority('5 + 3 ^ 2'));
|
||
$this->assertEquals(4, t3lib_div::calcPriority('5 % 2 + 3'));
|
||
$this->assertEquals(3, t3lib_div::calcPriority('2 + 6 / 2 - 2'));
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning intExplode
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkIntExplodeConvertsStringsToInteger() {
|
||
public function intExplodeConvertsStringsToInteger() {
|
||
$testString = '1,foo,2';
|
||
$expectedArray = array(1, 0, 2);
|
||
$actualArray = t3lib_div::intExplode(',', $testString);
|
||
... | ... | |
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning revExplode
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkRevExplodeCorrectlyExplodesString() {
|
||
public function revExplodeExplodesString() {
|
||
$testString = 'my:words:here';
|
||
$expectedArray = array('my:words', 'here');
|
||
$actualArray = t3lib_div::revExplode(':', $testString, 2);
|
||
... | ... | |
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning trimExplode
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
*/
|
||
... | ... | |
public function checkTrimExplodeRemovesNewLines() {
|
||
$testString = ' a , b , ' . LF . ' ,d ,, e,f,';
|
||
$expectedArray = array('a', 'b', 'd', 'e', 'f');
|
||
$actualArray = t3lib_div::trimExplode(',', $testString, true);
|
||
$actualArray = t3lib_div::trimExplode(',', $testString, TRUE);
|
||
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
... | ... | |
public function checkTrimExplodeRemovesEmptyElements() {
|
||
$testString = 'a , b , c , ,d ,, ,e,f,';
|
||
$expectedArray = array('a', 'b', 'c', 'd', 'e', 'f');
|
||
$actualArray = t3lib_div::trimExplode(',', $testString, true);
|
||
$actualArray = t3lib_div::trimExplode(',', $testString, TRUE);
|
||
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
... | ... | |
*/
|
||
public function checkTrimExplodeKeepsRemainingResultsWithEmptyItemsAfterReachingLimitWithPositiveParameter() {
|
||
$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, false, 3);
|
||
$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);
|
||
}
|
||
... | ... | |
*/
|
||
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);
|
||
$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);
|
||
}
|
||
... | ... | |
*/
|
||
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);
|
||
$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);
|
||
}
|
||
... | ... | |
*/
|
||
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);
|
||
$expectedArray = array('a', 'b', 'c');
|
||
// Limiting returns the rest of the string as the last element
|
||
$actualArray = t3lib_div::trimExplode(',', $testString, TRUE, -3);
|
||
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
... | ... | |
*/
|
||
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);
|
||
$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);
|
||
}
|
||
... | ... | |
public function checkTrimExplodeKeepsZeroAsString() {
|
||
$testString = 'a , b , c , ,d ,, ,e,f, 0 ,';
|
||
$expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0');
|
||
$actualArray = t3lib_div::trimExplode(',', $testString, true);
|
||
$actualArray = t3lib_div::trimExplode(',', $testString, TRUE);
|
||
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning removeArrayEntryByValue
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
*/
|
||
... | ... | |
$this->assertEquals($expectedResult, $actualResult);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning getBytesFromSizeMeasurement
|
||
//////////////////////////////////
|
||
/**
|
||
* Checks whether measurement strings like "100k" return the accordant
|
||
* byte representation like 102400 in this case.
|
||
* Data provider for getBytesFromSizeMeasurement
|
||
*
|
||
* @test
|
||
* @return array expected value, input string
|
||
*/
|
||
public function checkGetBytesFromSizeMeasurement() {
|
||
$this->assertEquals(
|
||
'102400',
|
||
t3lib_div::getBytesFromSizeMeasurement('100k')
|
||
public function getBytesFromSizeMeasurementDataProvider() {
|
||
return array(
|
||
'100 kilo Bytes' => array('102400', '100k'),
|
||
'100 mega Bytes' => array('104857600', '100m'),
|
||
'100 giga Bytes' => array('107374182400', '100g'),
|
||
);
|
||
$this->assertEquals(
|
||
'104857600',
|
||
t3lib_div::getBytesFromSizeMeasurement('100m')
|
||
);
|
||
$this->assertEquals(
|
||
'107374182400',
|
||
t3lib_div::getBytesFromSizeMeasurement('100g')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @dataProvider getBytesFromSizeMeasurementDataProvider
|
||
*/
|
||
public function checkIndpEnvTypo3SitePathNotEmpty() {
|
||
$actualEnv = t3lib_div::getIndpEnv('TYPO3_SITE_PATH');
|
||
$this->assertTrue(strlen($actualEnv) >= 1);
|
||
$this->assertEquals('/', $actualEnv{0});
|
||
$this->assertEquals('/', $actualEnv{strlen($actualEnv) - 1});
|
||
public function getBytesFromSizeMeasurementCalculatesCorrectByteValue($expected, $byteString) {
|
||
$this->assertEquals($expected, t3lib_div::getBytesFromSizeMeasurement($byteString));
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::underscoredToUpperCamelCase
|
||
*/
|
||
public function canConvertFromUnderscoredToUpperCamelCase() {
|
||
$this->assertEquals('BlogExample', t3lib_div::underscoredToUpperCamelCase('blog_example'));
|
||
$this->assertEquals('Blogexample', t3lib_div::underscoredToUpperCamelCase('blogexample'));
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning getIndpEnv
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::underscoredToLowerCamelCase
|
||
*/
|
||
public function canConvertFromUnderscoredToLowerCamelCase() {
|
||
$this->assertEquals('minimalValue', t3lib_div::underscoredToLowerCamelCase('minimal_value'));
|
||
$this->assertEquals('minimalvalue', t3lib_div::underscoredToLowerCamelCase('minimalvalue'));
|
||
public function getIndpEnvTypo3SitePathReturnNonEmptyString() {
|
||
$this->assertTrue(strlen(t3lib_div::getIndpEnv('TYPO3_SITE_PATH')) >= 1);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::camelCaseToLowerCaseUnderscored
|
||
*/
|
||
public function canConvertFromCamelCaseToLowerCaseUnderscored() {
|
||
$this->assertEquals('blog_example', t3lib_div::camelCaseToLowerCaseUnderscored('BlogExample'));
|
||
$this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('Blogexample'));
|
||
$this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('blogexample'));
|
||
$this->assertEquals('minimal_value', t3lib_div::camelCaseToLowerCaseUnderscored('minimalValue'));
|
||
public function getIndpEnvTypo3SitePathReturnsStringStartingWithSlash() {
|
||
$result = t3lib_div::getIndpEnv('TYPO3_SITE_PATH');
|
||
$this->assertEquals('/', $result[0]);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::lcfirst
|
||
*/
|
||
public function canConvertFirstCharacterToBeLowerCase() {
|
||
$this->assertEquals('blogexample', t3lib_div::lcfirst('Blogexample'));
|
||
$this->assertEquals('blogExample', t3lib_div::lcfirst('BlogExample'));
|
||
$this->assertEquals('blogexample', t3lib_div::lcfirst('blogexample'));
|
||
public function getIndpEnvTypo3SitePathReturnsStringEndingWithSlash() {
|
||
$result = t3lib_div::getIndpEnv('TYPO3_SITE_PATH');
|
||
$this->assertEquals('/', $result[strlen($result) - 1]);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning underscoredToUpperCamelCase
|
||
//////////////////////////////////
|
||
/**
|
||
* Tests whether whitespaces are encoded correctly in a quoted-printable mail header.
|
||
* @test
|
||
* Data provider for underscoredToUpperCamelCase
|
||
*
|
||
* @return array expected, input string
|
||
*/
|
||
public function areWhitespacesEncodedInQuotedPrintableMailHeader() {
|
||
$this->assertEquals(
|
||
'=?utf-8?Q?We_test_whether_the_copyright_character_=C2=A9_is_encoded_correctly?=',
|
||
t3lib_div::encodeHeader(
|
||
"We test whether the copyright character \xc2\xa9 is encoded correctly",
|
||
'quoted-printable',
|
||
'utf-8'
|
||
)
|
||
public function underscoredToUpperCamelCaseDataProvider() {
|
||
return array(
|
||
'single word' => array('Blogexample', 'blogexample'),
|
||
'multiple words' => array('BlogExample', 'blog_example'),
|
||
);
|
||
}
|
||
/**
|
||
* Tests whether question marks are encoded correctly in a quoted-printable mail header.
|
||
* @test
|
||
* @dataProvider underscoredToUpperCamelCaseDataProvider
|
||
*/
|
||
public function areQuestionMarksEncodedInQuotedPrintableMailHeader() {
|
||
$this->assertEquals(
|
||
'=?utf-8?Q?Is_the_copyright_character_=C2=A9_really_encoded_correctly=3F_Really=3F?=',
|
||
t3lib_div::encodeHeader(
|
||
"Is the copyright character \xc2\xa9 really encoded correctly? Really?",
|
||
'quoted-printable',
|
||
'utf-8'
|
||
)
|
||
);
|
||
public function underscoredToUpperCamelCase($expected, $inputString) {
|
||
$this->assertEquals($expected, t3lib_div::underscoredToUpperCamelCase($inputString));
|
||
}
|
||
/**
|
||
* Data provider for valid URLs, like PHP's source code test cases
|
||
*/
|
||
public function validUrlDataProvider() {
|
||
return array(
|
||
array('http://example.com/index.html'),
|
||
array('http://www.example.com/index.php'),
|
||
array('http://www.example/img/test.png'),
|
||
array('http://www.example/img/dir/'),
|
||
array('http://www.example/img/dir'),
|
||
array('file:///tmp/test.c'),
|
||
array('ftp://ftp.example.com/tmp/'),
|
||
array('mailto:foo@bar.com'),
|
||
array('news:news.php.net'),
|
||
array('file://foo/bar'),
|
||
array('http://qwe'),
|
||
);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning underscoredToLowerCamelCase
|
||
//////////////////////////////////
|
||
/**
|
||
* Data provider for invalid URLs, like PHP's source code test cases
|
||
* Data provider for underscoredToLowerCamelCase
|
||
*
|
||
* @return array expected, input string
|
||
*/
|
||
public function invalidUrlDataProvider() {
|
||
public function underscoredToLowerCamelCaseDataProvider() {
|
||
return array(
|
||
array('http//www.example/wrong/url/'),
|
||
array('http:/www.example'),
|
||
array('/tmp/test.c'),
|
||
array('/'),
|
||
array('http://'),
|
||
array('http:/'),
|
||
array('http:'),
|
||
array('http'),
|
||
array(''),
|
||
array('-1'),
|
||
array('array()'),
|
||
array('qwe'),
|
||
'single word' => array('minimalvalue', 'minimalvalue'),
|
||
'multiple words' => array('minimalValue', 'minimal_value'),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @dataProvider validUrlDataProvider
|
||
* @see t3lib_div::isValidUrl()
|
||
* @dataProvider underscoredToLowerCamelCaseDataProvider
|
||
*/
|
||
public function checkisValidURL($url) {
|
||
$this->assertTrue(t3lib_div::isValidUrl($url));
|
||
public function underscoredToLowerCamelCase($expected, $inputString) {
|
||
$this->assertEquals($expected, t3lib_div::underscoredToLowerCamelCase($inputString));
|
||
}
|
||
/**
|
||
* @test
|
||
* @dataProvider invalidUrlDataProvider
|
||
* @see t3lib_div::isValidUrl()
|
||
*/
|
||
public function checkisInValidURL($url) {
|
||
$this->assertFalse(t3lib_div::isValidUrl($url));
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning camelCaseToLowerCaseUnderscored
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidUrl()
|
||
* Data provider for camelCaseToLowerCaseUnderscored
|
||
*
|
||
* @return array expected, input string
|
||
*/
|
||
public function checkisValidURLSucceedsWithWebRessource() {
|
||
$testUrl = 'http://www.example.org/';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
public function camelCaseToLowerCaseUnderscoredDataProvider() {
|
||
return array(
|
||
'single word' => array('blogexample', 'blogexample'),
|
||
'single word starting upper case' => array('blogexample', 'Blogexample'),
|
||
'two words starting lower case' => array('minimal_value', 'minimalValue'),
|
||
'two words starting upper case' => array('blog_example', 'BlogExample'),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidUrl()
|
||
* @dataProvider camelCaseToLowerCaseUnderscoredDataProvider
|
||
*/
|
||
public function checkisValidURLSucceedsWithExtentedWebRessource() {
|
||
$testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
public function camelCaseToLowerCaseUnderscored($expected, $inputString) {
|
||
$this->assertEquals($expected, t3lib_div::camelCaseToLowerCaseUnderscored($inputString));
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning lcFirst
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidUrl()
|
||
* Data provider for lcFirst
|
||
*
|
||
* @return array expected, input string
|
||
*/
|
||
public function checkisValidURLSucceedsWithTelnetRessource() {
|
||
$testUrl = 'telnet://192.0.2.16:80/';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
public function lcfirstDataProvider() {
|
||
return array(
|
||
'single word' => array('blogexample', 'blogexample'),
|
||
'single Word starting upper case' => array('blogexample', 'Blogexample'),
|
||
'two words' => array('blogExample', 'BlogExample'),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @dataProvider lcfirstDataProvider
|
||
*/
|
||
public function checkisValidURLSucceedsWithLdapRessource() {
|
||
$testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
public function lcFirst($expected, $inputString) {
|
||
$this->assertEquals($expected, t3lib_div::lcfirst($inputString));
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning encodeHeader
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidUrl()
|
||
*/
|
||
public function checkisValidURLSucceedsWithFileRessource() {
|
||
$testUrl = 'file:///etc/passwd';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
public function encodeHeaderEncodesWhitespacesInQuotedPrintableMailHeader() {
|
||
$this->assertEquals(
|
||
'=?utf-8?Q?We_test_whether_the_copyright_character_=C2=A9_is_encoded_correctly?=',
|
||
t3lib_div::encodeHeader(
|
||
"We test whether the copyright character \xc2\xa9 is encoded correctly",
|
||
'quoted-printable',
|
||
'utf-8'
|
||
)
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isValidUrl()
|
||
*/
|
||
public function checkisValidURLFailsWithHostnameOnly() {
|
||
$testUrl = 'www.example.org/';
|
||
$this->assertFalse(t3lib_div::isValidUrl($testUrl));
|
||
public function encodeHeaderEncodesQuestionmarksInQuotedPrintableMailHeader() {
|
||
$this->assertEquals(
|
||
'=?utf-8?Q?Is_the_copyright_character_=C2=A9_really_encoded_correctly=3F_Really=3F?=',
|
||
t3lib_div::encodeHeader(
|
||
"Is the copyright character \xc2\xa9 really encoded correctly? Really?",
|
||
'quoted-printable',
|
||
'utf-8'
|
||
)
|
||
);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning isValidUrl
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isOnCurrentHost()
|
||
* Data provider for valid isValidUrl's
|
||
*
|
||
* @return array Valid ressource
|
||
*/
|
||
public function checkisOnCurrentHostFailsWithLocalhostIPOnly() {
|
||
$testUrl = '127.0.0.1';
|
||
$this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
|
||
public function validUrlValidRessourceDataProvider() {
|
||
return array(
|
||
'http' => array('http://www.example.org/'),
|
||
'http without trailing slash' => array('http://qwe'),
|
||
'http directory with trailing slash' => array('http://www.example/img/dir/'),
|
||
'http directory without trailing slash' => array('http://www.example/img/dir'),
|
||
'http index.html' => array('http://example.com/index.html'),
|
||
'http index.php' => array('http://www.example.com/index.php'),
|
||
'http test.png' => array('http://www.example/img/test.png'),
|
||
'http username password querystring and ancher' => array('https://user:pw@www.example.org:80/path?arg=value#fragment'),
|
||
'file' => array('file:///tmp/test.c'),
|
||
'file directory' => array('file://foo/bar'),
|
||
'ftp directory' => array('ftp://ftp.example.com/tmp/'),
|
||
'mailto' => array('mailto:foo@bar.com'),
|
||
'news' => array('news:news.php.net'),
|
||
'telnet'=> array('telnet://192.0.2.16:80/'),
|
||
'ldap' => array('ldap://[2001:db8::7]/c=GB?objectClass?one'),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isOnCurrentHost()
|
||
* @dataProvider validUrlValidRessourceDataProvider
|
||
*/
|
||
public function checkisOnCurrentHostFailsWithPathsOnly() {
|
||
$testUrl = './relpath/file.txt';
|
||
$this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
|
||
$testUrl = '/abspath/file.txt?arg=value';
|
||
$this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
|
||
public function validURLReturnsTrueForValidRessource($url) {
|
||
$this->assertTrue(t3lib_div::isValidUrl($url));
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isOnCurrentHost()
|
||
* Data provider for invalid isValidUrl's
|
||
*
|
||
* @return array Invalid ressource
|
||
*/
|
||
public function checkisOnCurrentHostFailsWithArbitraryString() {
|
||
$testUrl = 'arbitrary string';
|
||
$this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
|
||
public function isValidUrlInvalidRessourceDataProvider() {
|
||
return array(
|
||
'http missing colon' => array('http//www.example/wrong/url/'),
|
||
'http missing slash' => array('http:/www.example'),
|
||
'hostname only' => array('www.example.org/'),
|
||
'file missing protocol specification' => array('/tmp/test.c'),
|
||
'slash only' => array('/'),
|
||
'string http://' => array('http://'),
|
||
'string http:/' => array('http:/'),
|
||
'string http:' => array('http:'),
|
||
'string http' => array('http'),
|
||
'empty string' => array(''),
|
||
'string -1' => array('-1'),
|
||
'string array()' => array('array()'),
|
||
'random string' => array('qwe'),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isOnCurrentHost()
|
||
* @dataProvider isValidUrlInvalidRessourceDataProvider
|
||
*/
|
||
public function checkisOnCurrentHostFailsWithEmptyUrl() {
|
||
$testUrl = '';
|
||
$this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
|
||
public function validURLReturnsFalseForInvalidRessoure($url) {
|
||
$this->assertFalse(t3lib_div::isValidUrl($url));
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning isOnCurrentHost
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isOnCurrentHost()
|
||
*/
|
||
public function checkisOnCurrentHostFailsWithDifferentHost() {
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org';
|
||
$this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
|
||
public function isOnCurrentHostReturnsTrueWithCurrentHost() {
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
|
||
$this->assertTrue(t3lib_div::isOnCurrentHost($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::isOnCurrentHost()
|
||
* Data provider for invalid isOnCurrentHost's
|
||
*
|
||
* @return array Invalid Hosts
|
||
*/
|
||
public function checkisOnCurrentHostSucceedsWithCurrentHost() {
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
|
||
$this->assertTrue(t3lib_div::isOnCurrentHost($testUrl));
|
||
public function checkisOnCurrentHostInvalidHosts() {
|
||
return array(
|
||
'empty string' => array(''),
|
||
'arbitrary string' => array('arbitrary string'),
|
||
'localhost IP' => array('127.0.0.1'),
|
||
'relative path' => array('./relpath/file.txt'),
|
||
'absolute path' => array('/abspath/file.txt?arg=value'),
|
||
'differnt host' => array(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org'),
|
||
);
|
||
}
|
||
... | ... | |
////////////////////////////////////////
|
||
/**
|
||
* Data provider for valid URLs.
|
||
* @see sanitizeLocalUrlAcceptsValidUrls
|
||
* Data provider for valid sanitizeLocalUrl's
|
||
*
|
||
* @return array Valid url
|
||
*/
|
||
public function validLocalUrlDataProvider() {
|
||
public function sanitizeLocalUrlValidUrlDataProvider() {
|
||
$subDirectory = t3lib_div::getIndpEnv('TYPO3_SITE_PATH');
|
||
$typo3SiteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
|
||
$typo3RequestHost = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
|
||
... | ... | |
}
|
||
/**
|
||
* Data provider for invalid URLs.
|
||
* @see sanitizeLocalUrlDeniesInvalidUrls
|
||
*/
|
||
public function invalidLocalUrlDataProvider() {
|
||
return array(
|
||
array(''),
|
||
array('http://www.google.de/'),
|
||
array('https://www.google.de/'),
|
||
array('../typo3/whatever.php?argument=javascript:alert(0)'),
|
||
);
|
||
}
|
||
/**
|
||
* Tests whether valid local URLs are handled correctly.
|
||
* @dataProvider validLocalUrlDataProvider
|
||
* @test
|
||
* @dataProvider sanitizeLocalUrlValidUrlDataProvider
|
||
*/
|
||
public function sanitizeLocalUrlAcceptsPlainValidUrls($url) {
|
||
public function sanitizeLocalUrlAcceptsNotEncodedValidUrls($url) {
|
||
$this->assertEquals($url, t3lib_div::sanitizeLocalUrl($url));
|
||
}
|
||
/**
|
||
* Tests whether valid local URLs are handled correctly.
|
||
* @dataProvider validLocalUrlDataProvider
|
||
* @test
|
||
* @dataProvider sanitizeLocalUrlValidUrlDataProvider
|
||
*/
|
||
public function sanitizeLocalUrlAcceptsEncodedValidUrls($url) {
|
||
$this->assertEquals(rawurlencode($url), t3lib_div::sanitizeLocalUrl(rawurlencode($url)));
|
||
}
|
||
/**
|
||
* Tests whether valid local URLs are handled correctly.
|
||
* @dataProvider invalidLocalUrlDataProvider
|
||
* Data provider for invalid sanitizeLocalUrl's
|
||
*
|
||
* @return array Valid url
|
||
*/
|
||
public function sanitizeLocalUrlInvalidDataProvider() {
|
||
return array(
|
||
'empty string' => array(''),
|
||
'http domain' => array('http://www.google.de/'),
|
||
'https domain' => array('https://www.google.de/'),
|
||
'relative path with XSS' => array('../typo3/whatever.php?argument=javascript:alert(0)'),
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @dataProvider sanitizeLocalUrlInvalidDataProvider
|
||
*/
|
||
public function sanitizeLocalUrlDeniesPlainInvalidUrls($url) {
|
||
$this->assertEquals('', t3lib_div::sanitizeLocalUrl($url));
|
||
}
|
||
/**
|
||
* Tests whether valid local URLs are handled correctly.
|
||
* @dataProvider invalidLocalUrlDataProvider
|
||
* @test
|
||
* @dataProvider sanitizeLocalUrlInvalidDataProvider
|
||
*/
|
||
public function sanitizeLocalUrlDeniesEncodedInvalidUrls($url) {
|
||
$this->assertEquals('', t3lib_div::sanitizeLocalUrl(rawurlencode($url)));
|
||
}
|
||
//////////////////////////////////////
|
||
// Tests concerning arrayDiffAssocRecursive
|
||
//////////////////////////////////////
|
||
/**
|
||
* Test if a one dimensional array is correctly diffed.
|
||
*
|
||
* @test
|
||
* @see t3lib_div::arrayDiffAssocRecursive
|
||
*/
|
||
public function doesArrayDiffAssocRecursiveCorrectlyHandleOneDimensionalArrays() {
|
||
public function arrayDiffAssocRecursiveHandlesOneDimensionalArrays() {
|
||
$array1 = array(
|
||
'key1' => 'value1',
|
||
'key2' => 'value2',
|
||
... | ... | |
}
|
||
/**
|
||
* Test if a three dimensional array is correctly diffed.
|
||
*
|
||
* @test
|
||
* @see t3lib_div::arrayDiffAssocRecursive
|
||
*/
|
||
public function doesArrayDiffAssocRecursiveCorrectlyHandleMultiDimensionalArrays() {
|
||
public function arrayDiffAssocRecursiveHandlesMultiDimensionalArrays() {
|
||
$array1 = array(
|
||
'key1' => 'value1',
|
||
'key2' => array(
|
||
... | ... | |
}
|
||
/**
|
||
* Test if arrays are correctly diffed if types are different.
|
||
*
|
||
* @test
|
||
* @see t3lib_div::arrayDiffAssocRecursive
|
||
*/
|
||
public function doesArrayDiffAssocRecursiveCorrectlyHandleMixedArrays() {
|
||
public function arrayDiffAssocRecursiveHandlesMixedArrays() {
|
||
$array1 = array(
|
||
'key1' => array(
|
||
'key11' => 'value11',
|
||
... | ... | |
$this->assertEquals($expectedResult, $actualResult);
|
||
}
|
||
//////////////////////////////////////
|
||
// Tests concerning removeDotsFromTS
|
||
//////////////////////////////////////
|
||
/**
|
||
* Tests whether removeDotsFromTS() behaves correctly.
|
||
* @test
|
||
* @see t3lib_div::removeDotsFromTS()
|
||
*/
|
||
public function doesRemoveDotsFromTypoScriptSucceed() {
|
||
public function removeDotsFromTypoScriptSucceedsWithDottedArray() {
|
||
$typoScript = array(
|
||
'propertyA.' => array(
|
||
'keyA.' => array(
|
||
... | ... | |
}
|
||
/**
|
||
* Tests whether removeDotsFromTS() behaves correctly.
|
||
* @test
|
||
* @see t3lib_div::removeDotsFromTS()
|
||
*/
|
||
public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithArray() {
|
||
public function removeDotsFromTypoScriptOverridesSubArray() {
|
||
$typoScript = array(
|
||
'propertyA.' => array(
|
||
'keyA' => 'getsOverridden',
|
||
... | ... | |
}
|
||
/**
|
||
* Tests whether removeDotsFromTS() behaves correctly.
|
||
* @test
|
||
* @see t3lib_div::removeDotsFromTS()
|
||
*/
|
||
public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithScalar() {
|
||
public function removeDotsFromTypoScriptOverridesWithScalar() {
|
||
$typoScript = array(
|
||
'propertyA.' => array(
|
||
'keyA.' => array(
|
||
... | ... | |
$this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
|
||
}
|
||
//////////////////////////////////////
|
||
// Tests concerning get_dirs
|
||
//////////////////////////////////////
|
||
/**
|
||
* Tests whether getDirs() returns an array of diretories from a given path
|
||
* @test
|
||
* @see t3lib_div::getDirs($path)
|
||
*/
|
||
public function checkGetDirsReturnsArrayOfDirectoriesFromGivenDirectory() {
|
||
public function getDirsReturnsArrayOfDirectoriesFromGivenDirectory() {
|
||
$path = PATH_t3lib;
|
||
$directories = t3lib_div::get_dirs($path);
|
||
... | ... | |
}
|
||
/**
|
||
* Tests whether getDirs() returns the string 'error' in case of problems reading from the given path
|
||
* @test
|
||
* @see t3lib_div::getDirs($path)
|
||
*/
|
||
public function checkGetDirsReturnsStringErrorOnPathFailure() {
|
||
public function getDirsReturnsStringErrorOnPathFailure() {
|
||
$path = 'foo';
|
||
$result = t3lib_div::get_dirs($path);
|
||
$expectedResult = 'error';
|
||
... | ... | |
/**
|
||
* @test
|
||
*/
|
||
public function hmacReturnsNotEqualHashesForNotEqualInput() {
|
||
public function hmacReturnsNoEqualHashesForNonEqualInput() {
|
||
$msg0 = 'message0';
|
||
$msg1 = 'message1';
|
||
$this->assertNotEquals(t3lib_div::hmac($msg0), t3lib_div::hmac($msg1));
|
||
... | ... | |
);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning readLLfile
|
||
//////////////////////////////////
|
||
/**
|
||
* Tests the locallangXMLOverride feature of readLLfile()
|
||
* @test
|
||
*/
|
||
public function readLLfileLocallangXMLOverride() {
|
||
public function readLLfileHandlesLocallangXMLOverride() {
|
||
$unique = uniqid('locallangXMLOverrideTest');
|
||
$xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||
... | ... | |
$file = PATH_site . 'typo3temp/' . $unique . '.xml';
|
||
t3lib_div::writeFileToTypo3tempDir($file, $xml);
|
||
// get default value
|
||
// Get default value
|
||
$defaultLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
|
||
// set override file
|
||
// Set override file
|
||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file;
|
||
// get override value
|
||
// Get override value
|
||
$overrideLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
|
||
// Clean up again
|
||
unlink($file);
|
||
$this->assertNotEquals($overrideLL['default']['buttons.logout'], '');
|
||
$this->assertNotEquals($defaultLL['default']['buttons.logout'], $overrideLL['default']['buttons.logout']);
|
||
$this->assertEquals($overrideLL['default']['buttons.logout'], 'EXIT');
|
||
unlink($file);
|
||
}
|
||
... | ... | |
/**
|
||
* @test
|
||
*/
|
||
public function getSetCanSetWholeArray() {
|
||
public function getSetWritesArrayToGetSystemVariable() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
t3lib_div::_GETset(array('oneKey' => 'oneValue'));
|
||
$this->assertEquals(
|
||
array('oneKey' => 'oneValue'),
|
||
$_GET
|
||
);
|
||
$this->assertEquals(
|
||
array('oneKey' => 'oneValue'),
|
||
$GLOBALS['HTTP_GET_VARS']
|
||
);
|
||
$getParameters = array('foo' => 'bar');
|
||
t3lib_div::_GETset($getParameters);
|
||
$this->assertSame($getParameters, $_GET);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function getSetWritesArrayToGlobalsHttpGetVars() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
$getParameters = array('foo' => 'bar');
|
||
t3lib_div::_GETset($getParameters);
|
||
$this->assertSame($getParameters, $GLOBALS['HTTP_GET_VARS']);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function getSetForArrayDropsExistingValues() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
t3lib_div::_GETset(array('foo' => 'bar'));
|
||
t3lib_div::_GETset(array('oneKey' => 'oneValue'));
|
||
$this->assertEquals(
|
||
array('oneKey' => 'oneValue'),
|
||
$_GET
|
||
);
|
||
$this->assertEquals(
|
||
array('oneKey' => 'oneValue'),
|
||
$GLOBALS['HTTP_GET_VARS']
|
||
);
|
||
}
|
||
... | ... | |
/**
|
||
* @test
|
||
*/
|
||
public function getSetCanAssignOneValueToOneKey() {
|
||
public function getSetAssignsOneValueToOneKey() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
... | ... | |
$this->assertEquals(
|
||
'oneValue',
|
||
$_GET['oneKey']
|
||
);
|
||
$this->assertEquals(
|
||
'oneValue',
|
||
$GLOBALS['HTTP_GET_VARS']['oneKey']
|
||
);
|
||
}
|
||
... | ... | |
/**
|
||
* @test
|
||
*/
|
||
public function getSetForOneValueNotDropsExistingValues() {
|
||
public function getSetForOneValueDoesNotDropUnrelatedValues() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
... | ... | |
$this->assertEquals(
|
||
array('foo' => 'bar', 'oneKey' => 'oneValue'),
|
||
$_GET
|
||
);
|
||
$this->assertEquals(
|
||
array('foo' => 'bar', 'oneKey' => 'oneValue'),
|
||
$GLOBALS['HTTP_GET_VARS']
|
||
);
|
||
}
|
||
... | ... | |
/**
|
||
* @test
|
||
*/
|
||
public function getSetCanAssignAnArrayToSpecificArrayElement() {
|
||
public function getSetCanAssignsAnArrayToASpecificArrayElement() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
... | ... | |
$this->assertEquals(
|
||
array('parentKey' => array('childKey' => 'oneValue')),
|
||
$_GET
|
||
);
|
||
$this->assertEquals(
|
||
array('parentKey' => array('childKey' => 'oneValue')),
|
||
$GLOBALS['HTTP_GET_VARS']
|
||
);
|
||
}
|
||
... | ... | |
/**
|
||
* @test
|
||
*/
|
||
public function getSetCanAssignAValueToSpecificArrayChildElement() {
|
||
public function getSetCanAssignAStringValueToASpecificArrayChildElement() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
... | ... | |
$this->assertEquals(
|
||
array('parentKey' => array('childKey' => 'oneValue')),
|
||
$_GET
|
||
);
|
||
$this->assertEquals(
|
||
array('parentKey' => array('childKey' => 'oneValue')),
|
||
$GLOBALS['HTTP_GET_VARS']
|
||
);
|
||
}
|
||
... | ... | |
/**
|
||
* @test
|
||
*/
|
||
public function getSetCanAssignAnArrayToSpecificArrayChildElement() {
|
||
public function getSetCanAssignAnArrayToASpecificArrayChildElement() {
|
||
$_GET = array();
|
||
$GLOBALS['HTTP_GET_VARS'] = array();
|
||
... | ... | |
'childKey' => array('key1' => 'value1', 'key2' => 'value2')
|
||
)
|
||
),
|
||
$_GET
|
||
);
|
||
$this->assertEquals(
|
||
array(
|
||
'parentKey' => array(
|
||
'childKey' => array('key1' => 'value1', 'key2' => 'value2')
|
||
)
|
||
),
|
||
$GLOBALS['HTTP_GET_VARS']
|
||
);
|
||
}
|
||
///////////////////////////////
|
||
// Tests concerning fixPermissions
|
||
///////////////////////////////
|
||
/**
|
||
* Checks if t3lib_div::fixPermissions() correctly sets permissions to single file
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
* This test is not available on windows OS
|
||
*
|
||
* @test
|
||
* @see t3lib_div::fixPermissions()
|
||
*/
|
||
public function checkFixPermissionsCorrectlySetsPermissionsToFile() {
|
||
public function fixPermissionsCorrectlySetsPermissionsToFile() {
|
||
if (TYPO3_OS == 'WIN') {
|
||
$this->markTestSkipped('fixPermissions() tests not available on Windows');
|
||
}
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden file
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
* This test is not available on windows OS
|
||
*
|
||
* @test
|
||
* @see t3lib_div::fixPermissions()
|
||
*/
|
||
public function checkFixPermissionsCorrectlySetsPermissionsToHiddenFile() {
|
||
public function fixPermissionsCorrectlySetsPermissionsToHiddenFile() {
|
||
if (TYPO3_OS == 'WIN') {
|
||
$this->markTestSkipped('fixPermissions() tests not available on Windows');
|
||
}
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::fixPermissions() correctly sets permissions to directory with trailing slash
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
* This test is not available on windows OS
|
||
*
|
||
* @test
|
||
* @see t3lib_div::fixPermissions()
|
||
*/
|
||
public function checkFixPermissionsCorrectlySetsPermissionsToDirectory() {
|
||
public function fixPermissionsCorrectlySetsPermissionsToDirectory() {
|
||
if (TYPO3_OS == 'WIN') {
|
||
$this->markTestSkipped('fixPermissions() tests not available on Windows');
|
||
}
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden directory
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
* This test is not available on windows OS
|
||
*
|
||
* @test
|
||
* @see t3lib_div::fixPermissions()
|
||
*/
|
||
public function checkFixPermissionsCorrectlySetsPermissionsToHiddenDirectory() {
|
||
public function fixPermissionsCorrectlySetsPermissionsToHiddenDirectory() {
|
||
if (TYPO3_OS == 'WIN') {
|
||
$this->markTestSkipped('fixPermissions() tests not available on Windows');
|
||
}
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::fixPermissions() correctly sets permissions recursivly
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
* This test is not available on windows OS
|
||
*
|
||
* @test
|
||
* @see t3lib_div::fixPermissions()
|
||
*/
|
||
public function checkFixPermissionsCorrectlySetsPermissionsRecursive() {
|
||
public function fixPermissionsCorrectlySetsPermissionsRecursive() {
|
||
if (TYPO3_OS == 'WIN') {
|
||
$this->markTestSkipped('fixPermissions() tests not available on Windows');
|
||
}
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::fixPermissions() does not fix permissions on not allowed path
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
* This test is not available on windows OS
|
||
*
|
||
* @test
|
||
* @see t3lib_div::fixPermissions()
|
||
*/
|
||
public function checkFixPermissionsDoesNotSetPermissionsToNotAllowedPath() {
|
||
public function fixPermissionsDoesNotSetPermissionsToNotAllowedPath() {
|
||
if (TYPO3_OS == 'WIN') {
|
||
$this->markTestSkipped('fixPermissions() tests not available on Windows');
|
||
}
|
||
... | ... | |
$this->assertEquals($resultFilePermissions, '0742');
|
||
}
|
||
///////////////////////////////
|
||
// Tests concerning mkdir
|
||
///////////////////////////////
|
||
/**
|
||
* Checks if t3lib_div::mkdir() correctly creates a directory
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
*
|
||
* @test
|
||
* @see t3lib_div::mkdir()
|
||
*/
|
||
public function checkMkdirCorrectlyCreatesDirectory() {
|
||
public function mkdirCorrectlyCreatesDirectory() {
|
||
$directory = PATH_site . 'typo3temp/' . uniqid('test_');
|
||
$mkdirResult = t3lib_div::mkdir($directory);
|
||
$directoryCreated = is_dir($directory);
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::mkdir() correctly creates a hidden directory
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
*
|
||
* @test
|
||
* @see t3lib_div::mkdir()
|
||
*/
|
||
public function checkMkdirCorrectlyCreatesHiddenDirectory() {
|
||
public function mkdirCorrectlyCreatesHiddenDirectory() {
|
||
$directory = PATH_site . 'typo3temp/' . uniqid('.test_');
|
||
$mkdirResult = t3lib_div::mkdir($directory);
|
||
$directoryCreated = is_dir($directory);
|
||
... | ... | |
}
|
||
/**
|
||
* Checks if t3lib_div::mkdir() correctly creates a directory with trailing slash
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
*
|
||
* @test
|
||
* @see t3lib_div::mkdir()
|
||
*/
|
||
public function checkMkdirCorrectlyCreatesDirectoryWithTrailingSlash() {
|
||
public function mkdirCorrectlyCreatesDirectoryWithTrailingSlash() {
|
||
$directory = PATH_site . 'typo3temp/' . uniqid('test_');
|
||
$mkdirResult = t3lib_div::mkdir($directory);
|
||
$directoryCreated = is_dir($directory);
|
||
... | ... | |
$this->assertTrue($directoryCreated);
|
||
}
|
||
///////////////////////////////
|
||
// Tests concerning split_fileref
|
||
///////////////////////////////
|
||
/**
|
||
* Checks if t3lib_div::split_fileref() return NO file extension if incomming $fileref is a folder
|
||
* This test avoid bug #0014845: Filelist module reports "type" of files also for directories
|
||
* This test assumes directory 'PATH_site'/typo3temp exists
|
||
*
|
||
* @test
|
||
* @see t3lib_div::split_fileref()
|
||
*/
|
||
public function checkIfSplitFileRefReturnsFileTypeNotForFolders(){
|
||
public function splitFileRefReturnsFileTypeNotForFolders(){
|
||
$directoryName = uniqid('test_') . '.com';
|
||
$directoryPath = PATH_site . 'typo3temp/';
|
||
$directory = $directoryPath . $directoryName;
|
||
... | ... | |
$fileInfo = t3lib_div::split_fileref($directory);
|
||
$directoryCreated = is_dir($directory);
|
||
$this->assertTrue($directoryCreated);
|
||
rmdir($directory);
|
||
$this->assertTrue($directoryCreated);
|
||
$this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $fileInfo);
|
||
$this->assertEquals($directoryPath, $fileInfo['path']);
|
||
$this->assertEquals($directoryName, $fileInfo['file']);
|
||
$this->assertEquals($directoryName, $fileInfo['filebody']);
|
||
$this->assertEquals('', $fileInfo['fileext']);
|
||
$this->assertArrayNotHasKey('realFileext', $fileInfo);
|
||
rmdir($directory);
|
||
}
|
||
/**
|
||
* @test
|
||
* @see t3lib_div::split_fileref()
|
||
*/
|
||
public function checkIfSplitFileRefReturnsFileTypeForFilesWithoutPathSite() {
|
||
public function splitFileRefReturnsFileTypeForFilesWithoutPathSite() {
|
||
$testFile = 'fileadmin/media/someFile.png';
|
||
$fileInfo = t3lib_div::split_fileref($testFile);
|