From 6417ee70f5253fc1d5792fb5d1d7c321c9f3743e Mon Sep 17 00:00:00 2001 From: thangnn Date: Thu, 14 Nov 2024 14:01:01 +0700 Subject: [PATCH 01/23] Add unitTest_BcFrontMiddleware_process --- .../src/Middleware/BcFrontMiddleware.php | 1 + .../Middleware/BcFrontMiddlewareTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/plugins/baser-core/src/Middleware/BcFrontMiddleware.php b/plugins/baser-core/src/Middleware/BcFrontMiddleware.php index 3a819f78b9..84b6d5f131 100644 --- a/plugins/baser-core/src/Middleware/BcFrontMiddleware.php +++ b/plugins/baser-core/src/Middleware/BcFrontMiddleware.php @@ -36,6 +36,7 @@ class BcFrontMiddleware implements MiddlewareInterface * @return ResponseInterface * @checked * @noTodo + * @unitTest */ public function process( ServerRequestInterface $request, diff --git a/plugins/baser-core/tests/TestCase/Middleware/BcFrontMiddlewareTest.php b/plugins/baser-core/tests/TestCase/Middleware/BcFrontMiddlewareTest.php index bb353b3439..777dc258cf 100644 --- a/plugins/baser-core/tests/TestCase/Middleware/BcFrontMiddlewareTest.php +++ b/plugins/baser-core/tests/TestCase/Middleware/BcFrontMiddlewareTest.php @@ -78,4 +78,34 @@ public function test_setCurrent(): void $this->assertNotEmpty($request->getAttribute('currentSite')); } + /** + * Test process + */ + public function test_process(): void + { + ContentFactory::make([ + 'id' => 1, + 'entity_id' => 1, + 'url' => '/', + 'site_id' => 1, + 'status' => true, + ])->persist(); + SiteFactory::make([ + 'id' => 1, + 'name' => '', + 'title' => 'baserCMS inc.', + 'status' => true, + ])->persist(); + $request = $this->getRequest()->withAttribute('isRequestView', true)->withQueryParams([ + 'Site' => SiteFactory::get(1), + 'Content' => ContentFactory::get(1) + ]); + + $rs = $this->execPrivateMethod($this->BcFrontMiddleware, 'setCurrent', [$request]); + $this->assertNotEmpty($rs->getAttribute('currentContent')); + $this->assertNotEmpty($rs->getAttribute('currentSite')); + dd($rs); + + } + } From cf79158971a2349be7a1709e031f7add2fdca652 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Mon, 18 Nov 2024 11:42:40 +0900 Subject: [PATCH 02/23] =?UTF-8?q?BlogCommentMailer::sendCommentToUser()?= =?UTF-8?q?=E3=80=80=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-blog/src/Mailer/BlogCommentMailer.php | 1 + .../tests/TestCase/Mailer/BlogCommentMailerTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/plugins/bc-blog/src/Mailer/BlogCommentMailer.php b/plugins/bc-blog/src/Mailer/BlogCommentMailer.php index d03bb0d333..c3bd0f41db 100755 --- a/plugins/bc-blog/src/Mailer/BlogCommentMailer.php +++ b/plugins/bc-blog/src/Mailer/BlogCommentMailer.php @@ -56,6 +56,7 @@ public function sendCommentToAdmin(string $senderName, array $data) * @param array $data * @checked * @noTodo + * @unitTest */ public function sendCommentToUser(string $senderName, string $userMail, array $data) { diff --git a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php index 49a64fa2ae..eb28851b5c 100644 --- a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php +++ b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php @@ -29,4 +29,14 @@ public function testSendCommentToAdmin() $this->assertEquals('BcBlog.blog_comment_admin', $this->BlogCommentMailer->viewBuilder()->getTemplate()); $this->assertEquals(['test' => 'test'], $this->BlogCommentMailer->viewBuilder()->getVars()); } + + /** + * test sendCommentToUser + */ + public function testSendCommentToUser() + { + $this->BlogCommentMailer->sendCommentToUser('admin baser','user@example.com', ['test' => 'test']); + $this->assertEquals('BcBlog.blog_comment_contributor', $this->BlogCommentMailer->viewBuilder()->getTemplate()); + $this->assertEquals(['test' => 'test'], $this->BlogCommentMailer->viewBuilder()->getVars()); + } } From b4b0fd49028fd99161244b17cc181e7ed8cc914a Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Mon, 18 Nov 2024 13:35:05 +0900 Subject: [PATCH 03/23] =?UTF-8?q?BcCustomContentControllerEventListener::s?= =?UTF-8?q?tartup()&setAdminMenu()=E3=80=80=E3=81=AE=E3=83=A6=E3=83=8B?= =?UTF-8?q?=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 --- ...BcCustomContentControllerEventListener.php | 2 + ...stomContentControllerEventListenerTest.php | 118 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php diff --git a/plugins/bc-custom-content/src/Event/BcCustomContentControllerEventListener.php b/plugins/bc-custom-content/src/Event/BcCustomContentControllerEventListener.php index a1377bb964..1458f8687f 100755 --- a/plugins/bc-custom-content/src/Event/BcCustomContentControllerEventListener.php +++ b/plugins/bc-custom-content/src/Event/BcCustomContentControllerEventListener.php @@ -38,6 +38,7 @@ class BcCustomContentControllerEventListener extends \BaserCore\Event\BcControll * Before render * @checked * @noTodo + * @unitTest */ public function startup(Event $event) { @@ -51,6 +52,7 @@ public function startup(Event $event) * 管理画面メニュー用のデータをセットする * @checked * @noTodo + * @unitTest */ public function setAdminMenu() { diff --git a/plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php b/plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php new file mode 100644 index 0000000000..5c68d259b9 --- /dev/null +++ b/plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php @@ -0,0 +1,118 @@ + + * Copyright (c) NPO baser foundation + * + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License + */ + +namespace BcCustomContent\Test\TestCase\Event; + +use BaserCore\Controller\Admin\UsersController; +use BaserCore\Service\BcDatabaseServiceInterface; +use BaserCore\Test\Scenario\InitAppScenario; +use BaserCore\TestSuite\BcTestCase; +use BcCustomContent\Event\BcCustomContentControllerEventListener; +use BcCustomContent\Service\CustomTablesServiceInterface; +use BcCustomContent\Test\Scenario\CustomContentsScenario; +use BcCustomContent\Test\Scenario\CustomEntriesScenario; +use Cake\Core\Configure; +use Cake\Event\Event; +use Cake\Event\EventManager; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; + +/** + * Class BcCustomContentControllerEventListenerTest + * + * @property BcCustomContentControllerEventListener $BcCustomContentControllerEventListener + */ +class BcCustomContentControllerEventListenerTest extends BcTestCase +{ + /** + * Trait + */ + use ScenarioAwareTrait; + + /** + * @var UsersController + */ + public $UsersController; + + /** + * @var EventManager|null + */ + public $eventManager; + + /** + * setUp + * + * @return void + */ + public function setUp(): void + { + parent::setUp(); + $this->loadFixtureScenario(InitAppScenario::class); + $this->eventManager = EventManager::instance(); + + $this->BcAuthenticationEventListener = new BcCustomContentControllerEventListener(); + foreach ($this->BcAuthenticationEventListener->implementedEvents() as $key => $event) { + $this->eventManager->off($key); + } + $this->UsersController = new UsersController($this->loginAdmin($this->getRequest('/baser/admin/baser-core/users/'))); + } + + /** + * tearDown + * + * @return void + */ + public function tearDown(): void + { + $this->BcAuthenticationEventListener = null; + parent::tearDown(); + } + + /** + * test startup + */ + public function testStartupAnSetAdminMenu() + { + //データを生成 + $dataBaseService = $this->getService(BcDatabaseServiceInterface::class); + $customTable = $this->getService(CustomTablesServiceInterface::class); + //カスタムテーブルとカスタムエントリテーブルを生成 + $customTable->create([ + 'id' => 1, + 'name' => 'recruit_categories', + 'title' => '求人情報', + 'type' => '1', + 'display_field' => 'title', + 'has_child' => 0 + ]); + //フィクチャーからデーターを生成 + $this->loadFixtureScenario(CustomContentsScenario::class); + $this->loadFixtureScenario(CustomEntriesScenario::class); + + $listener = $this->getMockBuilder(BcCustomContentControllerEventListener::class) + ->onlyMethods(['implementedEvents']) + ->addMethods(['usersStartup']) + ->getMock(); + + $listener->method('implementedEvents') + ->willReturn(['Controller.BaserCore.Users.startup' => ['callable' => 'usersStartup']]); + + $this->eventManager + ->on($listener) + ->on($this->BcAuthenticationEventListener) + ->dispatch(new Event('Controller.startup', $this->UsersController, [])); + + //メーニューにカスタムタイトルがあるか確認 + $menu = Configure::read('BcApp.adminNavigation.Contents'); + $this->assertEquals('サービスタイトル', $menu['CustomContent1']['title']); + //不要なテーブルを削除 + $dataBaseService->dropTable('custom_entry_1_recruit_categories'); + } +} From 370a0876236a034893e63780beb9495bf0dd8c91 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Mon, 18 Nov 2024 15:11:53 +0900 Subject: [PATCH 04/23] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php index eb28851b5c..887425ff66 100644 --- a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php +++ b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php @@ -35,7 +35,7 @@ public function testSendCommentToAdmin() */ public function testSendCommentToUser() { - $this->BlogCommentMailer->sendCommentToUser('admin baser','user@example.com', ['test' => 'test']); + $this->BlogCommentMailer->sendCommentToUser('admin baser', 'user@example.com', ['test' => 'test']); $this->assertEquals('BcBlog.blog_comment_contributor', $this->BlogCommentMailer->viewBuilder()->getTemplate()); $this->assertEquals(['test' => 'test'], $this->BlogCommentMailer->viewBuilder()->getVars()); } From 673c1ab3bfb81007197985909f80916ad3b4a86b Mon Sep 17 00:00:00 2001 From: thangnn Date: Tue, 19 Nov 2024 13:55:10 +0700 Subject: [PATCH 05/23] Add unitTest_CustomContentAdminHelper_displayPluginMeta --- .../View/Helper/CustomContentAdminHelper.php | 1 + .../Helper/CustomContentAdminHelperTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/plugins/bc-custom-content/src/View/Helper/CustomContentAdminHelper.php b/plugins/bc-custom-content/src/View/Helper/CustomContentAdminHelper.php index c812732534..0b4901bbde 100644 --- a/plugins/bc-custom-content/src/View/Helper/CustomContentAdminHelper.php +++ b/plugins/bc-custom-content/src/View/Helper/CustomContentAdminHelper.php @@ -319,6 +319,7 @@ public function getEntryIndexTitle(CustomTable $table, CustomEntry $entry) * プラグインのメタフィールドを表示する * @checked * @noTodo + * @unitTest */ public function displayPluginMeta() { diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAdminHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAdminHelperTest.php index 9867cac4d1..a5767ee56a 100644 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAdminHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAdminHelperTest.php @@ -4,6 +4,7 @@ use BaserCore\Service\BcDatabaseServiceInterface; use BaserCore\TestSuite\BcTestCase; +use BcBlog\View\BlogAdminAppView; use BcCustomContent\Model\Entity\CustomEntry; use BcCustomContent\Service\CustomEntriesServiceInterface; use BcCustomContent\Service\CustomTablesServiceInterface; @@ -462,4 +463,23 @@ public function test_isEnabledMoveDownEntry() $result = $this->CustomContentAdminHelper->isEnabledMoveDownEntry($entries, $currentEntry); $this->assertFalse($result); } + + /** + * test displayPluginMeta + */ + public function testDisplayPluginMeta() + { + //準備 + $view = new BlogAdminAppView($this->getRequest('/baser/admin')); + $view->loadHelper('BcAdminForm'); + $this->CustomContentAdminHelper = new CustomContentAdminHelper($view); + + //テスト + ob_start(); + $this->CustomContentAdminHelper->displayPluginMeta(); + $output = ob_get_clean(); + + //戻り値を確認 + $this->assertTextContains(' ', $output); + } } From 15a05d20f7b5979a16bff5e2d159e993110f62ae Mon Sep 17 00:00:00 2001 From: ryuring Date: Wed, 20 Nov 2024 11:43:36 +0900 Subject: [PATCH 06/23] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/Mailer/BcMailer.php | 10 +++++++--- .../baser-core/src/Model/Table/SiteConfigsTable.php | 8 ++++++-- .../tests/TestCase/Mailer/BlogCommentMailerTest.php | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/baser-core/src/Mailer/BcMailer.php b/plugins/baser-core/src/Mailer/BcMailer.php index 59385a1fa0..89672a265b 100644 --- a/plugins/baser-core/src/Mailer/BcMailer.php +++ b/plugins/baser-core/src/Mailer/BcMailer.php @@ -59,9 +59,13 @@ public function __construct($config = null) if ($site) $this->viewBuilder() ->setTheme($site->theme) ->setClassName('BaserCore.BcFrontEmail'); - $this->setFrom([ - BcSiteConfig::get('email') => BcSiteConfig::get('formal_name') - ]); + $adminMail = BcSiteConfig::get('email'); + if (strpos($adminMail, ',') !== false) { + [$fromAdmin] = explode(',', $adminMail); + } else { + $fromAdmin = $adminMail; + } + $this->setFrom($fromAdmin, BcSiteConfig::get('formal_name')); } /** diff --git a/plugins/baser-core/src/Model/Table/SiteConfigsTable.php b/plugins/baser-core/src/Model/Table/SiteConfigsTable.php index 01b5202d74..615fab96fd 100755 --- a/plugins/baser-core/src/Model/Table/SiteConfigsTable.php +++ b/plugins/baser-core/src/Model/Table/SiteConfigsTable.php @@ -79,8 +79,12 @@ public function validationKeyValue(Validator $validator): Validator { $validator ->scalar('email') - ->email('email', 255, __d('baser_core', '管理者メールアドレスの形式が不正です。')) - ->notEmptyString('email', __d('baser_core', '管理者メールアドレスを入力してください。')); + ->notEmptyString('email', __d('baser_core', '管理者メールアドレスを入力してください。')) + ->add('email', ['emails' => [ + 'rule' => 'emails', + 'provider' => 'bc', + 'message' => __d('baser_core', '管理者メールアドレスの形式が不正です。') + ]]); $validator ->scalar('site_url') ->regex('site_url', '/^(http|https):/', __d('baser_core', 'WebサイトURLはURLの形式を入力してください。')) diff --git a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php index 887425ff66..966440cc99 100644 --- a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php +++ b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php @@ -11,7 +11,7 @@ class BlogCommentMailerTest extends BcTestCase public function setUp(): void { parent::setUp(); - SiteConfigFactory::make(['name' => 'email', 'value' => 'basertest@example.com'])->persist(); + SiteConfigFactory::make(['name' => 'email', 'value' => 'basertest@example.com,basertest02@example.com'])->persist(); $this->BlogCommentMailer = new BlogCommentMailer(); } From e7d3e8452771f8026f6e710052f5b411ff70c332 Mon Sep 17 00:00:00 2001 From: hideichi saito Date: Wed, 20 Nov 2024 11:53:09 +0900 Subject: [PATCH 07/23] =?UTF-8?q?=E7=8B=AC=E8=87=AA=E3=83=97=E3=83=A9?= =?UTF-8?q?=E3=82=B0=E3=82=A4=E3=83=B3=E3=81=AE=E5=88=9D=E6=9C=9F=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E3=81=8C=E5=BE=A9=E5=85=83=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=20#4023=20(#4029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/baser-core/src/Service/BcDatabaseService.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/baser-core/src/Service/BcDatabaseService.php b/plugins/baser-core/src/Service/BcDatabaseService.php index 41a36e98af..2d9692659f 100644 --- a/plugins/baser-core/src/Service/BcDatabaseService.php +++ b/plugins/baser-core/src/Service/BcDatabaseService.php @@ -324,11 +324,8 @@ public function dropTable(string $tableName) */ public function loadDefaultDataPattern(string $theme, string $pattern, string $dbConfigKeyName = 'default'): bool { - $plugins = array_merge( - ['BaserCore'], - Configure::read('BcApp.corePlugins'), - BcUtil::getCurrentThemesPlugins() - ); + $folderUtility = new BcFolder(Plugin::path($theme) . 'config' . DS . 'data' . DS . $pattern); + $plugins = $folderUtility->getFolders(); $db = $this->getDataSource($dbConfigKeyName); $db->begin(); From c485e68ace2976e07463172992c742eb82041346 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Thu, 21 Nov 2024 10:04:13 +0900 Subject: [PATCH 08/23] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/SiteConfigsServiceTest.php | 10 +++++--- .../bc-blog/src/Mailer/BlogCommentMailer.php | 23 ++++++++----------- .../TestCase/Mailer/BlogCommentMailerTest.php | 1 + 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/Service/SiteConfigsServiceTest.php b/plugins/baser-core/tests/TestCase/Service/SiteConfigsServiceTest.php index 731a2ac758..ff01ff5631 100644 --- a/plugins/baser-core/tests/TestCase/Service/SiteConfigsServiceTest.php +++ b/plugins/baser-core/tests/TestCase/Service/SiteConfigsServiceTest.php @@ -15,6 +15,7 @@ use BaserCore\Service\SiteConfigsServiceInterface; use BaserCore\Test\Scenario\SiteConfigsScenario; use BaserCore\Utility\BcContainerTrait; +use Cake\TestSuite\EmailTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; use InvalidArgumentException; @@ -24,6 +25,7 @@ class SiteConfigsServiceTest extends \BaserCore\TestSuite\BcTestCase { + use EmailTrait; /** * Trait */ @@ -185,10 +187,12 @@ public function testSendTestMail() { //正常テスト エラーにならない $this->SiteConfigs->sendTestMail(['email' => 'aa@ff.ccc'], 'test@test.com', 'メール送信テスト', 'メール送信テスト'); - + $this->assertMailSentTo('test@test.com'); + $this->assertMailSubjectContains('メール送信テスト'); + $this->assertMailContains('メール送信テスト'); //異常常テスト エラーになる $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The email set for `from` is empty.'); - $this->SiteConfigs->sendTestMail([], '', 'メール送信テスト', 'メール送信テスト'); + $this->expectExceptionMessage('Invalid email set for `from`. You passed `aaa`'); + $this->SiteConfigs->sendTestMail(['email' => 'aaa'], '', 'メール送信テスト', 'メール送信テスト'); } } diff --git a/plugins/bc-blog/src/Mailer/BlogCommentMailer.php b/plugins/bc-blog/src/Mailer/BlogCommentMailer.php index c3bd0f41db..980e729423 100755 --- a/plugins/bc-blog/src/Mailer/BlogCommentMailer.php +++ b/plugins/bc-blog/src/Mailer/BlogCommentMailer.php @@ -33,20 +33,17 @@ class BlogCommentMailer extends BcMailer */ public function sendCommentToAdmin(string $senderName, array $data) { - $adminMail = BcSiteConfig::get('email'); - if (strpos($adminMail, ',') !== false) { - [$fromAdmin] = explode(',', $adminMail); - } else { - $fromAdmin = $adminMail; + $adminMail = explode(',', BcSiteConfig::get('email')); + $fromAdmin = $adminMail[0]; + foreach ($adminMail as $mailTo) { + $this->setTo($mailTo) + ->setFrom($fromAdmin, $senderName) + ->setReplyTo($fromAdmin) + ->setSubject(__d('baser_core', '【{0}】コメントを受け付けました', $senderName)) + ->viewBuilder() + ->setTemplate('BcBlog.blog_comment_admin') + ->setVars($data); } - - $this->setTo($adminMail) - ->setFrom($fromAdmin, $senderName) - ->setReplyTo($fromAdmin) - ->setSubject(__d('baser_core', '【{0}】コメントを受け付けました', $senderName)) - ->viewBuilder() - ->setTemplate('BcBlog.blog_comment_admin') - ->setVars($data); } /** diff --git a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php index 966440cc99..9400dd9aab 100644 --- a/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php +++ b/plugins/bc-blog/tests/TestCase/Mailer/BlogCommentMailerTest.php @@ -26,6 +26,7 @@ public function tearDown(): void public function testSendCommentToAdmin() { $this->BlogCommentMailer->sendCommentToAdmin('test', ['test' => 'test']); + $this->assertEquals(['basertest02@example.com' => 'basertest02@example.com'], $this->BlogCommentMailer->getTo()); $this->assertEquals('BcBlog.blog_comment_admin', $this->BlogCommentMailer->viewBuilder()->getTemplate()); $this->assertEquals(['test' => 'test'], $this->BlogCommentMailer->viewBuilder()->getVars()); } From e79b461e05fc2fd6400a1f734de7ac41ddddadf1 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Thu, 21 Nov 2024 10:22:46 +0900 Subject: [PATCH 09/23] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/TestCase/Service/Front/MailFrontServiceTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/bc-mail/tests/TestCase/Service/Front/MailFrontServiceTest.php b/plugins/bc-mail/tests/TestCase/Service/Front/MailFrontServiceTest.php index d995a1b89a..c2e60f6fbf 100644 --- a/plugins/bc-mail/tests/TestCase/Service/Front/MailFrontServiceTest.php +++ b/plugins/bc-mail/tests/TestCase/Service/Front/MailFrontServiceTest.php @@ -12,6 +12,7 @@ namespace BcMail\Test\TestCase\Service\Front; use BaserCore\Test\Factory\ContentFactory; +use BaserCore\Test\Factory\SiteConfigFactory; use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcFile; @@ -29,6 +30,7 @@ use BcMail\Test\Scenario\MailContentsScenario; use BcMail\Test\Scenario\MailFieldsScenario; use Cake\ORM\Entity; +use Cake\TestSuite\EmailTrait; use Cake\TestSuite\IntegrationTestTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; use InvalidArgumentException; @@ -46,6 +48,7 @@ class MailFrontServiceTest extends BcTestCase */ use ScenarioAwareTrait; use IntegrationTestTrait; + use EmailTrait; /** * set up @@ -483,7 +486,6 @@ public function test_getIndexTemplate() /** * test sendMail - * @throws \Throwable */ public function test_sendMail() { @@ -491,6 +493,7 @@ public function test_sendMail() $this->loadFixtureScenario(InitAppScenario::class); $this->loadFixtureScenario(MailContentsScenario::class); $this->loadFixtureScenario(MailFieldsScenario::class); + SiteConfigFactory::make(['name' => 'email', 'value' => 'basertest@example.com'])->persist(); $MailContentsService = $this->getService(MailContentsServiceInterface::class); $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); MailMessagesFactory::make( @@ -525,8 +528,9 @@ public function test_sendMail() ])->persist(); // normal case $mailContent = $MailContentsService->get(99); - $this->expectException(InvalidArgumentException::class); $this->MailFrontService->sendMail($mailContent, $mailMessage, []); + $this->assertMailSentTo('t@gm.com'); + $this->assertMailSubjectContains('お問い合わせを頂きました99'); } /** From 3471fcdd92e0439bb81cc1bb4699ed86f5b1e65d Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Thu, 21 Nov 2024 11:20:14 +0900 Subject: [PATCH 10/23] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...stomContentControllerEventListenerTest.php | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php b/plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php index 5c68d259b9..db5665b0a9 100644 --- a/plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php @@ -13,12 +13,12 @@ use BaserCore\Controller\Admin\UsersController; use BaserCore\Service\BcDatabaseServiceInterface; +use BaserCore\Test\Factory\ContentFactory; use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BcCustomContent\Event\BcCustomContentControllerEventListener; use BcCustomContent\Service\CustomTablesServiceInterface; -use BcCustomContent\Test\Scenario\CustomContentsScenario; -use BcCustomContent\Test\Scenario\CustomEntriesScenario; +use BcCustomContent\Test\Factory\CustomContentFactory; use Cake\Core\Configure; use Cake\Event\Event; use Cake\Event\EventManager; @@ -57,8 +57,8 @@ public function setUp(): void $this->loadFixtureScenario(InitAppScenario::class); $this->eventManager = EventManager::instance(); - $this->BcAuthenticationEventListener = new BcCustomContentControllerEventListener(); - foreach ($this->BcAuthenticationEventListener->implementedEvents() as $key => $event) { + $this->BcCustomContentControllerEventListener = new BcCustomContentControllerEventListener(); + foreach ($this->BcCustomContentControllerEventListener->implementedEvents() as $key => $event) { $this->eventManager->off($key); } $this->UsersController = new UsersController($this->loginAdmin($this->getRequest('/baser/admin/baser-core/users/'))); @@ -71,7 +71,7 @@ public function setUp(): void */ public function tearDown(): void { - $this->BcAuthenticationEventListener = null; + $this->BcCustomContentControllerEventListener = null; parent::tearDown(); } @@ -84,17 +84,15 @@ public function testStartupAnSetAdminMenu() $dataBaseService = $this->getService(BcDatabaseServiceInterface::class); $customTable = $this->getService(CustomTablesServiceInterface::class); //カスタムテーブルとカスタムエントリテーブルを生成 - $customTable->create([ - 'id' => 1, - 'name' => 'recruit_categories', - 'title' => '求人情報', - 'type' => '1', - 'display_field' => 'title', - 'has_child' => 0 - ]); - //フィクチャーからデーターを生成 - $this->loadFixtureScenario(CustomContentsScenario::class); - $this->loadFixtureScenario(CustomEntriesScenario::class); + $customTable->create(['id' => 1, 'name' => 'recruit_categories']); + CustomContentFactory::make(['id' => 1, 'custom_table_id' => 1])->persist(); + ContentFactory::make([ + 'plugin' => 'BcCustomContent', + 'type' => 'CustomContent', + 'site_id' => 1, + 'title' => 'サービスタイトル', + 'entity_id' => 1, + ])->persist(); $listener = $this->getMockBuilder(BcCustomContentControllerEventListener::class) ->onlyMethods(['implementedEvents']) @@ -106,7 +104,7 @@ public function testStartupAnSetAdminMenu() $this->eventManager ->on($listener) - ->on($this->BcAuthenticationEventListener) + ->on($this->BcCustomContentControllerEventListener) ->dispatch(new Event('Controller.startup', $this->UsersController, [])); //メーニューにカスタムタイトルがあるか確認 From 34fd48b9d03e5203d8bb133ebe3ce1ee8f111121 Mon Sep 17 00:00:00 2001 From: IwasakiRyuichi Date: Thu, 21 Nov 2024 16:06:48 +0900 Subject: [PATCH 11/23] =?UTF-8?q?URL=E5=BD=A2=E5=BC=8F=E4=BB=A5=E5=A4=96?= =?UTF-8?q?=E3=81=AE=E6=96=87=E5=AD=97=E3=81=8C=E5=85=A5=E5=8A=9B=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86=20fix=20#4021?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/ThemeConfigs/index.php | 12 +++--- .../src/Model/Table/ThemeConfigsTable.php | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/plugins/bc-admin-third/templates/plugin/BcThemeConfig/Admin/ThemeConfigs/index.php b/plugins/bc-admin-third/templates/plugin/BcThemeConfig/Admin/ThemeConfigs/index.php index 9ca47785ec..2adbb53c89 100644 --- a/plugins/bc-admin-third/templates/plugin/BcThemeConfig/Admin/ThemeConfigs/index.php +++ b/plugins/bc-admin-third/templates/plugin/BcThemeConfig/Admin/ThemeConfigs/index.php @@ -79,7 +79,7 @@

BcAdminForm->control('logo', ['type' => 'file']) ?>logo): ?>BcAdminForm->control('logo_delete', ['type' => 'checkbox', 'label' => __d('baser_core', '削除する')]) ?>BcAdminForm->error('logo') ?>

BcAdminForm->control('logo_alt', ['type' => 'text', 'size' => 50]) ?> []
- BcAdminForm->control('logo_link', ['type' => 'text', 'size' => 50]) ?> + BcAdminForm->control('logo_link', ['type' => 'text', 'size' => 50]) ?>BcAdminForm->error('logo_link') ?> [] @@ -90,7 +90,7 @@

BcAdminForm->control('main_image_1', ['type' => 'file']) ?>main_image_1): ?>BcAdminForm->control('main_image_1_delete', ['type' => 'checkbox', 'label' => __d('baser_core', '削除する')]) ?>BcAdminForm->error('main_image_1') ?>

BcAdminForm->control('main_image_alt_1', ['type' => 'text', 'size' => 50]) ?> []
- BcAdminForm->control('main_image_link_1', ['type' => 'text', 'size' => 50]) ?> + BcAdminForm->control('main_image_link_1', ['type' => 'text', 'size' => 50]) ?>BcAdminForm->error('main_image_link_1') ?> [] @@ -101,7 +101,7 @@

BcAdminForm->control('main_image_2', ['type' => 'file']) ?>main_image_2): ?>BcAdminForm->control('main_image_2_delete', ['type' => 'checkbox', 'label' => __d('baser_core', '削除する')]) ?>BcAdminForm->error('main_image_2') ?>

BcAdminForm->control('main_image_alt_2', ['type' => 'text', 'size' => 50]) ?> []
- BcAdminForm->control('main_image_link_2', ['type' => 'text', 'size' => 50]) ?> + BcAdminForm->control('main_image_link_2', ['type' => 'text', 'size' => 50]) ?>BcAdminForm->error('main_image_link_2') ?> [] @@ -112,7 +112,7 @@

BcAdminForm->control('main_image_3', ['type' => 'file']) ?>main_image_3): ?>BcAdminForm->control('main_image_3_delete', ['type' => 'checkbox', 'label' => __d('baser_core', '削除する')]) ?>BcAdminForm->error('main_image_3') ?>

