add composer's vendor directory
This commit is contained in:
parent
01a3860d73
commit
60b094d5fa
745 changed files with 56017 additions and 1 deletions
176
vendor/codeguy/upload/tests/FileTest.php
vendored
Normal file
176
vendor/codeguy/upload/tests/FileTest.php
vendored
Normal file
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
class FileTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $assetsDirectory;
|
||||
|
||||
protected $storage;
|
||||
|
||||
/********************************************************************************
|
||||
* Setup
|
||||
*******************************************************************************/
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->assetsDirectory = dirname(__FILE__) . '/assets';
|
||||
$_FILES['foo'] = array(
|
||||
'name' => 'foo.txt',
|
||||
'tmp_name' => $this->assetsDirectory . '/foo.txt',
|
||||
'error' => UPLOAD_ERR_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function getNewFile()
|
||||
{
|
||||
if (is_null($this->storage)) {
|
||||
// Prepare storage
|
||||
$this->storage = $this->getMock(
|
||||
'\Upload\Storage\FileSystem',
|
||||
array('upload'),
|
||||
array($this->assetsDirectory)
|
||||
);
|
||||
$this->storage->expects($this->any())
|
||||
->method('upload')
|
||||
->will($this->returnValue(true));
|
||||
}
|
||||
|
||||
// Prepare file
|
||||
$file = $this->getMock(
|
||||
'\Upload\File',
|
||||
array('isUploadedFile'),
|
||||
array('foo', $this->storage)
|
||||
);
|
||||
$file->expects($this->any())
|
||||
->method('isUploadedFile')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* Tests
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructionWithInvalidKey()
|
||||
{
|
||||
$file = new \Upload\File('bar', new \Upload\Storage\FileSystem($this->assetsDirectory));
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$this->assertEquals('foo', $file->getName());
|
||||
}
|
||||
|
||||
public function testGetNameWithExtension()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$this->assertEquals('foo.txt', $file->getNameWithExtension());
|
||||
}
|
||||
|
||||
public function testGetNameWithExtensionUsingCustomName()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$file->setName('bar');
|
||||
$this->assertEquals('bar.txt', $file->getNameWithExtension());
|
||||
}
|
||||
|
||||
public function testGetMimetype()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$this->assertEquals('text/plain', $file->getMimetype());
|
||||
}
|
||||
|
||||
public function testAddValidationErrors()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$file->addError('Error');
|
||||
$this->assertEquals(1, count($file->getErrors()));
|
||||
}
|
||||
|
||||
public function testIsValidIfNoValidations()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$this->assertEmpty($file->getErrors());
|
||||
}
|
||||
|
||||
public function testWillUploadIfNoValidations()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$this->assertTrue($file->upload());
|
||||
}
|
||||
|
||||
public function testAddValidations()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$file->addValidations(new \Upload\Validation\Mimetype(array(
|
||||
'text/plain'
|
||||
)));
|
||||
$this->assertEquals(1, count($file->getValidations()));
|
||||
}
|
||||
|
||||
public function testWillUploadWithPassingValidations()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$file->addValidations(new \Upload\Validation\Mimetype(array(
|
||||
'text/plain'
|
||||
)));
|
||||
$this->assertTrue($file->upload());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Upload\Exception\UploadException
|
||||
*/
|
||||
public function testWillNotUploadWithFailingValidations()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$file->addValidations(new \Upload\Validation\Mimetype(array(
|
||||
'image/png'
|
||||
)));
|
||||
$file->upload();
|
||||
}
|
||||
|
||||
public function testPopulatesErrorsWithFailingValidations()
|
||||
{
|
||||
$file = $this->getNewFile();
|
||||
$file->addValidations(new \Upload\Validation\Mimetype(array(
|
||||
'image/png'
|
||||
)));
|
||||
try {
|
||||
$file->upload();
|
||||
} catch(\Upload\Exception\UploadException $e) {
|
||||
$this->assertEquals(1, count($file->getErrors()));
|
||||
}
|
||||
}
|
||||
|
||||
public function testValidationFailsIfUploadErrorCode()
|
||||
{
|
||||
$_FILES['foo']['error'] = 4;
|
||||
$file = $this->getNewFile();
|
||||
$this->assertFalse($file->validate());
|
||||
}
|
||||
|
||||
public function testValidationFailsIfNotUploadedFile()
|
||||
{
|
||||
$file = $this->getMock(
|
||||
'\Upload\File',
|
||||
array('isUploadedFile'),
|
||||
array('foo', new \Upload\Storage\FileSystem($this->assetsDirectory))
|
||||
);
|
||||
$file->expects($this->any())
|
||||
->method('isUploadedFile')
|
||||
->will($this->returnValue(false));
|
||||
$this->assertFalse($file->validate());
|
||||
}
|
||||
|
||||
public function testParsesHumanFriendlyFileSizes()
|
||||
{
|
||||
$this->assertEquals(100, \Upload\File::humanReadableToBytes('100'));
|
||||
$this->assertEquals(102400, \Upload\File::humanReadableToBytes('100K'));
|
||||
$this->assertEquals(104857600, \Upload\File::humanReadableToBytes('100M'));
|
||||
$this->assertEquals(107374182400, \Upload\File::humanReadableToBytes('100G'));
|
||||
$this->assertEquals(100, \Upload\File::humanReadableToBytes('100F')); // <-- Unrecognized. Assume bytes.
|
||||
}
|
||||
}
|
79
vendor/codeguy/upload/tests/Storage/FileSystemTest.php
vendored
Normal file
79
vendor/codeguy/upload/tests/Storage/FileSystemTest.php
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
class FileSystemTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Setup (each test)
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
// Path to test assets
|
||||
$this->assetsDirectory = dirname(__DIR__) . '/assets';
|
||||
|
||||
// Reset $_FILES superglobal
|
||||
$_FILES['foo'] = array(
|
||||
'name' => 'foo.txt',
|
||||
'tmp_name' => $this->assetsDirectory . '/foo.txt',
|
||||
'error' => 0
|
||||
);
|
||||
}
|
||||
|
||||
public function testInstantiationWithValidDirectory()
|
||||
{
|
||||
try {
|
||||
$storage = $this->getMock(
|
||||
'\Upload\Storage\FileSystem',
|
||||
array('upload'),
|
||||
array($this->assetsDirectory)
|
||||
);
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
$this->fail('Unexpected argument thrown during instantiation with valid directory');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInstantiationWithInvalidDirectory()
|
||||
{
|
||||
$storage = $this->getMock(
|
||||
'\Upload\Storage\FileSystem',
|
||||
array('upload'),
|
||||
array('/foo')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test won't overwrite existing file
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testWillNotOverwriteFile()
|
||||
{
|
||||
$storage = new \Upload\Storage\FileSystem($this->assetsDirectory, false);
|
||||
$file = new \Upload\File('foo', $storage);
|
||||
$file->upload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test will overwrite existing file
|
||||
*/
|
||||
public function testWillOverwriteFile()
|
||||
{
|
||||
$storage = $this->getMock(
|
||||
'\Upload\Storage\FileSystem',
|
||||
array('moveUploadedFile'),
|
||||
array($this->assetsDirectory, true)
|
||||
);
|
||||
$storage->expects($this->any())
|
||||
->method('moveUploadedFile')
|
||||
->will($this->returnValue(true));
|
||||
$file = $this->getMock(
|
||||
'\Upload\File',
|
||||
array('isUploadedFile'),
|
||||
array('foo', $storage)
|
||||
);
|
||||
$file->expects($this->any())
|
||||
->method('isUploadedFile')
|
||||
->will($this->returnValue(true));
|
||||
$this->assertTrue($file->upload());
|
||||
}
|
||||
}
|
43
vendor/codeguy/upload/tests/Validation/ExtensionTest.php
vendored
Normal file
43
vendor/codeguy/upload/tests/Validation/ExtensionTest.php
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
class ExtensionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Setup (each test)
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
// Path to test assets
|
||||
$this->assetsDirectory = dirname(__DIR__) . '/assets';
|
||||
|
||||
// Create stubbed storage instance
|
||||
$this->storage = $this->getMock(
|
||||
'\Upload\Storage\FileSystem',
|
||||
array('upload'),
|
||||
array($this->assetsDirectory)
|
||||
);
|
||||
$this->storage->expects($this->any())
|
||||
->method('upload')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
// Reset $_FILES superglobal
|
||||
$_FILES['foo'] = array(
|
||||
'name' => 'foo.txt',
|
||||
'tmp_name' => $this->assetsDirectory . '/foo.txt',
|
||||
'error' => 0
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidExtension()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Extension('txt');
|
||||
$this->assertTrue($validation->validate($file));
|
||||
}
|
||||
|
||||
public function testInvalidExtension()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Extension('csv');
|
||||
$this->assertFalse($validation->validate($file));
|
||||
}
|
||||
}
|
47
vendor/codeguy/upload/tests/Validation/MimetypeTest.php
vendored
Normal file
47
vendor/codeguy/upload/tests/Validation/MimetypeTest.php
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
class MimetypeTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Setup (each test)
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
// Path to test assets
|
||||
$this->assetsDirectory = dirname(__DIR__) . '/assets';
|
||||
|
||||
// Create stubbed storage instance
|
||||
$this->storage = $this->getMock(
|
||||
'\Upload\Storage\FileSystem',
|
||||
array('upload'),
|
||||
array($this->assetsDirectory)
|
||||
);
|
||||
$this->storage->expects($this->any())
|
||||
->method('upload')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
// Reset $_FILES superglobal
|
||||
$_FILES['foo'] = array(
|
||||
'name' => 'foo.txt',
|
||||
'tmp_name' => $this->assetsDirectory . '/foo.txt',
|
||||
'error' => 0
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidMimetype()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Mimetype(array(
|
||||
'text/plain'
|
||||
));
|
||||
$this->assertTrue($validation->validate($file));
|
||||
}
|
||||
|
||||
public function testInvalidMimetype()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Mimetype(array(
|
||||
'image/png'
|
||||
));
|
||||
$this->assertFalse($validation->validate($file));
|
||||
}
|
||||
}
|
57
vendor/codeguy/upload/tests/Validation/SizeTest.php
vendored
Normal file
57
vendor/codeguy/upload/tests/Validation/SizeTest.php
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
class SizeTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Setup (each test)
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
// Path to test assets
|
||||
$this->assetsDirectory = dirname(__DIR__) . '/assets';
|
||||
|
||||
// Create stubbed storage instance
|
||||
$this->storage = $this->getMock(
|
||||
'\Upload\Storage\FileSystem',
|
||||
array('upload'),
|
||||
array($this->assetsDirectory)
|
||||
);
|
||||
$this->storage->expects($this->any())
|
||||
->method('upload')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
// Reset $_FILES superglobal
|
||||
$_FILES['foo'] = array(
|
||||
'name' => 'foo.txt',
|
||||
'tmp_name' => $this->assetsDirectory . '/foo.txt',
|
||||
'error' => 0
|
||||
);
|
||||
}
|
||||
|
||||
public function testValidFileSize()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Size(500);
|
||||
$this->assertTrue($validation->validate($file));
|
||||
}
|
||||
|
||||
public function testValidFileSizeWithHumanReadableArgument()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Size('500B');
|
||||
$this->assertTrue($validation->validate($file));
|
||||
}
|
||||
|
||||
public function testInvalidFileSize()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Size(400);
|
||||
$this->assertFalse($validation->validate($file));
|
||||
}
|
||||
|
||||
public function testInvalidFileSizeWithHumanReadableArgument()
|
||||
{
|
||||
$file = new \Upload\File('foo', $this->storage);
|
||||
$validation = new \Upload\Validation\Size('400B');
|
||||
$this->assertFalse($validation->validate($file));
|
||||
}
|
||||
}
|
6
vendor/codeguy/upload/tests/assets/foo.txt
vendored
Normal file
6
vendor/codeguy/upload/tests/assets/foo.txt
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
||||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
|
||||
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
||||
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
|
||||
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
||||
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
3
vendor/codeguy/upload/tests/bootstrap.php
vendored
Normal file
3
vendor/codeguy/upload/tests/bootstrap.php
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
require dirname(__FILE__) . '/../src/Upload/Autoloader.php';
|
||||
\Upload\Autoloader::register();
|
Reference in a new issue