From ef57c52707064cf3495251d929544f7dac9cbb78 Mon Sep 17 00:00:00 2001 From: thangnn Date: Fri, 25 Oct 2024 13:59:11 +0700 Subject: [PATCH 1/2] Add unitTest_BcThemeConfigControllerEventListener_baserCoreThemesAfterApply --- .../BcThemeConfigControllerEventListener.php | 3 ++ ...ThemeConfigControllerEventListenerTest.php | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php diff --git a/plugins/bc-theme-config/src/Event/BcThemeConfigControllerEventListener.php b/plugins/bc-theme-config/src/Event/BcThemeConfigControllerEventListener.php index 451e078718..1b6dce75ff 100644 --- a/plugins/bc-theme-config/src/Event/BcThemeConfigControllerEventListener.php +++ b/plugins/bc-theme-config/src/Event/BcThemeConfigControllerEventListener.php @@ -32,6 +32,9 @@ class BcThemeConfigControllerEventListener extends BcControllerEventListener * テーマ適用後イベント * @param Event $event * @return void + * @checked + * @noTodo + * @unitTest */ public function baserCoreThemesAfterApply(Event $event) { diff --git a/plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php b/plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php new file mode 100644 index 0000000000..53e4cb29cd --- /dev/null +++ b/plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php @@ -0,0 +1,48 @@ +BcThemeConfigControllerEventListener = new BcThemeConfigControllerEventListener(); + } + + public function tearDown(): void + { + parent::tearDown(); + } + + /** + * Test baserCoreThemesAfterApply + */ + public function test_baserCoreThemesAfterApply() + { + $path = WWW_ROOT . 'files' . DS . 'theme_configs' . DS . 'config.css'; + + if (!is_dir(dirname($path))) { + mkdir(dirname($path), 0777, true); + } + file_put_contents($path, 'test content'); + $this->assertFileExists($path); + + $event = new Event('BaserCore.Themes.afterApply'); + $this->BcThemeConfigControllerEventListener->baserCoreThemesAfterApply($event); + + $this->assertFileDoesNotExist($path); + + // cleanup + if (file_exists($path)) { + unlink($path); + } + if (is_dir(dirname($path))) { + rmdir(dirname($path)); + } + } +} From 4d0385852f154a70d6cc00b3a0984779bf63d663 Mon Sep 17 00:00:00 2001 From: thangnn Date: Tue, 29 Oct 2024 10:10:57 +0700 Subject: [PATCH 2/2] modified --- .../Event/BcThemeConfigControllerEventListenerTest.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php b/plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php index 53e4cb29cd..7d895584ae 100644 --- a/plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php +++ b/plugins/bc-theme-config/tests/TestCase/Event/BcThemeConfigControllerEventListenerTest.php @@ -36,13 +36,5 @@ public function test_baserCoreThemesAfterApply() $this->BcThemeConfigControllerEventListener->baserCoreThemesAfterApply($event); $this->assertFileDoesNotExist($path); - - // cleanup - if (file_exists($path)) { - unlink($path); - } - if (is_dir(dirname($path))) { - rmdir(dirname($path)); - } } }