-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nemmo
committed
Feb 4, 2016
1 parent
77a8c8f
commit 1927ef6
Showing
16 changed files
with
156 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.idea/ | ||
build/ | ||
vendor/ | ||
tests/uploads/ | ||
tests/data/db.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Alimzhan | ||
* Date: 2/2/2016 | ||
* Time: 9:45 PM | ||
*/ | ||
|
||
namespace tests; | ||
|
||
use nemmo\attachments\Module; | ||
use Yii; | ||
use yii\helpers\FileHelper; | ||
use yii\web\UploadedFile; | ||
|
||
class FileControllerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
FileHelper::removeDirectory(Yii::getAlias('@tests/uploads')); | ||
UploadedFile::reset(); | ||
} | ||
|
||
/** | ||
* Upload action test | ||
*/ | ||
public function testUpload1() | ||
{ | ||
$types = ['png', 'txt', 'jpg']; | ||
$this->generateFiles($types); | ||
$output = Yii::$app->runAction('attachments/file/upload'); | ||
$this->assertArrayHasKey('uploadedFiles', $output); | ||
$this->assertTrue(in_array('file.png', $output['uploadedFiles'])); | ||
$this->checkFilesExist($types); | ||
} | ||
|
||
public function testUpload2() | ||
{ | ||
$types = ['png', 'txt', 'jpg', 'zip']; | ||
$this->generateFiles($types); | ||
$output = Yii::$app->runAction('attachments/file/upload'); | ||
$this->assertArrayHasKey('error', $output); | ||
} | ||
|
||
public function testUpload3() | ||
{ | ||
Yii::$app->setModule('attachments', [ | ||
'class' => Module::className(), | ||
'rules' => [ | ||
'maxFiles' => 1 | ||
] | ||
]); | ||
$types = ['png', 'zip']; | ||
$this->generateFiles($types); | ||
$output = Yii::$app->runAction('attachments/file/upload'); | ||
$this->assertArrayHasKey('error', $output); | ||
} | ||
|
||
public function testUpload4() | ||
{ | ||
Yii::$app->setModule('attachments', [ | ||
'class' => Module::className(), | ||
'rules' => [ | ||
'maxFiles' => 1 | ||
] | ||
]); | ||
$types = ['png']; | ||
$this->generateFiles($types); | ||
$output = Yii::$app->runAction('attachments/file/upload'); | ||
$this->assertArrayHasKey('uploadedFiles', $output); | ||
$this->assertTrue(in_array('file.png', $output['uploadedFiles'])); | ||
$this->checkFilesExist($types); | ||
} | ||
|
||
public function testUpload5() | ||
{ | ||
Yii::$app->setModule('attachments', [ | ||
'class' => Module::className(), | ||
'rules' => [ | ||
'maxFiles' => 3, | ||
'mimeTypes' => ['image/png', 'image/jpeg'] | ||
] | ||
]); | ||
$types = ['png', 'jpg', 'zip']; | ||
$this->generateFiles($types); | ||
$output = Yii::$app->runAction('attachments/file/upload'); | ||
var_dump($output); | ||
$this->assertArrayHasKey('error', $output); | ||
} | ||
|
||
public function generateFiles($types) | ||
{ | ||
$_FILES = []; | ||
foreach ($types as $index => $type) { | ||
$file = "file.$type"; | ||
$path = Yii::getAlias("@tests/files/$file"); | ||
$_FILES["UploadForm[file][$index]"] = [ | ||
'name' => $file, | ||
'type' => mime_content_type($path), | ||
'size' => filesize($path), | ||
'tmp_name' => $path, | ||
'error' => 0 | ||
]; | ||
} | ||
} | ||
|
||
public function checkFilesExist($types) | ||
{ | ||
foreach ($types as $type) { | ||
$filePath = Yii::getAlias('@tests/uploads/temp/' . Yii::$app->session->id . '/file.' . $type); | ||
$this->assertTrue(file_exists($filePath)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
file 1 |
Binary file not shown.
Binary file not shown.