From 2135fb77760d9083b5bfa33a57997893382386a8 Mon Sep 17 00:00:00 2001 From: Mohamed Amine Date: Fri, 7 Sep 2018 23:56:12 -0400 Subject: [PATCH] Add Multi files upload Tests --- tests/processFileTest.php | 38 +++++++++++++++++++++++- tests/uploadTest.php | 19 +++++++++--- tests/validationTest.php | 62 +++++++++++++++++++++++++++++++++++---- 3 files changed, 109 insertions(+), 10 deletions(-) diff --git a/tests/processFileTest.php b/tests/processFileTest.php index 2e84620..fde8af3 100644 --- a/tests/processFileTest.php +++ b/tests/processFileTest.php @@ -15,13 +15,39 @@ 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() @@ -29,13 +55,23 @@ 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() diff --git a/tests/uploadTest.php b/tests/uploadTest.php index 9541be5..dffbd24 100644 --- a/tests/uploadTest.php +++ b/tests/uploadTest.php @@ -32,25 +32,29 @@ 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() @@ -58,6 +62,9 @@ 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()); } @@ -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())); } } diff --git a/tests/validationTest.php b/tests/validationTest.php index 1a8baac..7285751 100644 --- a/tests/validationTest.php +++ b/tests/validationTest.php @@ -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()); } }