forked from iangreenleaf/Scisr
/
RenameFileSystemTest.php
93 lines (68 loc) · 3.71 KB
/
RenameFileSystemTest.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
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
92
93
<?php
require_once 'MultipleFileTest.php';
class RenameFileSystemTest extends Scisr_Tests_MultipleFileTestCase
{
public function testRenameFileAndCompareDir() {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileFixture', $this->test_dir);
$this->doRenameFile($this->test_dir . '/stuff.php', $this->test_dir . '/things.php');
$this->compareDir(dirname(__FILE__) . '/_files/renameFileFixture-after-rename-file', $this->test_dir);
}
public function testRenameFileToOtherDirAndCompare() {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileFixture', $this->test_dir);
$this->doRenameFile($this->test_dir . '/stuff.php', $this->test_dir . '/otherfolder/things.php');
$this->compareDir(dirname(__FILE__) . '/_files/renameFileFixture-after-rename-file-other-dir', $this->test_dir);
}
public function testRenameFileToNewDirAndCompare() {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileFixture', $this->test_dir);
$this->doRenameFile($this->test_dir . '/stuff.php', $this->test_dir . '/newfolder/subdir/things.php');
$this->compareDir(dirname(__FILE__) . '/_files/renameFileFixture-after-rename-file-new-dir', $this->test_dir);
}
public function testRenameFileWithRelativePath() {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileFixture', $this->test_dir);
chdir($this->test_dir);
$this->doRenameFile('stuff.php', 'things.php');
$this->compareDir(dirname(__FILE__) . '/_files/renameFileFixture-after-rename-file', $this->test_dir);
}
public function testDontMoveFileInTimidMode() {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileFixture', $this->test_dir);
$s = $this->getScisr();
$s->setEditMode(Scisr::MODE_TIMID);
$s->setRenameFile($this->test_dir . '/test2.php', $this->test_dir . '/otherfolder/things.php');
$s->addFile($this->test_dir);
$s->run();
$this->compareDir(dirname(__FILE__) . '/_files/renameFileFixture', $this->test_dir);
}
/**
* @dataProvider includesRenameProvider
*/
public function testRenameFileAltersIncludes($oldName, $newName, $expectedDir) {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileIncludesFixture', $this->test_dir);
chdir($this->test_dir);
$this->doRenameFile($oldName, $newName);
$this->compareDir(dirname(__FILE__) . '/_files/' . $expectedDir, $this->test_dir);
}
public function includesRenameProvider() {
return array(
array('test.php', 'otherfolder/test.php', 'renameFileIncludesFixture-after-rename-1'),
array('otherfolder/stuff.php', 'stuff.php', 'renameFileIncludesFixture-after-rename-2'),
array('test2.php', 'test3.php', 'renameFileIncludesFixture-after-rename-4'),
array('test2.php', 'otherfolder/test2.php', 'renameFileIncludesFixture-after-rename-5'),
array('test2.php', '../test2.php', 'renameFileIncludesFixture-after-rename-6'),
);
}
public function testRenameFileAltersIncludesSwitchPlaces() {
$this->populateDir(dirname(__FILE__) . '/_files/renameFileIncludesFixture', $this->test_dir);
chdir($this->test_dir);
$this->doRenameFile('otherfolder/stuff.php', 'stuff.php');
// This is kinda hacky, but we need to clear out the static data since we're not creating a second process
Scisr_ChangeRegistry::clearAll();
$this->doRenameFile('test.php', 'otherfolder/test.php');
$this->compareDir(dirname(__FILE__) . '/_files/renameFileIncludesFixture-after-rename-3', $this->test_dir);
}
public function doRenameFile($old, $new) {
$s = $this->getScisr();
$s->setRenameFile($old, $new);
$s->addFile($this->test_dir);
$s->run();
}
}