Skip to content

Commit

Permalink
Add unitTest_BcFileUploder_moveFileSessionToTmp (#3802)
Browse files Browse the repository at this point in the history
Co-authored-by: thangnn <[email protected]>
  • Loading branch information
thangnnmd and thangnn committed Sep 17, 2024
1 parent 5e21b97 commit 9e18c0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions plugins/baser-core/src/Utility/BcFileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ public function deleteFile($setting, $file, $delImagecopy = true)
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function moveFileSessionToTmp($data, $fieldName)
{
Expand Down
29 changes: 13 additions & 16 deletions plugins/baser-core/tests/TestCase/Utility/BcFileUploaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,18 +555,13 @@ public static function saveFilesCanResizeDataProvider()
*/
public function testMoveFileSessionToTmp()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$tmpId = 1;
$fieldName = 'fieldName';
$tmp_name = 'basercms_tmp';
$basename = 'basename';
$ext = 'png';
$namefield = 'hoge';

//—————————————————————————
// セッションを設定
//—————————————————————————

// パス情報
$tmpPath = $this->savePath . $tmp_name;

Expand All @@ -577,24 +572,26 @@ public function testMoveFileSessionToTmp()
];
$this->BcFileUploader->tmpId = $tmpId;

$this->uploadedData['eyecatch']['name'] = $basename . '.' . $ext;
$this->uploadedData['eyecatch']['tmp_name'] = $tmpPath;
$this->uploadedData['eyecatch']['type'] = 'basercms';
$this->uploadedData['eyecatch']['ext'] = $ext;

// ダミーファイルの作成
$file = new BcFile($tmpPath);
$file->create();
$file->write('dummy');

// UploadedFileオブジェクトの作成
$uploadedFile = new UploadedFile(
$tmpPath,
filesize($tmpPath),
UPLOAD_ERR_OK,
$basename . '.' . $ext,
'image/png'
);

$this->uploadedData['eyecatch'] = $uploadedFile;

// セッションを設定
$entity = $this->BcFileUploader->saveTmpFiles($this->uploadedData, $tmpId);

//—————————————————————————
// 本題
//—————————————————————————

// パス情報
$targetName = $entity->eyecatch_tmp;
$targetPath = $this->savePath . str_replace(['.', '/'], ['_', '_'], $targetName);

Expand All @@ -610,11 +607,11 @@ public function testMoveFileSessionToTmp()
$this->assertFileExists($targetPath, 'セッションに保存されたファイルデータをファイルとして保存できません');
$result = $this->BcFileUploader->getUploadingFiles($bcUploadId)[$fieldName];
$expected = [
'error' => 0,
'error' => UPLOAD_ERR_OK,
'name' => $targetName,
'tmp_name' => $targetPath,
'size' => 5,
'type' => 'basercms',
'type' => 'image/png',
'uploadable' => true,
'ext' => 'png'
];
Expand Down

0 comments on commit 9e18c0f

Please sign in to comment.