Skip to content

Commit

Permalink
Add Multi files upload Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Amine authored and Mohamed Amine committed Sep 8, 2018
1 parent 35c83f9 commit 2135fb7
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 10 deletions.
38 changes: 37 additions & 1 deletion tests/processFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,63 @@ public function setUp()
'size' => [182447],
'error' => [0],
],
'images' => [
'name' => [
'file1.jpg',
'file2.jpg',
],
'type' => [
'image/jpeg',
'image/jpeg',
],
'tmp_name' => [
__DIR__.'/helpers/tmpfile1',
__DIR__.'/helpers/tmpfile2',
],
'error' => [
0,
0,
],
'size' => [
182447,
182447,
],
],
];
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile');
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile1');
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile2');
}

public function tearDown()
{
unlink(__DIR__.'/helpers/tmpfile');
unlink(__DIR__.'/helpers/tmpfile1');
unlink(__DIR__.'/helpers/tmpfile2');
}

public function testCompression()
{
$image = new \Upload\Upload('image');
$image->process()->compress(50);
$this->assertNotEquals(filesize(__DIR__.'/helpers/tmpfile'), filesize(__DIR__.'/helpers/testfile'));

$images = new \Upload\Upload('images');
$images->process()->compress(75);
$this->assertNotEquals(filesize(__DIR__.'/helpers/testfile'), filesize(__DIR__.'/helpers/tmpfile1'));
$this->assertNotEquals(filesize(__DIR__.'/helpers/testfile'), filesize(__DIR__.'/helpers/tmpfile2'));
}

public function testResize()
{
$image = new \Upload\Upload('image');
$image->process()->resize(300, 100);
$this->assertNotEquals(getimagesize(__DIR__.'/helpers/tmpfile'), getimagesize(__DIR__.'/helpers/testfile'));
$this->assertNotEquals(getimagesize(__DIR__.'/helpers/testfile'), getimagesize(__DIR__.'/helpers/tmpfile'));

$images = new \Upload\Upload('images');
$images->process()->resize(100, 100);
$this->assertNotEquals(getimagesize(__DIR__.'/helpers/testfile'), getimagesize(__DIR__.'/helpers/tmpfile1'));
$this->assertNotEquals(getimagesize(__DIR__.'/helpers/testfile'), getimagesize(__DIR__.'/helpers/tmpfile2'));
}

public function testSetNames()
Expand Down
19 changes: 15 additions & 4 deletions tests/uploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,39 @@ public function setUp()
'image/jpeg',
],
'tmp_name' => [
'tmpname',
'tmpname',
__DIR__.'/helpers/tmpfile1',
__DIR__.'/helpers/tmpfile2',
],
'error' => [
0,
0,
],
'size' => [
654645,
54568,
182447,
182447,
],
],
];
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile');
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile1');
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile2');
}

public function tearDown()
{
unlink(__DIR__.'/helpers/tmpfile');
unlink(__DIR__.'/helpers/tmpfile1');
unlink(__DIR__.'/helpers/tmpfile2');
}

public function testExist()
{
$upload = new \Upload\Upload('image');
$this->assertTrue($upload->exist());

$upload = new \Upload\Upload('images');
$this->assertTrue($upload->exist());

$upload = new \Upload\Upload('image2');
$this->assertTrue($upload->exist());
}
Expand Down Expand Up @@ -89,5 +96,9 @@ public function testGetErrors()
$upload = new \Upload\Upload('image');
$upload->validate()->size(1, 2)->extension(['mp3']);
$this->assertTrue(is_array($upload->getErrors()));

$uploads = new \Upload\UPload('images');
$uploads->validate()->size(1, 2)->extension(['mp3']);
$this->assertTrue(is_array($uploads->getErrors()));
}
}
62 changes: 57 additions & 5 deletions tests/validationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,98 @@ public function setUp()
'size' => [182447],
'error' => [0],
],
'images' => [
'name' => [
'file1.jpg',
'file2.jpg',
],
'type' => [
'image/jpeg',
'image/jpeg',
],
'tmp_name' => [
__DIR__.'/helpers/tmpfile1',
__DIR__.'/helpers/tmpfile2',
],
'error' => [
0,
0,
],
'size' => [
182447,
182447,
],
],
];
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile');
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile1');
copy(__DIR__.'/helpers/testfile', __DIR__.'/helpers/tmpfile2');
}

public function tearDown()
{
unlink(__DIR__.'/helpers/tmpfile');
unlink(__DIR__.'/helpers/tmpfile1');
unlink(__DIR__.'/helpers/tmpfile2');
}

public function testSize()
{
$file = new Upload\Upload('image');
$file->validate()->size(0, 0.1);
$file = new \Upload\Upload('image');
$file->validate()->size(0, 1);
$this->assertTrue($file->isValide());
$file->validate()->size(10, 20);
$this->assertFalse($file->isValide());

$files = new \Upload\Upload('images');
$files->validate()->size(0, 1);
$this->assertTrue($files->isValide());
$files->validate()->size(10, 20);
$this->assertFalse($files->isValide());
}

public function testExtension()
{
$file = new Upload\Upload('image');
$file = new \Upload\Upload('image');
$file->validate()->extension(['jpg']);
$this->assertTrue($file->isValide());
$file->validate()->extension(['png', 'mp3']);
$this->assertFalse($file->isValide());

$files = new \Upload\Upload('images');
$files->validate()->extension(['jpg']);
$this->assertTrue($files->isValide());
$files->validate()->extension(['png', 'mp3']);
$this->assertFalse($files->isValide());
}

public function testMinimumNumber()
{
$file = new Upload\Upload('image');
$file = new \Upload\Upload('image');
$file->validate()->number(1);
$this->assertTrue($file->isValide());
$file->validate()->number(2);
$this->assertFalse($file->isValide());

$files = new \Upload\Upload('images');
$files->validate()->number(2);
$this->assertTrue($files->isValide());
$files->validate()->number(3);
$this->assertFalse($files->isValide());
}

public function testBetweenNumber()
{
$file = new Upload\Upload('image');
$file = new \Upload\Upload('image');
$file->validate()->number(1, 3);
$this->assertTrue($file->isValide());
$file->validate()->number(2, 5);
$this->assertFalse($file->isValide());

$files = new \Upload\Upload('images');
$files->validate()->number(1, 3);
$this->assertTrue($files->isValide());
$files->validate()->number(3, 5);
$this->assertFalse($files->isValide());
}
}

0 comments on commit 2135fb7

Please sign in to comment.