Browse Source

more tests for FileHelper

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
b968402ebd
  1. 24
      tests/unit/framework/helpers/FileHelperTest.php

24
tests/unit/framework/helpers/FileHelperTest.php

@ -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/'));
}
}

Loading…
Cancel
Save