-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpakeFunctionTest.php
More file actions
66 lines (52 loc) · 1.98 KB
/
pakeFunctionTest.php
File metadata and controls
66 lines (52 loc) · 1.98 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
<?php
class pakeFunctionTest extends UnitTestCase
{
protected $test_dir;
public function setUp()
{
pakeApp::get_instance()->do_option('quiet', null);
$dir = dirname(__FILE__);
$this->test_dir = $dir.DIRECTORY_SEPARATOR.'temporary-files';
if (!is_dir($this->test_dir)) {
mkdir($this->test_dir);
}
$this->_cleanup();
}
function tearDown()
{
$this->_cleanup();
rmdir($this->test_dir);
}
private function _cleanup()
{
foreach (scandir($this->test_dir) as $entry) {
$full_path = $this->test_dir.DIRECTORY_SEPARATOR.$entry;
if (is_file($full_path)) {
unlink($full_path);
}
}
}
public function test_pake_replace_tokens()
{
$test_file_name = 'file1.tpl';
file_put_contents($this->test_dir.DIRECTORY_SEPARATOR.$test_file_name, '{token} {token2}');
pake_replace_tokens($test_file_name, $this->test_dir, '{', '}', array('token' => 'hello', 'token2' => 'world'));
$test_file = $this->test_dir.DIRECTORY_SEPARATOR.$test_file_name;
$replaced = file_get_contents($test_file);
$this->assertEqual('hello world', $replaced);
}
public function test_pake_replace_tokens_finder()
{
$test_file_names = array('file1.tpl', 'file2.tpl', 'file3.tpl');
foreach ($test_file_names as $test_file_name) {
file_put_contents($this->test_dir.DIRECTORY_SEPARATOR.$test_file_name, '{token} {token2}');
}
$files = pakeFinder::type('file')->relative()->in($this->test_dir);
pake_replace_tokens($files, $this->test_dir, '{', '}', array('token' => 'hello', 'token2' => 'world'));
foreach ($test_file_names as $test_file_name) {
$test_file = $this->test_dir.DIRECTORY_SEPARATOR.$test_file_name;
$replaced = file_get_contents($test_file);
$this->assertEqual('hello world', $replaced);
}
}
}