mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
add filepath normalization tests
This commit is contained in:
@@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the Smarty PHPUnit tests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class for path normalization tests
|
||||||
|
*
|
||||||
|
* @runTestsInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupStaticAttributes enabled
|
||||||
|
*/
|
||||||
|
class PathNormalizationTest extends PHPUnit_Smarty
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Setup test fixture
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->setUpSmarty(__DIR__);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormalizeToAbsolute() {
|
||||||
|
$d = $this->smarty->_realpath('./foo/a.foo', true);
|
||||||
|
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeAbsolute() {
|
||||||
|
if (DIRECTORY_SEPARATOR == '/') {
|
||||||
|
$d = $this->smarty->_realpath('\\foo\\a.foo', true);
|
||||||
|
$this->assertEquals('/foo/a.foo', $d);
|
||||||
|
} else {
|
||||||
|
$d = $this->smarty->_realpath('/foo/a.foo', true);
|
||||||
|
$this->assertEquals(substr(getcwd(), 0, 2) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
$d = $this->smarty->_realpath(substr(getcwd(), 0, 2) . '/foo/a.foo', true);
|
||||||
|
$this->assertEquals(substr(getcwd(), 0, 2) . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsoluteNoStart() {
|
||||||
|
$d = $this->smarty->_realpath('foo/a.foo', true);
|
||||||
|
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsoluteNoStart2() {
|
||||||
|
$d = $this->smarty->_realpath('a.foo', true);
|
||||||
|
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsolutePathLeadingDot() {
|
||||||
|
$d = $this->smarty->_realpath('.foo/a.foo', true);
|
||||||
|
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . '.foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsolutePathTrailingDot() {
|
||||||
|
$d = $this->smarty->_realpath('./foo./a.foo', true);
|
||||||
|
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo.' . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsolutePathBubbleUp() {
|
||||||
|
$ds = '\\' . DIRECTORY_SEPARATOR;
|
||||||
|
$prefix = preg_replace("#[{$ds}][^{$ds}]+$#", '', getcwd());
|
||||||
|
$d = $this->smarty->_realpath('./../a.foo', true);
|
||||||
|
$this->assertEquals($prefix . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsolutePathBubbleUp2() {
|
||||||
|
$ds = '\\' . DIRECTORY_SEPARATOR;
|
||||||
|
$prefix = preg_replace("#[{$ds}][^{$ds}]+$#", '', getcwd());
|
||||||
|
$d = $this->smarty->_realpath('././../././a.foo', true);
|
||||||
|
$this->assertEquals($prefix . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsolutePathBubbleUp3() {
|
||||||
|
$ds = '\\' . DIRECTORY_SEPARATOR;
|
||||||
|
$prefix = preg_replace("#[{$ds}][^{$ds}]+[{$ds}][^{$ds}]+$#", '', getcwd());
|
||||||
|
$d = $this->smarty->_realpath('././.././.././a.foo', true);
|
||||||
|
$this->assertEquals($prefix . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
public function testNormalizeToAbsoluteKomplex() {
|
||||||
|
$d = $this->smarty->_realpath('./foo/\\./bar/jo/wie/so/../../go/../..//.././../a.foo', true);
|
||||||
|
$this->assertEquals(getcwd() . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR . 'a.foo', $d);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
0
tests/UnitTests/A_0/PathNormalization/cache/dummy.txt
vendored
Normal file
0
tests/UnitTests/A_0/PathNormalization/cache/dummy.txt
vendored
Normal file
Reference in New Issue
Block a user