Commit b968402e by Alexander Makarov

more tests for FileHelper

parent 582ff594
......@@ -169,7 +169,7 @@ class FileHelperTest extends TestCase
$this->assertFileMode($fileMode, $dstDirName . DIRECTORY_SEPARATOR . $fileName, 'Copied file has wrong mode!');
}
public function stestRemoveDirectory()
public function testRemoveDirectory()
{
$dirName = 'test_dir_for_remove';
$this->createFileStructure(array(
......@@ -189,6 +189,9 @@ class FileHelperTest extends TestCase
FileHelper::removeDirectory($dirName);
$this->assertFalse(file_exists($dirName), 'Unable to remove directory!');
// should be silent about non-existing directories
FileHelper::removeDirectory($basePath . DIRECTORY_SEPARATOR . 'nonExisting');
}
public function testFindFiles()
......@@ -272,8 +275,9 @@ class FileHelperTest extends TestCase
{
$basePath = $this->testFilePath;
$dirName = $basePath . DIRECTORY_SEPARATOR . 'test_dir_level_1' . DIRECTORY_SEPARATOR . 'test_dir_level_2';
FileHelper::mkdir($dirName);
$this->assertTrue(FileHelper::mkdir($dirName), 'FileHelper::mkdir should return true if directory was created!');
$this->assertTrue(file_exists($dirName), 'Unable to create directory recursively!');
$this->assertTrue(FileHelper::mkdir($dirName), 'FileHelper::mkdir should return true for already existing directories!');
}
public function testGetMimeTypeByExtension()
......@@ -292,4 +296,20 @@ class FileHelperTest extends TestCase
$this->assertEquals($mimeType, FileHelper::getMimeTypeByExtension($fileName, $magicFile));
}
}
public function testGetMimeType()
{
$file = $this->testFilePath . DIRECTORY_SEPARATOR . 'mime_type_test.txt';
file_put_contents($file, 'some text');
$this->assertEquals('text/plain', FileHelper::getMimeType($file));
$file = $this->testFilePath . DIRECTORY_SEPARATOR . 'mime_type_test.json';
file_put_contents($file, '{"a": "b"}');
$this->assertEquals('text/plain', FileHelper::getMimeType($file));
}
public function testNormalizePath()
{
$this->assertEquals(DIRECTORY_SEPARATOR.'home'.DIRECTORY_SEPARATOR.'demo', FileHelper::normalizePath('/home\demo/'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment