Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユニットテストを調整 #2844

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/bc-theme-config/src/Service/ThemeConfigsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public function saveImage($entity)
// サムネイルを保存
$imageresizer = new Imageresizer();
$thumbPath = $saveDir . $image . $thumbSuffix . '.' . $ext;
$imageresizer->resize($filePath, $thumbPath, 320, 320);
if (file_exists($filePath))
$imageresizer->resize($filePath, $thumbPath, 320, 320);

// エンティティを更新
$entity->{$image} = $fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use BaserCore\Model\Entity\SiteConfig;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcThemeConfig\Model\Entity\ThemeConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ public function test_upload()

//テストファイルを作成
$filePath = TMP . 'test_upload' . DS;
(new BcFolder($filePath))->create();
$folder = new BcFolder($filePath);
$folder->create();
$testFile = $filePath . 'uploadTestFile.html';
$tmpFile = new BcFile($testFile);
$tmpFile->create();
Expand All @@ -359,10 +360,14 @@ public function test_upload()
rmdir($filePath);
unlink($fullpath . 'uploadTestFile.html');

$folder->create();
$tmpFile->create();
//エラーを発生した場合
$this->post('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout3');
ryuring marked this conversation as resolved.
Show resolved Hide resolved
$this->post('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample333333/layout3');
//ステータスを確認
$this->assertResponseCode(500);
//テストファイルとフォルダを削除
$folder->delete();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
Expand Down Expand Up @@ -61,6 +63,7 @@ public function test_add()
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/';
$data = [
'theme' => 'BcThemeSample',
'parent' => $fullpath,
'type' => 'layout',
'path' => '',
'base_name' => 'base_name_1',
Expand Down Expand Up @@ -316,13 +319,17 @@ public function test_upload()
{
//テストテーマフォルダを作成
$fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/';
(new Folder())->create($fullpath . 'new_folder', 0777);
$folder = new BcFolder($fullpath . 'new_folder');
$folder->create();

//テストファイルを作成
$filePath = TMP . 'test_upload' . DS;
(new Folder())->create($filePath, 0777);
$filePath = TMP . 'test_upload' . DS;
$folder = new BcFolder($filePath);
$folder->create();

$testFile = $filePath . 'uploadTestFile.html';
new File($testFile, true);
$file = new BcFile($testFile);
$file->create();

//Postデータを生成
$data = [
Expand All @@ -344,8 +351,6 @@ public function test_upload()
$this->assertTrue(file_exists($fullpath . 'new_folder/uploadTestFile.html'));

//テストファイルとフォルダを削除
rmdir($filePath);
unlink($fullpath . 'new_folder/uploadTestFile.html');
rmdir($fullpath . 'new_folder');
$folder->delete();
}
}