|
|
@@ -17,6 +17,7 @@ namespace Cake\Test\TestCase\Filesystem;
|
|
|
use Cake\Filesystem\File;
|
|
|
use Cake\Filesystem\Folder;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
+use SplFileInfo;
|
|
|
|
|
|
/**
|
|
|
* FileTest class
|
|
|
@@ -124,6 +125,88 @@ class FileTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * testUtf8Filenames
|
|
|
+ *
|
|
|
+ * @link https://github.com/cakephp/cakephp/issues/11749
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testUtf8Filenames()
|
|
|
+ {
|
|
|
+ $File = new File(TMP . 'tests/permissions/نام فارسی.php', true);
|
|
|
+ $this->assertEquals('نام فارسی', $File->name());
|
|
|
+ $this->assertTrue($File->exists());
|
|
|
+ $this->assertTrue($File->readable());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test _basename method
|
|
|
+ * @dataProvider baseNameValueProvider
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testBasename($path, $suffix, $isRoot)
|
|
|
+ {
|
|
|
+ if (!$isRoot) {
|
|
|
+ $path = TMP . 'tests/permissions' . $path;
|
|
|
+ }
|
|
|
+ $File = new File($path, false);
|
|
|
+
|
|
|
+ //some of paths is directory like '/etc/sudoers.d'
|
|
|
+ if (!is_dir($path)) {
|
|
|
+ //test the name after running __construct()
|
|
|
+ $result = $File->name;
|
|
|
+ $expecting = basename($path);
|
|
|
+ $this->assertEquals($expecting, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //test the name()
|
|
|
+ $splInfo = new SplFileInfo($path);
|
|
|
+ $File->name = ltrim($splInfo->getFilename(), '/\\');
|
|
|
+ if ($suffix === null) {
|
|
|
+ $File->info();//to set and unset 'extension' in bellow
|
|
|
+ if (isset($File->info['extension'])) {
|
|
|
+ unset($File->info['extension']);
|
|
|
+ }
|
|
|
+ $this->assertEquals(basename($path), $File->name());
|
|
|
+ } else {
|
|
|
+ $File->info['extension'] = $suffix;
|
|
|
+ $this->assertEquals(basename($path, '.' . $suffix), $File->name());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Data provider for testBasename().
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function baseNameValueProvider()
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ ['folder/نام.txt', null, false],
|
|
|
+ ['folder/نام فارسی.txt', null, false],
|
|
|
+ ['نام.txt', null, true],
|
|
|
+ ['نام فارسی.txt', null, true],
|
|
|
+ ['/نام.txt', null, true],
|
|
|
+ ['/نام فارسی.txt', null, true],
|
|
|
+ //
|
|
|
+ ['folder/نام.txt', 'txt', false],
|
|
|
+ ['folder/نام فارسی.txt', 'txt', false],
|
|
|
+ ['نام.txt', 'txt', true],
|
|
|
+ ['نام فارسی.txt', 'txt', true],
|
|
|
+ ['/نام.txt', 'txt', true],
|
|
|
+ ['/نام فارسی.txt', 'txt', true],
|
|
|
+ //
|
|
|
+ ['abcde.ab', 'abe', false],
|
|
|
+ ['/etc/sudoers.d', null, true],
|
|
|
+ ['/etc/.d', 'd', true],
|
|
|
+ ['/etc/sudoers.d', 'd', true],
|
|
|
+ ['/etc/passwd', null, true],
|
|
|
+ ['/etc/', null, true],
|
|
|
+ ['.', null, true],
|
|
|
+ ['/', null, true],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* testPermission method
|
|
|
*
|
|
|
* @return void
|