Skip to content
Permalink
Browse files

move tests from protected method to name()

  • Loading branch information...
saeideng committed Mar 28, 2018
1 parent 7b576d3 commit 5347287542b577644036c126b991a82bc8f1eade
Showing with 45 additions and 26 deletions.
  1. +45 −26 tests/TestCase/Filesystem/FileTest.php
@@ -17,6 +17,7 @@
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use Cake\TestSuite\TestCase;
use SplFileInfo;
/**
* FileTest class
@@ -142,15 +143,33 @@ public function testUtf8Filenames()
* @dataProvider baseNameValueProvider
* @return void
*/
public function testBasename($path, $suffix)
public function testBasename($path, $suffix, $isRoot)
{
$class = new \ReflectionClass('Cake\Filesystem\File');
$method = $class->getMethod('_basename');
$method->setAccessible(true);
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) {
$this->assertEquals(basename($path), $method->invokeArgs(null, [$path]));
$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 {
$this->assertEquals(basename($path, $suffix), $method->invokeArgs(null, [$path, $suffix]));
$File->info['extension'] = $suffix;
$this->assertEquals(basename($path, '.' . $suffix), $File->name());
}
}
@@ -162,28 +181,28 @@ public function testBasename($path, $suffix)
public function baseNameValueProvider()
{
return [
['folder/نام.txt', null],
['folder/نام فارسی.txt', null],
['نام.txt', null],
['نام فارسی.txt', null],
['/نام.txt', null],
['/نام فارسی.txt', null],
['folder/نام.txt', null, false],
['folder/نام فارسی.txt', null, false],
['نام.txt', null, true],
['نام فارسی.txt', null, true],
['/نام.txt', null, true],
['/نام فارسی.txt', null, true],
//
['folder/نام.txt', '.txt'],
['folder/نام فارسی.txt', '.txt'],
['نام.txt', '.txt'],
['نام فارسی.txt', '.txt'],
['/نام.txt', '.txt'],
['/نام فارسی.txt', '.txt'],
['folder/نام.txt', 'txt', false],
['folder/نام فارسی.txt', 'txt', false],
['نام.txt', 'txt', true],
['نام فارسی.txt', 'txt', true],
['/نام.txt', 'txt', true],
['/نام فارسی.txt', 'txt', true],
//
['abcde.ab', '.abe'],
['/etc/sudoers.d', null],
['/etc/.d', '.d'],
['/etc/sudoers.d', '.d'],
['/etc/passwd', null],
['/etc/', null],
['.', null],
['/', null],
['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],
];
}

0 comments on commit 5347287

Please sign in to comment.
You can’t perform that action at this time.