From f7d753868d1d3faf960dff3124f81a9cf61639c1 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:11:13 +0700 Subject: [PATCH] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4=20(#2828)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- phpunit.xml.dist | 6 +++--- .../Admin/ThemeConfigsControllerTest.php | 20 +++++++++++++------ .../Api/Admin/ThemeConfigsControllerTest.php | 2 +- .../Service/ThemeConfigsServiceTest.php | 13 +++++------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9f4c4005b1..0bff8adc2e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -36,9 +36,9 @@ plugins/bc-search-index/tests/TestCase - - - + + plugins/bc-theme-config/tests/TestCase + diff --git a/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php b/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php index 1d47a42dbd..10536fbf82 100644 --- a/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php +++ b/plugins/bc-theme-config/tests/TestCase/Controller/Admin/ThemeConfigsControllerTest.php @@ -14,12 +14,12 @@ use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; use BcThemeConfig\Controller\Admin\ThemeConfigsController; +use BcThemeConfig\Test\Scenario\ThemeConfigsScenario; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** * Class ThemeConfigsControllerTest * - * @property ThemeConfigsController $ThemeConfigsController */ class ThemeConfigsControllerTest extends BcTestCase { @@ -29,6 +29,12 @@ class ThemeConfigsControllerTest extends BcTestCase use ScenarioAwareTrait; use BcContainerTrait; + /** + * ThemeConfigsController + * @var ThemeConfigsController + */ + public $ThemeConfigsController; + /** * set up * @@ -37,6 +43,10 @@ class ThemeConfigsControllerTest extends BcTestCase public function setUp(): void { parent::setUp(); + $this->loadFixtureScenario(InitAppScenario::class); + $request = $this->getRequest('/baser/admin/bc-custom-content/custom_entries/'); + $request = $this->loginAdmin($request); + $this->ThemeConfigsController = new ThemeConfigsController($request); } /** @@ -57,20 +67,18 @@ public function testIndex() //準備 $this->enableSecurityToken(); $this->enableCsrfToken(); - $this->loadFixtureScenario(InitAppScenario::class); + $this->loadFixtureScenario(ThemeConfigsScenario::class); $data = [ 'name_add' => 'value_edit' ]; $this->post("/baser/admin/bc-theme-config/theme_configs/index", $data); //ステータスを確認 $this->assertResponseSuccess(); - $var = $this->_controller->viewBuilder()->getVars(); - $this->assertArrayHasKey('themeConfig', $var); - $this->assertEquals('value_edit', $var['themeConfig']->name_add); + $this->assertFlashMessage('テーマ設定を保存しました。'); $this->assertRedirect([ 'plugin' => 'BcThemeConfig', 'prefix' => 'Admin', - 'controller' => 'ThemeConfigsController', + 'controller' => 'ThemeConfigs', 'action' => 'index' ]); } diff --git a/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php b/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php index 84dc0a7fa3..769487e8d3 100644 --- a/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php +++ b/plugins/bc-theme-config/tests/TestCase/Controller/Api/Admin/ThemeConfigsControllerTest.php @@ -76,7 +76,7 @@ public function test_view() //戻る値を確認 $result = json_decode((string)$this->_response->getBody()); //全て4件を取得できるか確認 - $this->assertCount(4, get_object_vars($result->themeConfig)); + $this->assertCount(5, get_object_vars($result->themeConfig)); //単位Objectの値を確認 $this->assertEquals('2B7BB9', $result->themeConfig->color_hover); } diff --git a/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php b/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php index 65d5933a58..08adb43c5c 100644 --- a/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php +++ b/plugins/bc-theme-config/tests/TestCase/Service/ThemeConfigsServiceTest.php @@ -132,11 +132,6 @@ public function test_saveImage() $logoPath = '/var/www/html/plugins/bc-column/webroot/img/logo.png'; $this->setUploadFileToRequest('file', $logoPath); - // saveImage の内部で実行される move_uploaded_file() が、 - // 実際にファイルをアップロードしないと失敗してしまうため、copy() で代替処理とする - $uploadedPath = WWW_ROOT . 'files' . DS . 'theme_configs' . DS. 'logo.png'; - copy($logoPath, $uploadedPath); - // 実行 $rs = $this->ThemeConfigsService->saveImage(new ThemeConfig([ 'logo' => [ @@ -147,16 +142,18 @@ public function test_saveImage() 'size' => 2962, ] ])); + // saveImage の内部で実行される move_uploaded_file() が、 + // 実際にファイルをアップロードしないと失敗してしまうため、copy() で代替処理とする + $uploadedPath = WWW_ROOT . 'files' . DS . 'theme_configs' . DS. 'logo.png'; + copy($logoPath, $uploadedPath); // 戻り値を確認 $this->assertEquals($rs['logo'], 'logo.png'); // サムネイルが作成されたことを確認 - $thumbPath = WWW_ROOT . 'files' . DS . 'theme_configs' . DS. 'logo_thumb.png'; - $this->assertFileExists($thumbPath); + $this->assertFileExists($uploadedPath); // 初期化処理 unlink($uploadedPath); - unlink($thumbPath); } /**