BcAdminForm->control('main_image_alt_3', ['type' => 'text', 'size' => 50]) ?> []
- BcAdminForm->control('main_image_link_3', ['type' => 'text', 'size' => 50]) ?> + BcAdminForm->control('main_image_link_3', ['type' => 'text', 'size' => 50]) ?>BcAdminForm->error('main_image_link_3') ?> [] @@ -123,7 +123,7 @@

BcAdminForm->control('main_image_4', ['type' => 'file']) ?>main_image_4): ?>BcAdminForm->control('main_image_4_delete', ['type' => 'checkbox', 'label' => __d('baser_core', '削除する')]) ?>BcAdminForm->error('main_image_4') ?>

BcAdminForm->control('main_image_alt_4', ['type' => 'text', 'size' => 50]) ?> []
- BcAdminForm->control('main_image_link_4', ['type' => 'text', 'size' => 50]) ?> + BcAdminForm->control('main_image_link_4', ['type' => 'text', 'size' => 50]) ?>BcAdminForm->error('main_image_link_4') ?> [] @@ -134,7 +134,7 @@

BcAdminForm->control('main_image_5', ['type' => 'file']) ?>main_image_5): ?>BcAdminForm->control('main_image_5_delete', ['type' => 'checkbox', 'label' => __d('baser_core', '削除する')]) ?>BcAdminForm->error('main_image_5') ?>

