laravel-6 support
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ApiTest extends Illuminate\Foundation\Testing\TestCase
|
||||
{
|
||||
/**
|
||||
* The base URL to use while testing the application.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $baseUrl = 'http://localhost';
|
||||
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require './bootstrap/app.php';
|
||||
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
public function testFolder()
|
||||
{
|
||||
auth()->loginUsingId(1);
|
||||
|
||||
$create = $this->getResponseByRouteName('getAddfolder', [
|
||||
'name' => 'testcase',
|
||||
]);
|
||||
|
||||
$create_duplicate = $this->getResponseByRouteName('getAddfolder', [
|
||||
'name' => 'testcase',
|
||||
]);
|
||||
|
||||
$create_empty = $this->getResponseByRouteName('getAddfolder', [
|
||||
'name' => '',
|
||||
]);
|
||||
|
||||
Config::set('lfm.alphanumeric_directory', true);
|
||||
$create_alphanumeric = $this->getResponseByRouteName('getAddfolder', [
|
||||
'name' => '測試資料夾',
|
||||
]);
|
||||
|
||||
$rename = $this->getResponseByRouteName('getRename', [
|
||||
'file' => 'testcase',
|
||||
'new_name' => 'testcase2',
|
||||
]);
|
||||
|
||||
$delete = $this->getResponseByRouteName('getDelete', [
|
||||
'items' => 'testcase2',
|
||||
]);
|
||||
|
||||
$this->assertEquals('OK', $create);
|
||||
$this->assertEquals(trans('laravel-filemanager::lfm.error-folder-exist'), $create_duplicate);
|
||||
$this->assertEquals(trans('laravel-filemanager::lfm.error-folder-name'), $create_empty);
|
||||
$this->assertEquals(trans('laravel-filemanager::lfm.error-folder-alnum'), $create_alphanumeric);
|
||||
$this->assertEquals('OK', $rename);
|
||||
$this->assertEquals('OK', $delete);
|
||||
}
|
||||
|
||||
private function getResponseByRouteName($route_name, $input = [])
|
||||
{
|
||||
$response = $this->call('GET', route('unisharp.lfm.' . $route_name), $input);
|
||||
$data = json_encode($response);
|
||||
|
||||
return $response->getContent();
|
||||
}
|
||||
}
|
212
vendor/unisharp/laravel-filemanager/tests/LfmItemTest.php
vendored
Normal file
212
vendor/unisharp/laravel-filemanager/tests/LfmItemTest.php
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Mockery as m;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use UniSharp\LaravelFilemanager\Lfm;
|
||||
use UniSharp\LaravelFilemanager\LfmItem;
|
||||
use UniSharp\LaravelFilemanager\LfmPath;
|
||||
|
||||
class LfmItemTest extends TestCase
|
||||
{
|
||||
private $lfm_path;
|
||||
private $lfm;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->lfm = m::mock(Lfm::class);
|
||||
|
||||
$this->lfm_path = m::mock(LfmPath::class);
|
||||
$this->lfm_path->shouldReceive('thumb')->andReturn($this->lfm_path);
|
||||
$this->lfm->shouldReceive('config')
|
||||
->with('item_columns')
|
||||
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testMagicGet()
|
||||
{
|
||||
$this->lfm_item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->lfm_item->attributes['foo'] = 'bar';
|
||||
|
||||
$this->assertEquals('bar', $this->lfm_item->foo);
|
||||
}
|
||||
|
||||
public function testName()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('getName')->andReturn('bar');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('bar', $item->name());
|
||||
}
|
||||
|
||||
public function testAbsolutePath()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('foo/bar.baz', $item->path());
|
||||
}
|
||||
|
||||
public function testIsDirectory()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertFalse($item->isDirectory());
|
||||
}
|
||||
|
||||
public function testIsFile()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertTrue($item->isFile());
|
||||
}
|
||||
|
||||
public function testIsImage()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain')->shouldReceive('isDirectory')
|
||||
->andReturn(false);
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertFalse($item->isImage());
|
||||
}
|
||||
|
||||
public function testMimeType()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('application/plain', $item->mimeType());
|
||||
}
|
||||
|
||||
public function testType()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
|
||||
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
|
||||
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
|
||||
$this->lfm_path->shouldReceive('extension')->andReturn('baz');
|
||||
|
||||
$this->lfm->shouldReceive('getFileType')->with('baz')->andReturn('File');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('File', $item->type());
|
||||
}
|
||||
|
||||
public function testExtension()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
|
||||
$this->lfm_path->shouldReceive('extension')->andReturn('baz');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('baz', $item->extension());
|
||||
}
|
||||
|
||||
public function testThumbUrl()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
|
||||
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertNull($item->thumbUrl());
|
||||
}
|
||||
|
||||
// TODO: refactor
|
||||
public function testUrl()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
|
||||
$this->lfm_path->shouldReceive('getName')->andReturn('bar');
|
||||
$this->lfm_path->shouldReceive('setName')->andReturn($this->lfm_path);
|
||||
$this->lfm_path->shouldReceive('url')->andReturn('foo/bar');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('foo/bar', $item->url());
|
||||
}
|
||||
|
||||
public function testSize()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('size')->andReturn(1024);
|
||||
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('1.00 kB', $item->size());
|
||||
}
|
||||
|
||||
public function testTime()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('lastModified')->andReturn(0)->shouldReceive('isDirectory')
|
||||
->andReturn(false);
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals(0, $item->time());
|
||||
}
|
||||
|
||||
public function testIcon()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('isDirectory')->andReturn(false);
|
||||
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain');
|
||||
$this->lfm_path->shouldReceive('path')->with('absolute')->andReturn('foo/bar.baz');
|
||||
$this->lfm_path->shouldReceive('extension')->andReturn('baz');
|
||||
|
||||
$this->lfm->shouldReceive('getFileIcon')->with('baz')->andReturn('fa-file');
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('baz', $item->icon());
|
||||
|
||||
// $path1 = m::mock(LfmPath::class);
|
||||
// $path1->shouldReceive('path')->with('absolute')->andReturn('foo/bar');
|
||||
// $path1->shouldReceive('isDirectory')->andReturn(false);
|
||||
// $path1->shouldReceive('mimeType')->andReturn('image/png');
|
||||
|
||||
// $path3 = m::mock(LfmPath::class);
|
||||
// $path3->shouldReceive('path')->with('absolute')->andReturn('foo/biz');
|
||||
// $path3->shouldReceive('isDirectory')->andReturn(true);
|
||||
|
||||
// $this->assertEquals('fa-image', (new LfmItem($path1))->icon());
|
||||
// $this->assertEquals('fa-folder-o', (new LfmItem($path3))->icon());
|
||||
}
|
||||
|
||||
public function testHasThumb()
|
||||
{
|
||||
$this->lfm_path->shouldReceive('mimeType')->andReturn('application/plain')->shouldReceive('isDirectory')
|
||||
->andReturn(false);
|
||||
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertFalse($item->hasThumb());
|
||||
}
|
||||
|
||||
public function testHumanFilesize()
|
||||
{
|
||||
$item = new LfmItem($this->lfm_path, $this->lfm);
|
||||
|
||||
$this->assertEquals('1.00 kB', $item->humanFilesize(1024));
|
||||
$this->assertEquals('1.00 MB', $item->humanFilesize(1024 ** 2));
|
||||
$this->assertEquals('1.00 GB', $item->humanFilesize(1024 ** 3));
|
||||
$this->assertEquals('1.00 TB', $item->humanFilesize(1024 ** 4));
|
||||
$this->assertEquals('1.00 PB', $item->humanFilesize(1024 ** 5));
|
||||
$this->assertEquals('1.00 EB', $item->humanFilesize(1024 ** 6));
|
||||
}
|
||||
}
|
210
vendor/unisharp/laravel-filemanager/tests/LfmPathTest.php
vendored
Normal file
210
vendor/unisharp/laravel-filemanager/tests/LfmPathTest.php
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Mockery as m;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use UniSharp\LaravelFilemanager\Lfm;
|
||||
use UniSharp\LaravelFilemanager\LfmItem;
|
||||
use UniSharp\LaravelFilemanager\LfmPath;
|
||||
|
||||
class LfmPathTest extends TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testMagicGet()
|
||||
{
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertEquals($storage, $path->storage);
|
||||
}
|
||||
|
||||
public function testMagicCall()
|
||||
{
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
$storage->shouldReceive('foo')->andReturn('bar');
|
||||
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertEquals('bar', $path->foo());
|
||||
}
|
||||
|
||||
public function testDirAndNormalizeWorkingDir()
|
||||
{
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('input')->with('working_dir')->once()->andReturn('foo');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertEquals('foo', $path->normalizeWorkingDir());
|
||||
$this->assertEquals('bar', $path->dir('bar')->normalizeWorkingDir());
|
||||
}
|
||||
|
||||
public function testSetNameAndGetName()
|
||||
{
|
||||
$path = new LfmPath(m::mock(Lfm::class));
|
||||
|
||||
$path->setName('bar');
|
||||
|
||||
$this->assertEquals('bar', $path->getName());
|
||||
}
|
||||
|
||||
public function testPath()
|
||||
{
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getRootFolder')->andReturn('/foo');
|
||||
$helper->shouldReceive('basePath')->andReturn(realpath(__DIR__ . '/../'));
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturnNull();
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
$storage->shouldReceive('rootPath')->andReturn(realpath(__DIR__ . '/../') . '/storage/app');
|
||||
|
||||
$helper->shouldReceive('getStorage')->andReturn($storage);
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertEquals('files/foo', $path->path());
|
||||
$this->assertEquals('files/foo/bar', $path->setName('bar')->path('storage'));
|
||||
}
|
||||
|
||||
public function testUrl()
|
||||
{
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getRootFolder')->andReturn('/foo');
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturnNull();
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
$storage->shouldReceive('url')->andReturn('/files/foo/foo');
|
||||
|
||||
$helper->shouldReceive('getStorage')->andReturn($storage);
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertEquals('/files/foo/foo', $path->setName('foo')->url());
|
||||
}
|
||||
|
||||
public function testFolders()
|
||||
{
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
$storage->shouldReceive('directories')->andReturn(['foo/bar']);
|
||||
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturn('/shares');
|
||||
$helper->shouldReceive('input')->with('sort_type')->andReturn('alphabetic');
|
||||
$helper->shouldReceive('getStorage')->andReturn($storage);
|
||||
$helper->shouldReceive('getNameFromPath')->andReturn('bar');
|
||||
$helper->shouldReceive('getThumbFolderName')->andReturn('thumbs');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
$helper->shouldReceive('config')
|
||||
->with('item_columns')
|
||||
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertInstanceOf(LfmItem::class, $path->folders()[0]);
|
||||
}
|
||||
|
||||
public function testFiles()
|
||||
{
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
$storage->shouldReceive('files')->andReturn(['foo/bar']);
|
||||
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturn('/shares');
|
||||
$helper->shouldReceive('input')->with('sort_type')->andReturn('alphabetic');
|
||||
$helper->shouldReceive('getStorage')->andReturn($storage);
|
||||
$helper->shouldReceive('getNameFromPath')->andReturn('bar');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
$helper->shouldReceive('config')
|
||||
->with('item_columns')
|
||||
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertInstanceOf(LfmItem::class, $path->files()[0]);
|
||||
}
|
||||
|
||||
public function testPretty()
|
||||
{
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getNameFromPath')->andReturn('bar');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('config')
|
||||
->with('item_columns')
|
||||
->andReturn(['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']);
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertInstanceOf(LfmItem::class, $path->pretty('foo'));
|
||||
}
|
||||
|
||||
public function testCreateFolder()
|
||||
{
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
$storage->shouldReceive('rootPath')->andReturn(realpath(__DIR__ . '/../') . '/storage/app');
|
||||
$storage->shouldReceive('exists')->andReturn(false);
|
||||
$storage->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertNull($path->createFolder('bar'));
|
||||
}
|
||||
|
||||
public function testCreateFolderButFolderAlreadyExists()
|
||||
{
|
||||
$storage = m::mock(LfmStorage::class);
|
||||
$storage->shouldReceive('exists')->andReturn(true);
|
||||
$storage->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('getStorage')->with('files/bar')->andReturn($storage);
|
||||
$helper->shouldReceive('getCategoryName')->andReturn('files');
|
||||
$helper->shouldReceive('input')->with('working_dir')->andReturn('/bar');
|
||||
$helper->shouldReceive('isRunningOnWindows')->andReturn(false);
|
||||
$helper->shouldReceive('ds')->andReturn('/');
|
||||
|
||||
$path = new LfmPath($helper);
|
||||
|
||||
$this->assertFalse($path->createFolder('foo'));
|
||||
}
|
||||
}
|
58
vendor/unisharp/laravel-filemanager/tests/LfmStorageRepositoryTest.php
vendored
Normal file
58
vendor/unisharp/laravel-filemanager/tests/LfmStorageRepositoryTest.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Mockery as m;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use UniSharp\LaravelFilemanager\Lfm;
|
||||
use UniSharp\LaravelFilemanager\LfmPath;
|
||||
use UniSharp\LaravelFilemanager\LfmStorageRepository;
|
||||
|
||||
class LfmStorageRepositoryTest extends TestCase
|
||||
{
|
||||
private $storage;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$disk = m::mock('disk');
|
||||
$disk->shouldReceive('getDriver')->andReturn($disk);
|
||||
$disk->shouldReceive('getAdapter')->andReturn($disk);
|
||||
$disk->shouldReceive('getPathPrefix')->andReturn('foo/bar');
|
||||
$disk->shouldReceive('functionToCall')->with('foo/bar')->andReturn('baz');
|
||||
$disk->shouldReceive('directories')->with('foo')->andReturn(['foo/bar']);
|
||||
$disk->shouldReceive('move')->with('foo/bar', 'foo/bar/baz')->andReturn(true);
|
||||
|
||||
$helper = m::mock(Lfm::class);
|
||||
$helper->shouldReceive('config')->with('disk')->andReturn('local');
|
||||
|
||||
Storage::shouldReceive('disk')->with('local')->andReturn($disk);
|
||||
|
||||
$this->storage = new LfmStorageRepository('foo/bar', $helper);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testMagicCall()
|
||||
{
|
||||
$this->assertEquals('baz', $this->storage->functionToCall());
|
||||
}
|
||||
|
||||
public function testRootPath()
|
||||
{
|
||||
$this->assertEquals('foo/bar', $this->storage->rootPath());
|
||||
}
|
||||
|
||||
public function testMove()
|
||||
{
|
||||
$new_lfm_path = m::mock(LfmPath::class);
|
||||
$new_lfm_path->shouldReceive('path')->with('storage')->andReturn('foo/bar/baz');
|
||||
|
||||
$this->assertTrue($this->storage->move($new_lfm_path));
|
||||
}
|
||||
}
|
183
vendor/unisharp/laravel-filemanager/tests/LfmTest.php
vendored
Normal file
183
vendor/unisharp/laravel-filemanager/tests/LfmTest.php
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Contracts\Config\Repository as Config;
|
||||
use Illuminate\Http\Request;
|
||||
use Mockery as m;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use UniSharp\LaravelFilemanager\Lfm;
|
||||
use UniSharp\LaravelFilemanager\LfmFileRepository;
|
||||
use UniSharp\LaravelFilemanager\LfmStorageRepository;
|
||||
|
||||
class LfmTest extends TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testGetStorage()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.disk')->once()->andReturn('local');
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
$this->assertInstanceOf(LfmStorageRepository::class, $lfm->getStorage('foo/bar'));
|
||||
}
|
||||
|
||||
public function testInput()
|
||||
{
|
||||
$request = m::mock(Request::class);
|
||||
$request->shouldReceive('input')->with('foo')->andReturn('bar');
|
||||
|
||||
$lfm = new Lfm(m::mock(Config::class), $request);
|
||||
|
||||
$this->assertEquals('bar', $lfm->input('foo'));
|
||||
}
|
||||
|
||||
public function testGetNameFromPath()
|
||||
{
|
||||
$this->assertEquals('bar', (new Lfm)->getNameFromPath('foo/bar'));
|
||||
}
|
||||
|
||||
public function testAllowFolderType()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
|
||||
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false);
|
||||
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
|
||||
$config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false);
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
|
||||
$this->assertTrue($lfm->allowFolderType('user'));
|
||||
$this->assertTrue($lfm->allowFolderType('shared'));
|
||||
$this->assertFalse($lfm->allowFolderType('shared'));
|
||||
}
|
||||
|
||||
public function testGetCategoryName()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')
|
||||
->with('lfm.folder_categories.file.folder_name', m::type('string'))
|
||||
->once()
|
||||
->andReturn('files');
|
||||
$config->shouldReceive('get')
|
||||
->with('lfm.folder_categories.image.folder_name', m::type('string'))
|
||||
->once()
|
||||
->andReturn('photos');
|
||||
$config->shouldReceive('get')
|
||||
->with('lfm.folder_categories')
|
||||
->andReturn(['file' => [], 'image' => []]);
|
||||
|
||||
$request = m::mock(Request::class);
|
||||
$request->shouldReceive('input')->with('type')->once()->andReturn('file');
|
||||
$request->shouldReceive('input')->with('type')->once()->andReturn('image');
|
||||
|
||||
$lfm = new Lfm($config, $request);
|
||||
|
||||
$this->assertEquals('files', $lfm->getCategoryName('file'));
|
||||
$this->assertEquals('photos', $lfm->getCategoryName('image'));
|
||||
}
|
||||
|
||||
public function testCurrentLfmType()
|
||||
{
|
||||
$request = m::mock(Request::class);
|
||||
$request->shouldReceive('input')->with('type')->once()->andReturn('file');
|
||||
$request->shouldReceive('input')->with('type')->once()->andReturn('image');
|
||||
$request->shouldReceive('input')->with('type')->once()->andReturn('foo');
|
||||
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')
|
||||
->with('lfm.folder_categories')
|
||||
->andReturn(['file' => [], 'image' => []]);
|
||||
|
||||
$lfm = new Lfm($config, $request);
|
||||
|
||||
$this->assertEquals('file', $lfm->currentLfmType());
|
||||
$this->assertEquals('image', $lfm->currentLfmType());
|
||||
$this->assertEquals('file', $lfm->currentLfmType());
|
||||
}
|
||||
|
||||
public function testGetUserSlug()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.private_folder_name')->once()->andReturn(function () {
|
||||
return 'foo';
|
||||
});
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
|
||||
$this->assertEquals('foo', $lfm->getUserSlug());
|
||||
}
|
||||
|
||||
public function testGetRootFolder()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.allow_private_folder')->andReturn(true);
|
||||
$config->shouldReceive('get')->with('lfm.private_folder_name')->once()->andReturn(function () {
|
||||
return 'foo';
|
||||
});
|
||||
$config->shouldReceive('get')->with('lfm.shared_folder_name')->once()->andReturn('bar');
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
|
||||
$this->assertEquals('/foo', $lfm->getRootFolder('user'));
|
||||
$this->assertEquals('/bar', $lfm->getRootFolder('shared'));
|
||||
}
|
||||
|
||||
public function testGetThumbFolderName()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.thumb_folder_name')->once()->andReturn('foo');
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
|
||||
$this->assertEquals('foo', $lfm->getThumbFolderName());
|
||||
}
|
||||
|
||||
public function testGetFileType()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.file_type_array.foo', m::type('string'))->once()->andReturn('foo');
|
||||
$config->shouldReceive('get')->with(m::type('string'), m::type('string'))->once()->andReturn('File');
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
|
||||
$this->assertEquals('foo', $lfm->getFileType('foo'));
|
||||
$this->assertEquals('File', $lfm->getFileType('bar'));
|
||||
}
|
||||
|
||||
public function testAllowMultiUser()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
|
||||
$this->assertTrue($lfm->allowMultiUser());
|
||||
}
|
||||
|
||||
public function testAllowShareFolder()
|
||||
{
|
||||
$config = m::mock(Config::class);
|
||||
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false);
|
||||
$config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true);
|
||||
$config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false);
|
||||
|
||||
$lfm = new Lfm($config);
|
||||
|
||||
$this->assertTrue($lfm->allowShareFolder());
|
||||
$this->assertFalse($lfm->allowShareFolder());
|
||||
}
|
||||
|
||||
public function testTranslateFromUtf8()
|
||||
{
|
||||
$input = 'test/測試';
|
||||
|
||||
$this->assertEquals($input, (new Lfm)->translateFromUtf8($input));
|
||||
}
|
||||
}
|
160
vendor/unisharp/laravel-filemanager/tests/LfmUploadValidatorTest.php
vendored
Normal file
160
vendor/unisharp/laravel-filemanager/tests/LfmUploadValidatorTest.php
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use UniSharp\LaravelFilemanager\Exceptions\DuplicateFileNameException;
|
||||
use UniSharp\LaravelFilemanager\Exceptions\EmptyFileException;
|
||||
use UniSharp\LaravelFilemanager\Exceptions\ExcutableFileException;
|
||||
use UniSharp\LaravelFilemanager\Exceptions\FileFailedToUploadException;
|
||||
use UniSharp\LaravelFilemanager\Exceptions\FileSizeExceedConfigurationMaximumException;
|
||||
use UniSharp\LaravelFilemanager\Exceptions\FileSizeExceedIniMaximumException;
|
||||
use UniSharp\LaravelFilemanager\Exceptions\InvalidMimeTypeException;
|
||||
use UniSharp\LaravelFilemanager\LfmPath;
|
||||
use UniSharp\LaravelFilemanager\LfmUploadValidator;
|
||||
|
||||
function trans()
|
||||
{
|
||||
// leave empty
|
||||
}
|
||||
|
||||
class LfmUploadValidatorTest extends TestCase
|
||||
{
|
||||
public function testPassesSizeLowerThanIniMaximum()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_OK);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->assertEquals($validator->sizeLowerThanIniMaximum(), $validator);
|
||||
}
|
||||
|
||||
public function testFailsSizeLowerThanIniMaximum()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_INI_SIZE);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->expectException(FileSizeExceedIniMaximumException::class);
|
||||
|
||||
$validator->sizeLowerThanIniMaximum();
|
||||
}
|
||||
|
||||
public function testPassesUploadWasSuccessful()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_OK);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->assertEquals($validator->uploadWasSuccessful(), $validator);
|
||||
}
|
||||
|
||||
public function testFailsUploadWasSuccessful()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getError')->andReturn(UPLOAD_ERR_PARTIAL);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->expectException(FileFailedToUploadException::class);
|
||||
|
||||
$validator->uploadWasSuccessful();
|
||||
}
|
||||
|
||||
public function testPassesNameIsNotDuplicate()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
|
||||
$lfm_path = m::mock(LfmPath::class);
|
||||
$lfm_path->shouldReceive('setName')->andReturn($lfm_path);
|
||||
$lfm_path->shouldReceive('exists')->andReturn(false);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->assertEquals($validator->nameIsNotDuplicate('new_file_name', $lfm_path), $validator);
|
||||
}
|
||||
|
||||
public function testFailsNameIsNotDuplicate()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
|
||||
$lfm_path = m::mock(LfmPath::class);
|
||||
$lfm_path->shouldReceive('setName')->andReturn($lfm_path);
|
||||
$lfm_path->shouldReceive('exists')->andReturn(true);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->expectException(DuplicateFileNameException::class);
|
||||
|
||||
$validator->nameIsNotDuplicate('new_file_name', $lfm_path);
|
||||
}
|
||||
|
||||
public function testPassesIsNotExcutable()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getMimeType')->andReturn('image/jpeg');
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->assertEquals($validator->isNotExcutable(), $validator);
|
||||
}
|
||||
|
||||
public function testFailsIsNotExcutable()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getMimeType')->andReturn('text/x-php');
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->expectException(ExcutableFileException::class);
|
||||
|
||||
$validator->isNotExcutable();
|
||||
}
|
||||
|
||||
public function testPassesMimeTypeIsValid()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getMimeType')->andReturn('image/jpeg');
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->assertEquals($validator->mimeTypeIsValid(['image/jpeg']), $validator);
|
||||
}
|
||||
|
||||
public function testFailsMimeTypeIsValid()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getMimeType')->andReturn('image/jpeg');
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->expectException(InvalidMimeTypeException::class);
|
||||
|
||||
$validator->mimeTypeIsValid(['image/png']);
|
||||
}
|
||||
|
||||
public function testPassesSizeIsLowerThanConfiguredMaximum()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getSize')->andReturn(500 * 1000);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->assertEquals($validator->sizeIsLowerThanConfiguredMaximum(1000), $validator);
|
||||
}
|
||||
|
||||
public function testFailsSizeIsLowerThanConfiguredMaximum()
|
||||
{
|
||||
$uploaded_file = m::mock(UploadedFile::class);
|
||||
$uploaded_file->shouldReceive('getSize')->andReturn(2000 * 1000);
|
||||
|
||||
$validator = new LfmUploadValidator($uploaded_file);
|
||||
|
||||
$this->expectException(FileSizeExceedConfigurationMaximumException::class);
|
||||
|
||||
$validator->sizeIsLowerThanConfiguredMaximum(1000);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user