forked from adamaveray/shellshock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilitiesTest.php
47 lines (40 loc) · 1.35 KB
/
UtilitiesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Shellshock\Test;
use Shellshock\Utilities;
/**
* @coversDefaultClass \Shellshock\Utilities
*/
class UtilitiesTest extends \PHPUnit_Framework_TestCase {
const TARGET_CLASSNAME = '\\Shellshock\\Utilities';
/**
* @covers ::normalizePath
* @covers ::<!public>
* @dataProvider normalizePathDataProvider
*/
public function testNormalizePath($path, $expected, $message = null){
$this->assertEquals($expected, Utilities::normalizePath($path), $message = null);
}
public function normalizePathDataProvider(){
return [
// Absolute
['/path/to/file', '/path/to/file', 'Absolute paths should not be changed'],
// Relative
['path/to/file', getcwd().'/path/to/file', 'Relative paths should be made absolute'],
['./path/to/file', getcwd().'/./path/to/file', 'Relative paths should be made absolute'],
['', getcwd(), 'Relative paths should be made absolute'],
// Home directory
['~/path/to/file', $_SERVER['HOME'].'/path/to/file', 'Home-relative paths should be expanded'],
['~', $_SERVER['HOME'], 'Home-relative paths should be expanded'],
];
}
/**
* @covers ::normalizePath
* @covers ::<!public>
* @expectedException \RuntimeException
* @backupGlobals enabled
*/
public function testNormalizePathWithoutHome(){
unset($_SERVER['HOME']);
$this->testNormalizePath('~/path/to/file', null, null);
}
}