IncludePathTest.php
2.45 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require_once dirname(__FILE__)."/config.php";
class IncludePathTest extends PHPTAL_TestCase
{
private $cwd;
function testOverride()
{
$path = get_include_path();
PHPTAL::setIncludePath();
$this->assertNotEquals($path,get_include_path());
PHPTAL::restoreIncludePath();
$this->assertEquals($path,get_include_path());
}
function testPreserveCustomPath()
{
set_include_path(get_include_path() . PATH_SEPARATOR . "./my-custom-path-test/");
$this->assertContains("./my-custom-path-test/", $path = get_include_path());
PHPTAL::setIncludePath();
$this->assertNotEquals($path,get_include_path());
PHPTAL::restoreIncludePath();
$this->assertEquals($path,get_include_path());
$this->assertContains("./my-custom-path-test/", get_include_path());
}
function testNesting()
{
$path = get_include_path();
PHPTAL::setIncludePath();
$this->assertNotEquals($path,get_include_path());
PHPTAL::setIncludePath();
$this->assertNotEquals($path,get_include_path());
PHPTAL::setIncludePath();
$this->assertNotEquals($path,get_include_path());
PHPTAL::restoreIncludePath();
$this->assertNotEquals($path,get_include_path());
PHPTAL::restoreIncludePath();
$this->assertNotEquals($path,get_include_path());
PHPTAL::restoreIncludePath();
$this->assertEquals($path,get_include_path());
}
function testIncludePathIsChanged()
{
$cwd = getcwd();
chdir(dirname(__FILE__));
try
{
$this->assertFileNotExists("./PHPTAL/Context.php");
PHPTAL::setIncludePath();
$modified_include_path = get_include_path();
try
{
$fp = @fopen("PHPTAL/Context.php","r",true);
PHPTAL::restoreIncludePath();
}
catch(Exception $e)
{
PHPTAL::restoreIncludePath();
if (!$e instanceof ErrorException) throw $e;
$fp = NULL;
}
$this->assertTrue(!!$fp, "File should be opened via include path: ".$modified_include_path.'; . = '.getcwd());
if ($fp) fclose($fp);
chdir($cwd);
}
catch(Exception $e)
{
chdir($cwd); throw $e;
}
}
}