From 0f957ccdb57cbe623b0461a27ad5dc425e8439e2 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Wed, 11 Dec 2024 10:37:29 +0900 Subject: [PATCH 01/14] =?UTF-8?q?MailformHelper::authCaptcha()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/BcMail/element/auth_captcha.php | 2 +- .../src/View/Helper/MailformHelper.php | 1 + .../View/Helper/MailformHelperTest.php | 29 ++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php b/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php index c3f498d710..8b2fe10228 100644 --- a/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php +++ b/plugins/bc-front/templates/plugin/BcMail/element/auth_captcha.php @@ -24,7 +24,7 @@ ?> - +
BcBaser->img($captchaUrl, ['alt' => __d('baser_core', '認証画像'), 'class' => $options['class']]) ?> diff --git a/plugins/bc-mail/src/View/Helper/MailformHelper.php b/plugins/bc-mail/src/View/Helper/MailformHelper.php index 45b04a688e..d6530ed63a 100755 --- a/plugins/bc-mail/src/View/Helper/MailformHelper.php +++ b/plugins/bc-mail/src/View/Helper/MailformHelper.php @@ -275,6 +275,7 @@ public function create($context = null, $options = []): string * @return void * @checked * @noTodo + * @unitTest */ public function authCaptcha(string $fieldName, array $options = []) { diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php index 285332f5e9..39692e659c 100644 --- a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php +++ b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php @@ -10,13 +10,24 @@ */ namespace BcMail\Test\TestCase\View\Helper; +use BaserCore\Service\ContentsService; +use BaserCore\Service\ContentsServiceInterface; +use BaserCore\Test\Factory\ContentFactory; +use BaserCore\Test\Factory\SiteFactory; use BaserCore\TestSuite\BcTestCase; +use BaserCore\View\BcFrontAppView; +use BaserCore\View\Helper\BcBaserHelper; use BcMail\Model\Entity\MailField; +use BcMail\Test\Factory\MailContentFactory; +use BcMail\Test\Factory\MailFieldsFactory; use BcMail\Test\Factory\MailMessagesFactory; use BcMail\Service\MailFieldsServiceInterface; +use BcMail\View\Helper\BcMailBaserHelper; use BcMail\View\Helper\MailformHelper; use BcMail\Test\Scenario\MailContentsScenario; use BcMail\Test\Scenario\MailFieldsScenario; +use BcMail\View\Helper\MailHelper; +use BcMail\View\MailFrontAppView; use Cake\ORM\ResultSet; use Cake\View\View; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -71,7 +82,23 @@ public function testCreate() */ public function testAuthCaptcha() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + //データ生成 + SiteFactory::make(['id' => 1])->persist(); + ContentFactory::make(['plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1, 'url' => '/contact/', 'site_id' => 1, 'lft' => 1, 'rght' => 2])->persist(); + MailContentFactory::make(['id' => 1, 'form_template' => 'default', 'mail_template' => 'mail_default'])->persist(); + + //準備 + $view = new MailFrontAppView($this->getRequest('/contact/')); + $view->setPlugin('BcMail'); + $options['helper'] = new BcBaserHelper($view); + $this->MailformHelper = new MailformHelper($view); + + //対象メッソどを呼ぶ + ob_start(); + $this->MailformHelper->authCaptcha('auth_captcha', $options); + $result = ob_get_clean(); + //戻る値を確認 + $this->assertTextContains(' alt="認証画像" class="auth-captcha-image"', $result); } /** From 353fec37657727d4e60d5d95e497a8ca4cf4deb9 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Wed, 11 Dec 2024 10:38:41 +0900 Subject: [PATCH 02/14] =?UTF-8?q?MailformHelper::authCaptcha()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/TestCase/View/Helper/MailformHelperTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php index 39692e659c..51e2844f1f 100644 --- a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php +++ b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php @@ -10,23 +10,17 @@ */ namespace BcMail\Test\TestCase\View\Helper; -use BaserCore\Service\ContentsService; -use BaserCore\Service\ContentsServiceInterface; use BaserCore\Test\Factory\ContentFactory; use BaserCore\Test\Factory\SiteFactory; use BaserCore\TestSuite\BcTestCase; -use BaserCore\View\BcFrontAppView; use BaserCore\View\Helper\BcBaserHelper; use BcMail\Model\Entity\MailField; use BcMail\Test\Factory\MailContentFactory; -use BcMail\Test\Factory\MailFieldsFactory; use BcMail\Test\Factory\MailMessagesFactory; use BcMail\Service\MailFieldsServiceInterface; -use BcMail\View\Helper\BcMailBaserHelper; use BcMail\View\Helper\MailformHelper; use BcMail\Test\Scenario\MailContentsScenario; use BcMail\Test\Scenario\MailFieldsScenario; -use BcMail\View\Helper\MailHelper; use BcMail\View\MailFrontAppView; use Cake\ORM\ResultSet; use Cake\View\View; From 3663ab2c6caaa8a82b0ba8ccbc272c2a47ce4ea3 Mon Sep 17 00:00:00 2001 From: thangnn Date: Wed, 11 Dec 2024 15:31:35 +0700 Subject: [PATCH 03/14] Add unitTest_BcInstallerPlugin_routes --- plugins/bc-installer/src/BcInstallerPlugin.php | 1 + .../tests/TestCase/BcInstallerPluginTest.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/bc-installer/src/BcInstallerPlugin.php b/plugins/bc-installer/src/BcInstallerPlugin.php index 0e6d1f8cb4..0c0563e4c2 100644 --- a/plugins/bc-installer/src/BcInstallerPlugin.php +++ b/plugins/bc-installer/src/BcInstallerPlugin.php @@ -47,6 +47,7 @@ public function services(ContainerInterface $container): void * @param \Cake\Routing\RouteBuilder $routes * @checked * @noTodo + * @unitTest */ public function routes($routes): void { diff --git a/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php b/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php index 50714a0455..80c3f9f935 100644 --- a/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php +++ b/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php @@ -9,7 +9,9 @@ use BcInstaller\Service\Admin\InstallationsAdminServiceInterface; use BcInstaller\Service\InstallationsServiceInterface; use Cake\Console\CommandCollection; +use Cake\Core\Configure; use Cake\Core\Container; +use Cake\Routing\Router; class BcInstallerPluginTest extends BcTestCase { @@ -40,7 +42,12 @@ public function test_services() */ public function test_routes() { - $this->markTestIncomplete('Not implemented yet.'); + Configure::write('BcEnv.isInstalled', false); + $routes = Router::createRouteBuilder('/install'); + $this->BcInstallerPlugin->routes($routes); + $result = Router::parseRequest($this->getRequest('/install')); + $this->assertEquals('Installations', $result['controller']); + Configure::write('BcEnv.isInstalled', true); } /** From 31d0d281db4e1ba8c72c05264eba4c7a567f0f47 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Thu, 12 Dec 2024 11:35:44 +0900 Subject: [PATCH 04/14] =?UTF-8?q?MailformHelper::download=5Fcsv()=20?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/MailMessagesController.php | 1 + .../Admin/MailMessagesControllerTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php index c102d212d6..b759698b92 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php @@ -199,6 +199,7 @@ public function attachment(MailMessagesServiceInterface $service) * @return void * @checked * @noTodo + * @unitTest */ public function download_csv(MailMessagesAdminServiceInterface $service, int $mailContentId) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php index cd25a95477..ac0ac55444 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php @@ -209,4 +209,28 @@ public function testAttachment() { $this->markTestIncomplete('このテストは、まだ実装されていません。'); } + + /** + * test download_csv + */ + public function testDownloadCsv() + { + $this->enableSecurityToken(); + $this->enableCsrfToken(); + //データを生成 + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + $MailMessagesService->createTable(1); + MailContentFactory::make(['id' => 1])->persist(); + ContentFactory::make(['name' => 'name_test', 'plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1])->persist(); + $mailMessageTable = TableRegistry::getTableLocator()->get('mail_message_1'); + $mailMessageTable->save(new Entity(['id' => 1, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41'])); + $mailMessageTable->save(new Entity(['id' => 2, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41'])); + + //対象メソッドをテスト + $this->get('/baser/admin/bc-mail/mail_messages/download_csv/1'); + $this->assertResponseCode(200); + + //不要テーブルを削除 + $MailMessagesService->dropTable(1); + } } From 07afcc77ebd3756e53bc766d675696ab65dd2114 Mon Sep 17 00:00:00 2001 From: thangnn Date: Fri, 13 Dec 2024 07:15:00 +0700 Subject: [PATCH 05/14] Add unitTest_MailFieldsController_checkEnv --- .../Controller/Admin/MailFieldsController.php | 1 + .../Admin/MailFieldsControllerTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php index 153fd49efe..c688ad7213 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php @@ -78,6 +78,7 @@ public function beforeFilter(EventInterface $event) * プラグインの環境をチェックする * @checked * @noTodo + * @unitTest */ protected function _checkEnv() { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index ce15e3ccdf..84f4b4bed3 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -16,6 +16,8 @@ use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; +use BaserCore\Utility\BcFile; +use BaserCore\Utility\BcFolder; use BcMail\Controller\Admin\MailFieldsController; use BcMail\Service\Admin\MailFieldsAdminServiceInterface; use BcMail\Service\MailFieldsServiceInterface; @@ -469,4 +471,19 @@ public function testAdmin_unpublish() //check redirect $this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1'); } + + /** + * _checkEnv + */ + public function test_checkEnv() + { + $folderPath = '/var/www/html/webroot/files/mail/limited'; + $folder = new BcFolder($folderPath); + $folder->delete(); + + $this->execPrivateMethod($this->MailFieldsController, '_checkEnv'); + $this->assertTrue(is_dir($folderPath)); + $file = new BcFile($folderPath . DS . '.htaccess'); + $this->assertTextContains('Order allow', $file->read()); + } } From 9be8c218ed99b4de90345b991089feb12a32c78f Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Fri, 13 Dec 2024 11:48:53 +0900 Subject: [PATCH 06/14] =?UTF-8?q?MailContentsController::edit()=20?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/MailContentsController.php | 1 + .../Admin/MailContentsControllerTest.php | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php index 75d4da3a1f..b7037715ae 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php @@ -55,6 +55,7 @@ public function initialize(): void * @param int ブログコンテンツID * @checked * @noTodo + * @unitTest */ public function edit(MailContentsAdminServiceInterface $service, int $id) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php index d67bbbcb5c..37ef521504 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php @@ -12,7 +12,6 @@ namespace BcMail\Test\TestCase\Controller\Admin; -use BaserCore\Test\Factory\ContentFactory; use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; @@ -90,7 +89,23 @@ public function test_delete() */ public function testAdmin_edit() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + //データーを生成 + $mailContentServices = $this->getService(MailContentsServiceInterface::class); + //データを生成 + $this->loadFixtureScenario(MailContentsScenario::class); + //Postデータを生成 + $mailContent = $mailContentServices->get(1); + $mailContent->description = 'this is api edit'; + //対象URLをコル + $this->post('/baser/admin/bc-mail/mail_contents/edit/1', $mailContent->toArray()); + $this->assertResponseCode(302); + $this->assertFlashMessage('メールフォーム「お問い合わせ」を更新しました。'); + + //エラーを発生した場合 + $this->post('/baser/admin/bc-mail/mail_contents/edit/222', $mailContent->toArray()); + $this->assertResponseCode(404); } /** From bad185143ea52a1529f71d94dfad57043ea89796 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Mon, 16 Dec 2024 10:07:47 +0900 Subject: [PATCH 07/14] =?UTF-8?q?MailContentsController::redirectEditMail(?= =?UTF-8?q?)=20=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Controller/Admin/MailContentsController.php | 1 + .../Controller/Admin/MailContentsControllerTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php index 75d4da3a1f..0a9af8693c 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php @@ -99,6 +99,7 @@ public function edit(MailContentsAdminServiceInterface $service, int $id) * @return Response * @checked * @noTodo + * @unitTest */ private function redirectEditMail($template) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php index d67bbbcb5c..7594658a48 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php @@ -98,7 +98,12 @@ public function testAdmin_edit() */ public function test_redirectEditMail() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $rs = $this->execPrivateMethod($this->MailContentsController, 'redirectEditMail', ['default']); + $this->assertEquals(302, $rs->getStatusCode()); + $this->assertEquals( + ['https://localhost/baser/admin/bc-theme-file/theme_files/edit/BcFront/BcMail/email/text/default.php'], + $rs->getHeader('Location') + ); } /** From 99b885b0370e712f216693fa231ae5dd414e9519 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 17 Dec 2024 11:42:13 +0900 Subject: [PATCH 08/14] =?UTF-8?q?MailContentsController::redirectEditForm(?= =?UTF-8?q?)=20=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Controller/Admin/MailContentsController.php | 1 + .../Controller/Admin/MailContentsControllerTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php index 75d4da3a1f..d49ecdf7d4 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailContentsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailContentsController.php @@ -135,6 +135,7 @@ private function redirectEditMail($template) * @return Response * @checked * @noTodo + * @unitTest */ private function redirectEditForm($template) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php index d67bbbcb5c..37106c2d9f 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailContentsControllerTest.php @@ -106,7 +106,12 @@ public function test_redirectEditMail() */ public function test_redirectEditForm() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $rs = $this->execPrivateMethod($this->MailContentsController, 'redirectEditForm', ['default']); + $this->assertEquals(302, $rs->getStatusCode()); + $this->assertEquals( + ['https://localhost/baser/admin/bc-theme-file/theme_files/edit/BcFront/BcMail/etc/Mail/default/index.php'], + $rs->getHeader('Location') + ); } /** From 52b87b0cc41c69c4c175e6077a428541271b11a9 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 17 Dec 2024 12:07:31 +0900 Subject: [PATCH 09/14] =?UTF-8?q?MailFieldsController::beforeFilter()=20?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Admin/MailFieldsController.php | 1 + .../Admin/MailFieldsControllerTest.php | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php index 153fd49efe..4ac5e7ce23 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailFieldsController.php @@ -54,6 +54,7 @@ public function initialize(): void * @return void * @checked * @noTodo + * @unitTest */ public function beforeFilter(EventInterface $event) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php index ce15e3ccdf..3a7ea2a053 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailFieldsControllerTest.php @@ -13,12 +13,11 @@ namespace BcMail\Test\TestCase\Controller\Admin; use BaserCore\Service\BcDatabaseServiceInterface; +use BaserCore\Test\Factory\ContentFactory; use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; use BcMail\Controller\Admin\MailFieldsController; -use BcMail\Service\Admin\MailFieldsAdminServiceInterface; -use BcMail\Service\MailFieldsServiceInterface; use BcMail\Service\MailMessagesServiceInterface; use BcMail\Test\Factory\MailFieldsFactory; use BcMail\Test\Scenario\MailContentsScenario; @@ -75,7 +74,31 @@ public function testInitialize() */ public function testBeforeFilter() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + ContentFactory::make([ + 'name' => 'name_test', + 'plugin' => 'BcMail', + 'type' => 'MailContent', + 'url' => '/contact/', + 'site_id' => 1, + 'title' => 'お問い合わせ', + 'entity_id' => 1 + ])->persist(); + + //正常テスト・エラーにならない + $request = $this->getRequest('/baser/admin/bc-mail/mail_fields/view/1/1'); + $request = $this->loginAdmin($request); + $this->MailFieldsController = new MailFieldsController($request); + $event = new Event('filter'); + $this->MailFieldsController->beforeFilter($event); + + //異常テスト + $request = $this->getRequest('/baser/admin/bc-mail/mail_fields/view/2222/1'); + $request = $this->loginAdmin($request); + $this->MailFieldsController = new MailFieldsController($request); + $event = new Event('filter'); + $this->expectExceptionMessage('コンテンツデータが見つかりません。'); + $this->expectException('BaserCore\Error\BcException'); + $this->MailFieldsController->beforeFilter($event); } /** From c02ae3cc88643e716429ab5e3594068a0204fe7a Mon Sep 17 00:00:00 2001 From: thangnn Date: Tue, 17 Dec 2024 16:00:31 +0700 Subject: [PATCH 10/14] modified --- .../bc-installer/tests/TestCase/BcInstallerPluginTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php b/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php index 80c3f9f935..c8b371926a 100644 --- a/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php +++ b/plugins/bc-installer/tests/TestCase/BcInstallerPluginTest.php @@ -47,6 +47,11 @@ public function test_routes() $this->BcInstallerPlugin->routes($routes); $result = Router::parseRequest($this->getRequest('/install')); $this->assertEquals('Installations', $result['controller']); + + $routes = Router::createRouteBuilder('/'); + $this->BcInstallerPlugin->routes($routes); + $result = Router::parseRequest($this->getRequest('/')); + $this->assertEquals('Installations', $result['controller']); Configure::write('BcEnv.isInstalled', true); } From 0d77dd5d6b89d616050ec5bccea4476942ea2c56 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Wed, 18 Dec 2024 13:15:04 +0900 Subject: [PATCH 11/14] =?UTF-8?q?MailMessagesController::attachment()=20?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/MailMessagesController.php | 2 +- .../Admin/MailMessagesControllerTest.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php index b759698b92..3ccf5bed9d 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php @@ -163,6 +163,7 @@ public function delete( * @return void * @checked * @noTodo + * @unitTest */ public function attachment(MailMessagesServiceInterface $service) { @@ -189,7 +190,6 @@ public function attachment(MailMessagesServiceInterface $service) } Header(sprintf('Content-type: %s; name=%s', $mineType, $file)); echo file_get_contents($filePath); - exit(); } /** diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php index ac0ac55444..56d9c04280 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php @@ -207,7 +207,24 @@ public function testDelete() */ public function testAttachment() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + $MailMessagesService->createTable(1); + MailContentFactory::make(['id' => 1])->persist(); + ContentFactory::make(['name' => 'name_test', 'plugin' => 'BcMail', 'type' => 'MailContent', 'entity_id' => 1])->persist(); + $mailMessageTable = TableRegistry::getTableLocator()->get('mail_message_1'); + $mailMessageTable->save(new Entity(['id' => 1, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41'])); + $mailMessageTable->save(new Entity(['id' => 2, 'created' => '2016-07-29 18:02:53', 'modified' => '2020-09-14 21:10:41'])); + + ob_start(); + $this->get('/baser/admin/bc-mail/mail_messages/attachment/1/00000002_tel.jpg'); + $actualIsHelp = ob_get_clean(); + $this->assertNotEmpty($actualIsHelp); + + //不要テーブルを削除 + $MailMessagesService->dropTable(1); } /** From 880fee17264f23801cc00e567893a1ec0fa52b42 Mon Sep 17 00:00:00 2001 From: thangnn Date: Wed, 18 Dec 2024 16:08:57 +0700 Subject: [PATCH 12/14] unitTest_InstallerMailer_installed --- .../src/Mailer/Admin/InstallerMailer.php | 1 + .../Mailer/Admin/InstallerMailerTest.php | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php diff --git a/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php b/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php index 076f6dd09b..aba99d1054 100644 --- a/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php +++ b/plugins/bc-installer/src/Mailer/Admin/InstallerMailer.php @@ -33,6 +33,7 @@ class InstallerMailer extends BcAdminMailer * @param PasswordRequest|EntityInterface * @checked * @noTodo + * @unitTest */ public function installed(string $email) { diff --git a/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php b/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php new file mode 100644 index 0000000000..e6b4d431d8 --- /dev/null +++ b/plugins/bc-installer/tests/TestCase/Mailer/Admin/InstallerMailerTest.php @@ -0,0 +1,66 @@ + + * Copyright (c) baserCMS Users Community + * + * @copyright Copyright (c) baserCMS Users Community + * @link https://basercms.net baserCMS Project + * @since baserCMS v 4.0.9 + * @license https://basercms.net/license/index.html + */ + +namespace BcInstaller\Test\TestCase\Mailer\Admin; +use BaserCore\Test\Factory\SiteConfigFactory; +use BaserCore\Test\Factory\SiteFactory; +use BaserCore\TestSuite\BcTestCase; +use BcInstaller\Mailer\Admin\InstallerMailer; +use Cake\TestSuite\EmailTrait; + +/** + * Class InstallerMailerTest + * + * @property InstallerMailer $InstallerMailer + */ +class InstallerMailerTest extends BcTestCase +{ + + use EmailTrait; + + /** + * setup + */ + public function setUp(): void + { + parent::setUp(); + SiteConfigFactory::make(['name' => 'email', 'value' => 'basertest@example.com'])->persist(); + SiteFactory::make(['id' => 1, 'display_name' => 'main site'])->persist(); + + $this->InstallerMailer = new InstallerMailer(); + } + + /** + * tearDown + * + * @return void + */ + public function tearDown(): void + { + parent::tearDown(); + } + + /** + * beforeFilter + */ + public function testInstalled() + { + $this->InstallerMailer->installed('test@example.com'); + + //戻り値確認 + $this->assertEquals(['test@example.com' => 'test@example.com'], $this->InstallerMailer->getTo()); + $vars = $this->InstallerMailer->viewBuilder()->getVars(); + $this->assertEquals('test@example.com', $vars['email']); + $this->assertEquals('https://localhost/', $vars['siteUrl']); + $this->assertEquals('https://localhost/baser/admin/baser-core/users/login', $vars['adminUrl']); + } + +} From a8d9e93d0fa724bfd201949d649d340f343c6d7e Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Thu, 19 Dec 2024 09:52:13 +0900 Subject: [PATCH 13/14] =?UTF-8?q?InstallationsController::beforeFilter()?= =?UTF-8?q?=20=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Controller/Admin/InstallationsController.php | 1 + .../Controller/Admin/InstallationsControllerTest.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/bc-installer/src/Controller/Admin/InstallationsController.php b/plugins/bc-installer/src/Controller/Admin/InstallationsController.php index fdc348bebd..59c5c9402f 100644 --- a/plugins/bc-installer/src/Controller/Admin/InstallationsController.php +++ b/plugins/bc-installer/src/Controller/Admin/InstallationsController.php @@ -49,6 +49,7 @@ class InstallationsController extends BcAdminAppController * @return void * @checked * @noTodo + * @unitTest */ public function beforeFilter(EventInterface $event) { diff --git a/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php b/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php index ca642492d2..15c6f3af42 100644 --- a/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php +++ b/plugins/bc-installer/tests/TestCase/Controller/Admin/InstallationsControllerTest.php @@ -12,6 +12,7 @@ namespace BcInstaller\Test\TestCase\Controller\Admin; use BaserCore\TestSuite\BcTestCase; use BcInstaller\Controller\Admin\InstallationsController; +use Cake\Event\Event; /** * Class InstallationsControllerTest @@ -45,7 +46,10 @@ public function tearDown(): void */ public function testBeforeFilter() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->InstallationsController = new InstallationsController($this->getRequest()); + $event = new Event('Controller.beforeFilter', $this->InstallationsController); + $this->InstallationsController->beforeFilter($event); + $this->assertEquals(300, ini_get("max_execution_time")); } /** From be553fc45f5df5c0b323be0f0a7768b3aa6841de Mon Sep 17 00:00:00 2001 From: ryuring Date: Fri, 20 Dec 2024 17:52:52 +0900 Subject: [PATCH 14/14] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=BD=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A1=8C=E3=81=97=E3=81=9F=E9=9A=9B=E3=81=AB=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=97=E3=81=A6=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=86=E5=95=8F=E9=A1=8C=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/Controller/AppController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Controller/AppController.php b/plugins/baser-core/src/Controller/AppController.php index 042326c8f9..488570b559 100644 --- a/plugins/baser-core/src/Controller/AppController.php +++ b/plugins/baser-core/src/Controller/AppController.php @@ -75,7 +75,7 @@ public function __construct( parent::__construct($request, $response, $name, $eventManager, $components); // CSRFトークンの場合は高速化のためここで処理を終了 - if(!$request->is('requestview')) return; + if(!BcUtil::isConsole() && !$request->is('requestview')) return; $request->getSession()->start();