cakephp2-php8/tests/libs/folder.php
pies da79dff7d7 - merged in Brego's SimpleTest implementation, fixed some of the tests (the Folder test fails to delete one of the test directories on my system, so it's not perfectly clean yet)
- Dispatcher sets a Controller::here variable with the real URL used to access the page, so that tag generators can that use an url (linkTo and formTag for example) use the real url, not guess it from the controller and action names which often fails
- Log class works more reliably and a LogError() shortcut function was added
- Nstring class added, to store string-related functions (there are just four yet, including a random password generator and an string-to-array splitter
- SimpleTest library (with Rephlux) included in /vendors; I've tweaked SimpleScorer::inCli() function, because it didn't work on my setup, it should work everywhere now (it checks for empty REQUEST_METHOD, which should only be empty in CLI)

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@248 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-06-18 23:26:35 +00:00

161 lines
No EOL
3.9 KiB
PHP

<?php
uses('folder');
class FolderTest extends UnitTestCase
{
var $folder;
var $testDir;
// constructor of the test suite
function FolderTest()
{
$this->UnitTestCase('Folder test');
}
// called before the test functions will be executed
// this function is defined in PHPUnit_TestCase and overwritten
// here
function setUp()
{
$this->testDir = ROOT.'tmp'.DS.'tests';
touch($this->testDir.DS.'.htaccess');
if (!is_dir($this->testDir.DS.'dir1'))
mkdir($this->testDir.DS.'dir1');
touch($this->testDir.DS.'dir1'.DS.'test1.php');
if (!is_dir($this->testDir.DS.'dir2'))
mkdir($this->testDir.DS.'dir2');
touch($this->testDir.DS.'dir2'.DS.'test2.php');
$this->folder = new Folder($this->testDir);
}
// called after the test functions are executed
// this function is defined in PHPUnit_TestCase and overwritten
// here
function tearDown()
{
unset($this->folder);
unlink($this->testDir.DS.'.htaccess');
unlink($this->testDir.DS.'dir1'.DS.'test1.php');
if (is_dir($this->testDir.DS.'dir1'))
rmdir($this->testDir.DS.'dir1');
unlink($this->testDir.DS.'dir2'.DS.'test2.php');
if (is_dir($this->testDir.DS.'dir2'))
rmdir($this->testDir.DS.'dir2');
unset($this->folder);
}
function testLs()
{
$result = $this->folder->ls();
$expected = array (
array('.svn', 'dir1', 'dir2'),
array('.htaccess')
);
$this->assertEqual($result, $expected, "List directories and files from test dir");
}
function testPwd()
{
$result = $this->folder->pwd();
$this->assertEqual($result, $this->testDir, 'Print current path (test dir)');
}
function testCd()
{
$this->folder->cd($this->testDir);
$result = $this->folder->pwd();
$this->assertEqual($result, $this->testDir, 'Change directory to the actual one');
//THIS ONE IS HACKED... why do i need to give a full path to this method?
$this->folder->cd($this->testDir.DS.'dir1');
$result = $this->folder->pwd();
$this->assertEqual($result, Folder::addPathElement($this->testDir, 'dir1'), 'Change directory to dir1');
}
function testFindRecursive()
{
$result = $this->folder->findRecursive('.*\.php');
$expected = array(Folder::addPathElement($this->folder->pwd().DS.'dir1', 'test1.php'), Folder::addPathElement($this->folder->pwd().DS.'dir2', 'test2.php'));
$this->assertEqual($result, $expected, 'Find .php files');
}
function testIsWindowsPath()
{
$result = Folder::isWindowsPath('C:\foo');
$expected = true;
$this->assertEqual($result, $expected);
$result = Folder::isWindowsPath('/foo/bar');
$expected = false;
$this->assertEqual($result, $expected);
}
function testIsAbsolute()
{
$result = Folder::isAbsolute('foo/bar');
$expected = false;
$this->assertEqual($result, $expected);
$result = Folder::isAbsolute('c:\foo\bar');
$expected = true;
$this->assertEqual($result, $expected);
}
function testAddPathElement()
{
$result = Folder::addPathElement('c:\foo', 'bar');
$expected = 'c:\foo\bar';
$this->assertEqual($result, $expected);
$result = Folder::addPathElement('C:\foo\bar\\', 'baz');
$expected = 'C:\foo\bar\baz';
$this->assertEqual($result, $expected);
$result = Folder::addPathElement('/foo/bar/', 'baz');
$expected = '/foo/bar/baz';
$this->assertEqual($result, $expected);
}
function testIsSlashTerm()
{
$result = Folder::isSlashTerm('/foo/bar/');
$this->assertEqual($result, true);
$result = Folder::isSlashTerm('/foo/bar');
$this->assertEqual($result, false);
}
function testCorrectSlashFor()
{
$result = Folder::correctSlashFor('/foo/bar/');
$this->assertEqual($result, '/');
$result = Folder::correctSlashFor('C:\foo\bar');
$this->assertEqual($result, '\\');
}
function testSlashTerm()
{
$result = Folder::slashTerm('/foo/bar/');
$this->assertEqual($result, '/foo/bar/');
$result = Folder::slashTerm('/foo/bar');
$this->assertEqual($result, '/foo/bar/');
$result = Folder::slashTerm('C:\foo\bar');
$this->assertEqual($result, 'C:\foo\bar\\');
}
}
?>