Laravel version update
Laravel version update
This commit is contained in:
55
vendor/flowjs/flow-php-server/test/Unit/AutoloadTest.php
vendored
Normal file
55
vendor/flowjs/flow-php-server/test/Unit/AutoloadTest.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Unit;
|
||||
|
||||
|
||||
/**
|
||||
* Autoload unit tests
|
||||
*
|
||||
* @coversDefaultClass \Flow\Autoloader
|
||||
*
|
||||
* @package Unit
|
||||
*/
|
||||
class AutoloadTest extends FlowUnitCase
|
||||
{
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getDir
|
||||
*/
|
||||
public function testAutoloader_construct_default()
|
||||
{
|
||||
$expDir = realpath(__DIR__ . '/../../src/Flow') . '/..';
|
||||
$autoloader = new \Flow\Autoloader();
|
||||
|
||||
$this->assertSame($expDir, $autoloader->getDir());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getDir
|
||||
*/
|
||||
public function testAutoloader_construct_custom()
|
||||
{
|
||||
$expDir = __DIR__;
|
||||
$autoloader = new \Flow\Autoloader($expDir);
|
||||
|
||||
$this->assertSame($expDir, $autoloader->getDir());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::autoload
|
||||
*/
|
||||
public function testClassesExist()
|
||||
{
|
||||
$autoloader = new \Flow\Autoloader();
|
||||
|
||||
$autoloader->autoload('noclass');
|
||||
$this->assertFalse(class_exists('noclass', false));
|
||||
|
||||
$autoloader->autoload('Flow\NoClass');
|
||||
$this->assertFalse(class_exists('Flow\NoClass', false));
|
||||
|
||||
$autoloader->autoload('Flow\File');
|
||||
$this->assertTrue(class_exists('Flow\File'));
|
||||
}
|
||||
}
|
117
vendor/flowjs/flow-php-server/test/Unit/ConfigTest.php
vendored
Normal file
117
vendor/flowjs/flow-php-server/test/Unit/ConfigTest.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Unit;
|
||||
|
||||
|
||||
use Flow\Config;
|
||||
use Flow\Request;
|
||||
|
||||
/**
|
||||
* Config unit tests
|
||||
*
|
||||
* @coversDefaultClass \Flow\Config
|
||||
*
|
||||
* @package Unit
|
||||
*/
|
||||
class ConfigTest extends FlowUnitCase
|
||||
{
|
||||
/**
|
||||
* @covers ::getTempDir
|
||||
* @covers ::getDeleteChunksOnSave
|
||||
* @covers ::getHashNameCallback
|
||||
* @covers ::getPreprocessCallback
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testConfig_construct_config()
|
||||
{
|
||||
$exampleConfig = array(
|
||||
'tempDir' => '/some/dir',
|
||||
'deleteChunksOnSave' => TRUE,
|
||||
'hashNameCallback' => '\SomeNs\SomeClass::someMethod',
|
||||
'preprocessCallback' => '\SomeNs\SomeClass::preProcess'
|
||||
);
|
||||
|
||||
$config = new Config($exampleConfig);
|
||||
|
||||
$this->assertSame($exampleConfig['tempDir'], $config->getTempDir());
|
||||
$this->assertSame($exampleConfig['deleteChunksOnSave'], $config->getDeleteChunksOnSave());
|
||||
$this->assertSame($exampleConfig['hashNameCallback'], $config->getHashNameCallback());
|
||||
$this->assertSame($exampleConfig['preprocessCallback'], $config->getPreprocessCallback());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getTempDir
|
||||
* @covers ::getDeleteChunksOnSave
|
||||
* @covers ::getHashNameCallback
|
||||
* @covers ::getPreprocessCallback
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testConfig_construct_default()
|
||||
{
|
||||
$config = new Config();
|
||||
|
||||
$this->assertSame('', $config->getTempDir());
|
||||
$this->assertSame(true, $config->getDeleteChunksOnSave());
|
||||
$this->assertSame('\Flow\Config::hashNameCallback', $config->getHashNameCallback());
|
||||
$this->assertSame(null, $config->getPreprocessCallback());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setTempDir
|
||||
* @covers ::getTempDir
|
||||
*/
|
||||
public function testConfig_setTempDir()
|
||||
{
|
||||
$dir = '/some/dir';
|
||||
$config = new Config();
|
||||
|
||||
$config->setTempDir($dir);
|
||||
$this->assertSame($dir, $config->getTempDir());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setHashNameCallback
|
||||
* @covers ::getHashNameCallback
|
||||
*/
|
||||
public function testConfig_setHashNameCallback()
|
||||
{
|
||||
$callback = '\SomeNs\SomeClass::someMethod';
|
||||
$config = new Config();
|
||||
|
||||
$config->setHashNameCallback($callback);
|
||||
$this->assertSame($callback, $config->getHashNameCallback());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setPreprocessCallback
|
||||
* @covers ::getPreprocessCallback
|
||||
*/
|
||||
public function testConfig_setPreprocessCallback()
|
||||
{
|
||||
$callback = '\SomeNs\SomeClass::someOtherMethod';
|
||||
$config = new Config();
|
||||
|
||||
$config->setPreprocessCallback($callback);
|
||||
$this->assertSame($callback, $config->getPreprocessCallback());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setDeleteChunksOnSave
|
||||
* @covers ::getDeleteChunksOnSave
|
||||
*/
|
||||
public function testConfig_setDeleteChunksOnSave()
|
||||
{
|
||||
$config = new Config();
|
||||
|
||||
$config->setDeleteChunksOnSave(false);
|
||||
$this->assertFalse($config->getDeleteChunksOnSave());
|
||||
}
|
||||
|
||||
public function testConfig_hashNameCallback()
|
||||
{
|
||||
$request = new Request($this->requestArr);
|
||||
|
||||
$expHash = sha1($request->getIdentifier());
|
||||
$this->assertSame($expHash, Config::hashNameCallback($request));
|
||||
}
|
||||
}
|
428
vendor/flowjs/flow-php-server/test/Unit/FileTest.php
vendored
Normal file
428
vendor/flowjs/flow-php-server/test/Unit/FileTest.php
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
<?php
|
||||
|
||||
namespace Unit;
|
||||
|
||||
|
||||
use Flow\File;
|
||||
use Flow\Config;
|
||||
use Flow\FileLockException;
|
||||
use Flow\FileOpenException;
|
||||
use Flow\Request;
|
||||
use \org\bovigo\vfs\vfsStreamWrapper;
|
||||
use \org\bovigo\vfs\vfsStreamDirectory;
|
||||
use \org\bovigo\vfs\vfsStream;
|
||||
|
||||
/**
|
||||
* File unit tests
|
||||
*
|
||||
* @coversDefaultClass \Flow\File
|
||||
*
|
||||
* @package Unit
|
||||
*/
|
||||
class FileTest extends FlowUnitCase
|
||||
{
|
||||
/**
|
||||
* Config
|
||||
*
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Virtual file system
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $vfs;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Setup virtual file system
|
||||
vfsStreamWrapper::register();
|
||||
$this->vfs = new vfsStreamDirectory('chunks');
|
||||
vfsStreamWrapper::setRoot($this->vfs);
|
||||
|
||||
// Setup Config
|
||||
$this->config = new Config();
|
||||
$this->config->setTempDir($this->vfs->url());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getIdentifier
|
||||
*/
|
||||
public function testFile_construct_withRequest()
|
||||
{
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$expIdentifier = sha1($this->requestArr['flowIdentifier']);
|
||||
$this->assertSame($expIdentifier, $file->getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getIdentifier
|
||||
*/
|
||||
public function testFile_construct_noRequest()
|
||||
{
|
||||
$_REQUEST = $this->requestArr;
|
||||
|
||||
$file = new File($this->config);
|
||||
|
||||
$expIdentifier = sha1($this->requestArr['flowIdentifier']);
|
||||
$this->assertSame($expIdentifier, $file->getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getChunkPath
|
||||
*/
|
||||
public function testFile_construct_getChunkPath()
|
||||
{
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$expPath = $this->vfs->url() . DIRECTORY_SEPARATOR . sha1($this->requestArr['flowIdentifier']) . '_1';
|
||||
$this->assertSame($expPath, $file->getChunkPath(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkChunk
|
||||
*/
|
||||
public function testFile_construct_checkChunk()
|
||||
{
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$this->assertFalse($file->checkChunk());
|
||||
|
||||
$chunkName = sha1($request->getIdentifier()) . '_' . $request->getCurrentChunkNumber();
|
||||
$firstChunk = vfsStream::newFile($chunkName);
|
||||
$this->vfs->addChild($firstChunk);
|
||||
|
||||
$this->assertTrue($file->checkChunk());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validateChunk
|
||||
*/
|
||||
public function testFile_validateChunk()
|
||||
{
|
||||
// No $_FILES
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$this->assertFalse($file->validateChunk());
|
||||
|
||||
// No 'file' key $_FILES
|
||||
$fileInfo = new \ArrayObject();
|
||||
$request = new Request($this->requestArr, $fileInfo);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$this->assertFalse($file->validateChunk());
|
||||
|
||||
// Upload OK
|
||||
$fileInfo->exchangeArray(array(
|
||||
'size' => 10,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'tmp_name' => ''
|
||||
));
|
||||
$this->assertTrue($file->validateChunk());
|
||||
|
||||
// Chunk size doesn't match
|
||||
$fileInfo->exchangeArray(array(
|
||||
'size' => 9,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'tmp_name' => ''
|
||||
));
|
||||
$this->assertFalse($file->validateChunk());
|
||||
|
||||
// Upload error
|
||||
$fileInfo->exchangeArray(array(
|
||||
'size' => 10,
|
||||
'error' => UPLOAD_ERR_EXTENSION,
|
||||
'tmp_name' => ''
|
||||
));
|
||||
$this->assertFalse($file->validateChunk());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validateFile
|
||||
*/
|
||||
public function testFile_validateFile()
|
||||
{
|
||||
$this->requestArr['flowTotalSize'] = 10;
|
||||
$this->requestArr['flowTotalChunks'] = 3;
|
||||
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
$chunkPrefix = sha1($request->getIdentifier()) . '_';
|
||||
|
||||
// No chunks uploaded yet
|
||||
$this->assertFalse($file->validateFile());
|
||||
|
||||
// First chunk
|
||||
$firstChunk = vfsStream::newFile($chunkPrefix . '1');
|
||||
$firstChunk->setContent('123');
|
||||
$this->vfs->addChild($firstChunk);
|
||||
|
||||
// Uploaded not yet complete
|
||||
$this->assertFalse($file->validateFile());
|
||||
|
||||
// Second chunk
|
||||
$secondChunk = vfsStream::newFile($chunkPrefix . '2');
|
||||
$secondChunk->setContent('456');
|
||||
$this->vfs->addChild($secondChunk);
|
||||
|
||||
// Uploaded not yet complete
|
||||
$this->assertFalse($file->validateFile());
|
||||
|
||||
// Third chunk
|
||||
$lastChunk = vfsStream::newFile($chunkPrefix . '3');
|
||||
$lastChunk->setContent('7890');
|
||||
$this->vfs->addChild($lastChunk);
|
||||
|
||||
// All chunks uploaded
|
||||
$this->assertTrue($file->validateFile());
|
||||
|
||||
//// Test false values
|
||||
|
||||
// File size doesn't match
|
||||
$lastChunk->setContent('789');
|
||||
$this->assertFalse($file->validateFile());
|
||||
|
||||
// Correct file size and expect true
|
||||
$this->requestArr['flowTotalSize'] = 9;
|
||||
$this->assertTrue($file->validateFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::deleteChunks
|
||||
*/
|
||||
public function testFile_deleteChunks()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
$this->requestArr['flowTotalChunks'] = 4;
|
||||
|
||||
$fileInfo = new \ArrayObject();
|
||||
$request = new Request($this->requestArr, $fileInfo);
|
||||
$file = new File($this->config, $request);
|
||||
$chunkPrefix = sha1($request->getIdentifier()) . '_';
|
||||
|
||||
$firstChunk = vfsStream::newFile($chunkPrefix . 1);
|
||||
$this->vfs->addChild($firstChunk);
|
||||
|
||||
$secondChunk = vfsStream::newFile($chunkPrefix . 3);
|
||||
$this->vfs->addChild($secondChunk);
|
||||
|
||||
$thirdChunk = vfsStream::newFile('other');
|
||||
$this->vfs->addChild($thirdChunk);
|
||||
|
||||
//// Actual test
|
||||
|
||||
$this->assertTrue(file_exists($firstChunk->url()));
|
||||
$this->assertTrue(file_exists($secondChunk->url()));
|
||||
$this->assertTrue(file_exists($thirdChunk->url()));
|
||||
|
||||
$file->deleteChunks();
|
||||
$this->assertFalse(file_exists($firstChunk->url()));
|
||||
$this->assertFalse(file_exists($secondChunk->url()));
|
||||
$this->assertTrue(file_exists($thirdChunk->url()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::saveChunk
|
||||
*/
|
||||
public function testFile_saveChunk()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
// Setup temporary file
|
||||
$tmpDir = new vfsStreamDirectory('tmp');
|
||||
$tmpFile = vfsStream::newFile('tmpFile');
|
||||
$tmpFile->setContent('1234567890');
|
||||
$tmpDir->addChild($tmpFile);
|
||||
$this->vfs->addChild($tmpDir);
|
||||
$this->filesArr['file']['tmp_name'] = $tmpFile->url();
|
||||
|
||||
// Mock File to use rename instead of move_uploaded_file
|
||||
$request = new Request($this->requestArr, $this->filesArr['file']);
|
||||
$file = $this->getMock('Flow\File', array('_move_uploaded_file'), array($this->config, $request));
|
||||
$file->expects($this->once())
|
||||
->method('_move_uploaded_file')
|
||||
->will($this->returnCallback(function ($filename, $destination) {
|
||||
return rename($filename, $destination);
|
||||
}));
|
||||
|
||||
// Expected destination file
|
||||
$expDstFile = $this->vfs->url() . DIRECTORY_SEPARATOR . sha1($request->getIdentifier()) . '_1';
|
||||
|
||||
//// Accrual test
|
||||
|
||||
$this->assertFalse(file_exists($expDstFile));
|
||||
$this->assertTrue(file_exists($tmpFile->url()));
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$this->assertTrue($file->saveChunk());
|
||||
|
||||
$this->assertTrue(file_exists($expDstFile));
|
||||
//$this->assertFalse(file_exists($tmpFile->url()));
|
||||
|
||||
$this->assertSame('1234567890', file_get_contents($expDstFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testFile_save()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
$this->requestArr['flowTotalChunks'] = 3;
|
||||
$this->requestArr['flowTotalSize'] = 10;
|
||||
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$chunkPrefix = sha1($request->getIdentifier()) . '_';
|
||||
|
||||
$chunk = vfsStream::newFile($chunkPrefix . '1', 0777);
|
||||
$chunk->setContent('0123');
|
||||
$this->vfs->addChild($chunk);
|
||||
|
||||
$chunk = vfsStream::newFile($chunkPrefix . '2', 0777);
|
||||
$chunk->setContent('456');
|
||||
$this->vfs->addChild($chunk);
|
||||
|
||||
$chunk = vfsStream::newFile($chunkPrefix . '3', 0777);
|
||||
$chunk->setContent('789');
|
||||
$this->vfs->addChild($chunk);
|
||||
|
||||
$filePath = $this->vfs->url() . DIRECTORY_SEPARATOR . 'file';
|
||||
|
||||
//// Actual test
|
||||
|
||||
$this->assertTrue($file->save($filePath));
|
||||
$this->assertTrue(file_exists($filePath));
|
||||
$this->assertEquals($request->getTotalSize(), filesize($filePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testFile_save_lock()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$dstFile = $this->vfs->url() . DIRECTORY_SEPARATOR . 'file';
|
||||
|
||||
// Lock file
|
||||
$fh = fopen($dstFile, 'wb');
|
||||
$this->assertTrue(flock($fh, LOCK_EX));
|
||||
|
||||
//// Actual test
|
||||
|
||||
try {
|
||||
// practically on a normal file system exception would not be thrown, this happens
|
||||
// because vfsStreamWrapper does not support locking with block
|
||||
$file->save($dstFile);
|
||||
$this->fail();
|
||||
} catch (FileLockException $e) {
|
||||
$this->assertEquals('failed to lock file: ' . $dstFile, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testFile_save_FileOpenException()
|
||||
{
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
try {
|
||||
@$file->save('not/existing/path');
|
||||
$this->fail();
|
||||
} catch (FileOpenException $e) {
|
||||
$this->assertEquals('failed to open destination file: not/existing/path', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testFile_save_chunk_FileOpenException()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
$this->requestArr['flowTotalChunks'] = 3;
|
||||
$this->requestArr['flowTotalSize'] = 10;
|
||||
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$chunkPrefix = sha1($request->getIdentifier()) . '_';
|
||||
|
||||
$chunk = vfsStream::newFile($chunkPrefix . '1', 0777);
|
||||
$chunk->setContent('0123');
|
||||
$this->vfs->addChild($chunk);
|
||||
|
||||
$chunk = vfsStream::newFile($chunkPrefix . '2', 0777);
|
||||
$chunk->setContent('456');
|
||||
$this->vfs->addChild($chunk);
|
||||
|
||||
$missingChunk = $this->vfs->url() . DIRECTORY_SEPARATOR . $chunkPrefix . '3';
|
||||
$filePath = $this->vfs->url() . DIRECTORY_SEPARATOR . 'file';
|
||||
|
||||
//// Actual test
|
||||
|
||||
try {
|
||||
@$file->save($filePath);
|
||||
} catch (FileOpenException $e) {
|
||||
$this->assertEquals('failed to open chunk: ' . $missingChunk, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
*/
|
||||
public function testFile_save_preProcess()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
$this->requestArr['flowTotalChunks'] = 1;
|
||||
$this->requestArr['flowTotalSize'] = 10;
|
||||
$processCalled = false;
|
||||
|
||||
$process = function($chunk) use (&$processCalled)
|
||||
{
|
||||
$processCalled = true;
|
||||
};
|
||||
|
||||
$this->config->setPreprocessCallback($process);
|
||||
|
||||
$request = new Request($this->requestArr);
|
||||
$file = new File($this->config, $request);
|
||||
|
||||
$chunkPrefix = sha1($request->getIdentifier()) . '_';
|
||||
|
||||
$chunk = vfsStream::newFile($chunkPrefix . '1', 0777);
|
||||
$chunk->setContent('1234567890');
|
||||
$this->vfs->addChild($chunk);
|
||||
|
||||
$filePath = $this->vfs->url() . DIRECTORY_SEPARATOR . 'file';
|
||||
|
||||
//// Actual test
|
||||
|
||||
$this->assertTrue($file->save($filePath));
|
||||
$this->assertTrue(file_exists($filePath));
|
||||
$this->assertEquals($request->getTotalSize(), filesize($filePath));
|
||||
$this->assertTrue($processCalled);
|
||||
}
|
||||
}
|
53
vendor/flowjs/flow-php-server/test/Unit/FlowUnitCase.php
vendored
Normal file
53
vendor/flowjs/flow-php-server/test/Unit/FlowUnitCase.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Unit;
|
||||
|
||||
|
||||
use ArrayObject;
|
||||
|
||||
class FlowUnitCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test request
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $requestArr;
|
||||
|
||||
/**
|
||||
* $_FILES
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $filesArr;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->requestArr = new ArrayObject(array(
|
||||
'flowChunkNumber' => 1,
|
||||
'flowChunkSize' => 1048576,
|
||||
'flowCurrentChunkSize' => 10,
|
||||
'flowTotalSize' => 100,
|
||||
'flowIdentifier' => '13632-prettifyjs',
|
||||
'flowFilename' => 'prettify.js',
|
||||
'flowRelativePath' => 'home/prettify.js',
|
||||
'flowTotalChunks' => 42
|
||||
));
|
||||
|
||||
$this->filesArr = array(
|
||||
'file' => array(
|
||||
'name' => 'someFile.gif',
|
||||
'type' => 'image/gif',
|
||||
'size' => '10',
|
||||
'tmp_name' => '/tmp/abc1234',
|
||||
'error' => UPLOAD_ERR_OK
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$_REQUEST = array();
|
||||
$_FILES = array();
|
||||
}
|
||||
}
|
121
vendor/flowjs/flow-php-server/test/Unit/FustyRequestTest.php
vendored
Normal file
121
vendor/flowjs/flow-php-server/test/Unit/FustyRequestTest.php
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Unit;
|
||||
|
||||
|
||||
use Flow\File;
|
||||
use Flow\FustyRequest;
|
||||
use Flow\Config;
|
||||
use org\bovigo\vfs\vfsStreamWrapper;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
/**
|
||||
* FustyRequest unit tests
|
||||
*
|
||||
* @coversDefaultClass \Flow\FustyRequest
|
||||
*
|
||||
* @package Unit
|
||||
*/
|
||||
class FustyRequestTest extends FlowUnitCase
|
||||
{
|
||||
/**
|
||||
* Virtual file system
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $vfs;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
vfsStreamWrapper::register();
|
||||
$this->vfs = new vfsStreamDirectory('chunks');
|
||||
vfsStreamWrapper::setRoot($this->vfs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::isFustyFlowRequest
|
||||
*/
|
||||
public function testFustyRequest_construct()
|
||||
{
|
||||
$firstChunk = vfsStream::newFile('temp_file');
|
||||
$firstChunk->setContent('1234567890');
|
||||
$this->vfs->addChild($firstChunk);
|
||||
|
||||
$fileInfo = new \ArrayObject(array(
|
||||
'size' => 10,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'tmp_name' => $firstChunk->url()
|
||||
));
|
||||
|
||||
$request = new \ArrayObject(array(
|
||||
'flowIdentifier' => '13632-prettifyjs',
|
||||
'flowFilename' => 'prettify.js',
|
||||
'flowRelativePath' => 'home/prettify.js'
|
||||
));
|
||||
|
||||
$fustyRequest = new FustyRequest($request, $fileInfo);
|
||||
|
||||
$this->assertSame('prettify.js', $fustyRequest->getFileName());
|
||||
$this->assertSame('13632-prettifyjs', $fustyRequest->getIdentifier());
|
||||
$this->assertSame('home/prettify.js', $fustyRequest->getRelativePath());
|
||||
$this->assertSame(1, $fustyRequest->getCurrentChunkNumber());
|
||||
$this->assertTrue($fustyRequest->isFustyFlowRequest());
|
||||
$this->assertSame(10, $fustyRequest->getTotalSize());
|
||||
$this->assertSame(10, $fustyRequest->getDefaultChunkSize());
|
||||
$this->assertSame(10, $fustyRequest->getCurrentChunkSize());
|
||||
$this->assertSame(1, $fustyRequest->getTotalChunks());
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testFustyRequest_ValidateUpload()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
$firstChunk = vfsStream::newFile('temp_file');
|
||||
$firstChunk->setContent('1234567890');
|
||||
$this->vfs->addChild($firstChunk);
|
||||
|
||||
$fileInfo = new \ArrayObject(array(
|
||||
'size' => 10,
|
||||
'error' => UPLOAD_ERR_OK,
|
||||
'tmp_name' => $firstChunk->url()
|
||||
));
|
||||
|
||||
$request = new \ArrayObject(array(
|
||||
'flowIdentifier' => '13632-prettifyjs',
|
||||
'flowFilename' => 'prettify.js',
|
||||
'flowRelativePath' => 'home/prettify.js'
|
||||
));
|
||||
|
||||
$fustyRequest = new FustyRequest($request, $fileInfo);
|
||||
|
||||
$config = new Config();
|
||||
$config->setTempDir($this->vfs->url());
|
||||
|
||||
/** @var File $file */
|
||||
$file = $this->getMock('Flow\File', array('_move_uploaded_file'), array($config, $fustyRequest));
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$file->expects($this->once())
|
||||
->method('_move_uploaded_file')
|
||||
->will($this->returnCallback(function ($filename, $destination) {
|
||||
return rename($filename, $destination);
|
||||
}));
|
||||
|
||||
//// Actual test
|
||||
|
||||
$this->assertTrue($file->validateChunk());
|
||||
$this->assertFalse($file->validateFile());
|
||||
|
||||
$this->assertTrue($file->saveChunk());
|
||||
$this->assertTrue($file->validateFile());
|
||||
$path = $this->vfs->url() . DIRECTORY_SEPARATOR . 'new';
|
||||
$this->assertTrue($file->save($path));
|
||||
$this->assertEquals(10, filesize($path));
|
||||
}
|
||||
}
|
86
vendor/flowjs/flow-php-server/test/Unit/RequestTest.php
vendored
Normal file
86
vendor/flowjs/flow-php-server/test/Unit/RequestTest.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace Unit;
|
||||
|
||||
|
||||
use Flow\Request;
|
||||
|
||||
/**
|
||||
* Request unit tests
|
||||
*
|
||||
* @coversDefaultClass \Flow\Request
|
||||
*
|
||||
* @package Unit
|
||||
*/
|
||||
class RequestTest extends FlowUnitCase
|
||||
{
|
||||
/**
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testRequest_construct_withREQUEST()
|
||||
{
|
||||
$_REQUEST = $this->requestArr;
|
||||
|
||||
$request = new Request();
|
||||
$this->assertSame('prettify.js', $request->getFileName());
|
||||
$this->assertSame(100, $request->getTotalSize());
|
||||
$this->assertSame('13632-prettifyjs', $request->getIdentifier());
|
||||
$this->assertSame('home/prettify.js', $request->getRelativePath());
|
||||
$this->assertSame(42, $request->getTotalChunks());
|
||||
$this->assertSame(1048576, $request->getDefaultChunkSize());
|
||||
$this->assertSame(1, $request->getCurrentChunkNumber());
|
||||
$this->assertSame(10, $request->getCurrentChunkSize());
|
||||
$this->assertSame(null, $request->getFile());
|
||||
$this->assertFalse($request->isFustyFlowRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getParam
|
||||
* @covers ::getFileName
|
||||
* @covers ::getTotalSize
|
||||
* @covers ::getIdentifier
|
||||
* @covers ::getRelativePath
|
||||
* @covers ::getTotalChunks
|
||||
* @covers ::getDefaultChunkSize
|
||||
* @covers ::getCurrentChunkNumber
|
||||
* @covers ::getCurrentChunkSize
|
||||
* @covers ::getFile
|
||||
* @covers ::isFustyFlowRequest
|
||||
*/
|
||||
public function testRequest_construct_withCustomRequest()
|
||||
{
|
||||
$request = new Request($this->requestArr);
|
||||
|
||||
$this->assertSame('prettify.js', $request->getFileName());
|
||||
$this->assertSame(100, $request->getTotalSize());
|
||||
$this->assertSame('13632-prettifyjs', $request->getIdentifier());
|
||||
$this->assertSame('home/prettify.js', $request->getRelativePath());
|
||||
$this->assertSame(42, $request->getTotalChunks());
|
||||
$this->assertSame(1048576, $request->getDefaultChunkSize());
|
||||
$this->assertSame(1, $request->getCurrentChunkNumber());
|
||||
$this->assertSame(10, $request->getCurrentChunkSize());
|
||||
$this->assertSame(null, $request->getFile());
|
||||
$this->assertFalse($request->isFustyFlowRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testRequest_construct_withFILES()
|
||||
{
|
||||
$_FILES = $this->filesArr;
|
||||
|
||||
$request = new Request();
|
||||
$this->assertSame($this->filesArr['file'], $request->getFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testRequest_construct_withCustFiles()
|
||||
{
|
||||
$request = new Request(null, $this->filesArr['file']);
|
||||
$this->assertSame($this->filesArr['file'], $request->getFile());
|
||||
}
|
||||
}
|
77
vendor/flowjs/flow-php-server/test/Unit/UploaderTest.php
vendored
Normal file
77
vendor/flowjs/flow-php-server/test/Unit/UploaderTest.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Unit;
|
||||
|
||||
|
||||
use Flow\FileOpenException;
|
||||
use org\bovigo\vfs\vfsStreamWrapper;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use Flow\Uploader;
|
||||
|
||||
/**
|
||||
* Uploader unit tests
|
||||
*
|
||||
* @coversDefaultClass \Flow\Uploader
|
||||
*
|
||||
* @package Unit
|
||||
*/
|
||||
class UploaderTest extends FlowUnitCase
|
||||
{
|
||||
/**
|
||||
* Virtual file system
|
||||
*
|
||||
* @var vfsStreamDirectory
|
||||
*/
|
||||
protected $vfs;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
vfsStreamWrapper::register();
|
||||
$this->vfs = new vfsStreamDirectory('chunks');
|
||||
vfsStreamWrapper::setRoot($this->vfs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::pruneChunks
|
||||
*/
|
||||
public function testUploader_pruneChunks()
|
||||
{
|
||||
//// Setup test
|
||||
|
||||
$newDir = vfsStream::newDirectory('1');
|
||||
$newDir->lastModified(time()-31);
|
||||
$newDir->lastModified(time());
|
||||
|
||||
$fileFirst = vfsStream::newFile('file31');
|
||||
$fileFirst->lastModified(time()-31);
|
||||
$fileSecond = vfsStream::newFile('random_file');
|
||||
$fileSecond->lastModified(time()-30);
|
||||
$upDir = vfsStream::newFile('..');
|
||||
|
||||
$this->vfs->addChild($newDir);
|
||||
$this->vfs->addChild($fileFirst);
|
||||
$this->vfs->addChild($fileSecond);
|
||||
$this->vfs->addChild($upDir);
|
||||
|
||||
//// Actual test
|
||||
|
||||
Uploader::pruneChunks($this->vfs->url(), 30);
|
||||
$this->assertTrue(file_exists($newDir->url()));
|
||||
$this->assertFalse(file_exists($fileFirst->url()));
|
||||
$this->assertTrue(file_exists($fileSecond->url()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::pruneChunks
|
||||
*/
|
||||
public function testUploader_exception()
|
||||
{
|
||||
try {
|
||||
@Uploader::pruneChunks('not/existing/dir', 30);
|
||||
$this->fail();
|
||||
} catch (FileOpenException $e) {
|
||||
$this->assertSame('failed to open folder: not/existing/dir', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user