BcAdminForm->control('main_image_alt_5', ['type' => 'text', 'size' => 50]) ?> []
- BcAdminForm->control('main_image_link_5', ['type' => 'text', 'size' => 50]) ?> + BcAdminForm->control('main_image_link_5', ['type' => 'text', 'size' => 50]) ?>BcAdminForm->error('main_image_link_5') ?> [] diff --git a/plugins/bc-theme-config/src/Model/Table/ThemeConfigsTable.php b/plugins/bc-theme-config/src/Model/Table/ThemeConfigsTable.php index f61a3f556e..63155029ca 100644 --- a/plugins/bc-theme-config/src/Model/Table/ThemeConfigsTable.php +++ b/plugins/bc-theme-config/src/Model/Table/ThemeConfigsTable.php @@ -128,6 +128,13 @@ public function validationKeyValue(Validator $validator): Validator ] ]); + $validator->add('logo_link', [ + 'urlCheck' => [ + 'rule' => ['url', true], + 'message' => __d('baser_core', '無効なURLです') + ] + ]); + // main_image_1 $validator->add('main_image_1', [ 'fileExt' => [ @@ -137,6 +144,13 @@ public function validationKeyValue(Validator $validator): Validator ] ]); + $validator->add('main_image_link_1',[ + 'urlCheck' => [ + 'rule' => ['url', true], + 'message' => __d('baser_core', '無効なURLです') + ] + ]); + // main_image_2 $validator->add('main_image_2', [ 'fileExt' => [ @@ -146,6 +160,13 @@ public function validationKeyValue(Validator $validator): Validator ] ]); + $validator->add('main_image_link_2',[ + 'urlCheck' => [ + 'rule' => ['url', true], + 'message' => __d('baser_core', '無効なURLです') + ] + ]); + // main_image_3 $validator->add('main_image_3', [ 'fileExt' => [ @@ -155,6 +176,13 @@ public function validationKeyValue(Validator $validator): Validator ] ]); + $validator->add('main_image_link_3',[ + 'urlCheck' => [ + 'rule' => ['url', true], + 'message' => __d('baser_core', '無効なURLです') + ] + ]); + // main_image_4 $validator->add('main_image_4', [ 'fileExt' => [ @@ -164,6 +192,13 @@ public function validationKeyValue(Validator $validator): Validator ] ]); + $validator->add('main_image_link_4',[ + 'urlCheck' => [ + 'rule' => ['url', true], + 'message' => __d('baser_core', '無効なURLです') + ] + ]); + // main_image_5 $validator->add('main_image_5', [ 'fileExt' => [ @@ -172,6 +207,13 @@ public function validationKeyValue(Validator $validator): Validator 'message' => __d('baser_core', '許可されていないファイルです。') ] ]); + + $validator->add('main_image_link_5',[ + 'urlCheck' => [ + 'rule' => ['url', true], + 'message' => __d('baser_core', '無効なURLです') + ] + ]); return $validator; } From c777b7b1046a157baa75538341ef8d833bdc803a Mon Sep 17 00:00:00 2001 From: thangnn Date: Thu, 21 Nov 2024 14:07:06 +0700 Subject: [PATCH 12/23] Add unitTest_BcEventListener_construct --- plugins/baser-core/src/Event/BcEventListener.php | 1 + .../tests/TestCase/Event/BcEventListenerTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/baser-core/src/Event/BcEventListener.php b/plugins/baser-core/src/Event/BcEventListener.php index 355b454a40..462cec063a 100644 --- a/plugins/baser-core/src/Event/BcEventListener.php +++ b/plugins/baser-core/src/Event/BcEventListener.php @@ -64,6 +64,7 @@ class BcEventListener implements EventListenerInterface * コンストラクタ * @checked * @noTodo + * @unitTest */ public function __construct() { diff --git a/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php b/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php index 3fdebf0398..bd88410c70 100644 --- a/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php +++ b/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php @@ -20,6 +20,19 @@ public function tearDown(): void parent::tearDown(); } + /** + * test __construct + */ + public function test__construct() + { + $this->BcEventListener = $this->getMockBuilder(BcEventListener::class) + ->onlyMethods(['getAction']) + ->setMockClassName('TestAction') + ->getMock(); + + $this->assertEquals('TestAction', $this->BcEventListener->plugin); + } + /** * Test getAction * From b39d405152da221f200c97a8cf33676cafa4a233 Mon Sep 17 00:00:00 2001 From: thangnn Date: Thu, 21 Nov 2024 14:09:49 +0700 Subject: [PATCH 13/23] Add unitTest_BcEventListener_implementedEvents --- plugins/baser-core/src/Event/BcEventListener.php | 1 + .../tests/TestCase/Event/BcEventListenerTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/baser-core/src/Event/BcEventListener.php b/plugins/baser-core/src/Event/BcEventListener.php index 355b454a40..bf3c6dd9dc 100644 --- a/plugins/baser-core/src/Event/BcEventListener.php +++ b/plugins/baser-core/src/Event/BcEventListener.php @@ -78,6 +78,7 @@ public function __construct() * @return array * @checked * @noTodo + * @unitTest */ public function implementedEvents(): array { diff --git a/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php b/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php index 3fdebf0398..fd6c79b8eb 100644 --- a/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php +++ b/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php @@ -80,4 +80,15 @@ public static function isActionDataProvider() ['Users.Index', 'Users.Index', true, true], ]; } + + + /** + * test implementedEvents + */ + public function testImplementedEvents() + { + $this->BcEventListener->events = ['isAction' => ['priority' => 100]]; + $rs = $this->BcEventListener->implementedEvents(); + $this->assertNotEmpty($rs); + } } From 062215d78fba0429d858b262289cc1425baf5444 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Fri, 22 Nov 2024 10:28:11 +0900 Subject: [PATCH 14/23] =?UTF-8?q?BcShortCodeEventListener::afterRender()?= =?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=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Event/BcShortCodeEventListener.php | 2 + .../Event/BcShortCodeEventListenerTest.php | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/plugins/baser-core/src/Event/BcShortCodeEventListener.php b/plugins/baser-core/src/Event/BcShortCodeEventListener.php index 97efbd65e2..8cbd21144c 100644 --- a/plugins/baser-core/src/Event/BcShortCodeEventListener.php +++ b/plugins/baser-core/src/Event/BcShortCodeEventListener.php @@ -50,6 +50,7 @@ public function implementedEvents(): array * @return void * @checked * @noTodo + * @unitTest */ public function afterRender(Event $event) { @@ -65,6 +66,7 @@ public function afterRender(Event $event) * @return void * @checked * @noTodo + * @unitTest */ protected function _execShortCode(View $view) { diff --git a/plugins/baser-core/tests/TestCase/Event/BcShortCodeEventListenerTest.php b/plugins/baser-core/tests/TestCase/Event/BcShortCodeEventListenerTest.php index 667183dd9e..4fe21e662e 100644 --- a/plugins/baser-core/tests/TestCase/Event/BcShortCodeEventListenerTest.php +++ b/plugins/baser-core/tests/TestCase/Event/BcShortCodeEventListenerTest.php @@ -4,9 +4,16 @@ use BaserCore\Event\BcShortCodeEventListener; use BaserCore\TestSuite\BcTestCase; +use BaserCore\View\BcFrontAppView; +use Cake\Event\Event; class BcShortCodeEventListenerTest extends BcTestCase { + /** + * @var BcShortCodeEventListener + */ + protected $BcShortCodeEventListener; + public function setUp(): void { parent::setUp(); @@ -26,4 +33,34 @@ public function testImplementedEvents() $this->assertTrue(is_array($this->BcShortCodeEventListener->implementedEvents())); } + /** + * test afterRender + */ + public function testAfterRender() + { + //準備 + $view = new BcFrontAppView($this->getRequest('/')); + $view->loadHelper('BcBaser', ['className' => 'BaserCore.BcBaser']); + $view->assign('content', '[BcBaser.getSitemap]'); + $event = new Event('afterRender', $view); + //テストを実行 + $this->BcShortCodeEventListener->afterRender($event); + //戻り値を確認 + $this->assertTextContains('