diff --git a/plugins/baser-core/src/BcPlugin.php b/plugins/baser-core/src/BcPlugin.php index 9560e58a1c..dcc449b98c 100644 --- a/plugins/baser-core/src/BcPlugin.php +++ b/plugins/baser-core/src/BcPlugin.php @@ -466,6 +466,7 @@ public function routes(RouteBuilder $routes): void * @return RouteBuilder * @checked * @noTodo + * @unitTest */ public function contentsRoutingForReverse(RouteBuilder $routes, string $plugin) { @@ -494,6 +495,7 @@ function(RouteBuilder $routes) { * @return RouteBuilder * @checked * @noTodo + * @unitTest */ public function frontPageRouting(RouteBuilder $routes, string $plugin) { diff --git a/plugins/baser-core/src/Event/BcEventListener.php b/plugins/baser-core/src/Event/BcEventListener.php index 355b454a40..7d1c3d7863 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() { @@ -78,6 +79,7 @@ public function __construct() * @return array * @checked * @noTodo + * @unitTest */ public function implementedEvents(): array { 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/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/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/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/baser-core/src/Service/Admin/BcAdminContentsService.php b/plugins/baser-core/src/Service/Admin/BcAdminContentsService.php index 8513b44ebb..5a632f5fc6 100644 --- a/plugins/baser-core/src/Service/Admin/BcAdminContentsService.php +++ b/plugins/baser-core/src/Service/Admin/BcAdminContentsService.php @@ -133,7 +133,7 @@ public function getLayoutTemplates(EntityInterface $content) if (in_array($parentTemplate, $templates)) { unset($templates[$parentTemplate]); } - $templates = array_merge($templates, ['' => __d('baser_core', '親フォルダの設定に従う') . '(' . $parentTemplate . ')']); + $templates = array_merge(['' => __d('baser_core', '親フォルダの設定に従う') . '(' . $parentTemplate . ')'], $templates); } return $templates; } diff --git a/plugins/baser-core/src/Service/BcDatabaseService.php b/plugins/baser-core/src/Service/BcDatabaseService.php index 41a36e98af..fedc16963c 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(); @@ -1052,7 +1049,7 @@ public function writeSchema($table, $options) 'schema' => $schema ]); - $eventManager = EventManager::instance(); + $eventManager = new EventManager(); $beforeRenderListeners = BcUtil::offEvent($eventManager, 'View.beforeRender'); $afterRenderListeners = BcUtil::offEvent($eventManager, 'View.afterRender'); diff --git a/plugins/baser-core/src/Utility/BcUtil.php b/plugins/baser-core/src/Utility/BcUtil.php index c48cb7623c..8da2c6a2ae 100644 --- a/plugins/baser-core/src/Utility/BcUtil.php +++ b/plugins/baser-core/src/Utility/BcUtil.php @@ -11,6 +11,7 @@ namespace BaserCore\Utility; +use BaserCore\Error\BcException; use BaserCore\Middleware\BcAdminMiddleware; use BaserCore\Middleware\BcFrontMiddleware; use BaserCore\Middleware\BcRequestFilterMiddleware; @@ -1641,6 +1642,13 @@ public static function fgetcsvReg(&$handle, $length = null, $d = ',', $e = '"') */ public static function offEvent(EventManagerInterface $eventManager, string $eventKey) { + $reflection = new ReflectionClass($eventManager); + $property = $reflection->getProperty('_isGlobal'); + $property->setAccessible(true); + if($property->getValue($eventManager)) { + throw new BcException(__d('baser_core', 'グローバルイベントマネージャーからはイベントをオフにすることはできません。')); + } + $globalEventManager = $eventManager->instance(); $eventListeners = [ 'local' => $eventManager->prioritisedListeners($eventKey), @@ -1674,6 +1682,13 @@ public static function offEvent(EventManagerInterface $eventManager, string $eve */ public static function onEvent(EventManagerInterface $eventManager, string $eventKey, array $eventListeners) { + $reflection = new ReflectionClass($eventManager); + $property = $reflection->getProperty('_isGlobal'); + $property->setAccessible(true); + if($property->getValue($eventManager)) { + throw new BcException(__d('baser_core', 'グローバルイベントマネージャーからはイベントをオンにすることはできません。')); + } + $globalEventManager = $eventManager->instance(); if (!empty($eventListeners['local'])) { foreach($eventListeners['local'] as $priority => $listeners) { diff --git a/plugins/baser-core/tests/TestCase/BcPluginTest.php b/plugins/baser-core/tests/TestCase/BcPluginTest.php index 34218a84b2..bf637057f2 100644 --- a/plugins/baser-core/tests/TestCase/BcPluginTest.php +++ b/plugins/baser-core/tests/TestCase/BcPluginTest.php @@ -576,6 +576,24 @@ public function test_applyAsTheme() $this->assertEquals($updateTheme, $site->theme); } + /** + * test frontPageRouting + */ + public function testFrontPageRouting() + { + // 管理画面のプラグイン用ルーティング + $result = Router::parseRequest($this->getRequest('/baser/admin/bc-blog/blog_contents/index')); + $this->assertEquals('BlogContents', $result['controller']); + $result = Router::parseRequest($this->getRequest('/baser/admin/bc-blog/blog_contents/edit/1')); + $this->assertEquals('BlogContents', $result['controller']); + + // フロントエンドのプラグイン用ルーティング + $result = Router::parseRequest($this->getRequest('/bc-blog/blog_contents/index')); + $this->assertEquals('BlogContents', $result['controller']); + $result = Router::parseRequest($this->getRequest('/bc-blog/blog_contents/edit/1')); + $this->assertEquals('BlogContents', $result['controller']); + } + /** * test Rest API */ @@ -646,4 +664,24 @@ public function testRestApi() $this->assertEquals(0, count($result->pages)); } + /** + * test contentsRoutingForReverse + */ + public function testContentsRoutingForReverse() + { + SiteFactory::make(['id' => '1', 'main_site_id' => null])->persist(); + SiteFactory::make(['id' => '2', 'main_site_id' => 1, 'alias' => 's'])->persist(); + ContentFactory::make(['plugin' => 'BcBlog', 'type' => 'BlogContent', 'entity_id' => 31, 'url' => '/news/', 'site_id' => 1])->persist(); + $this->BcPlugin = new BcPlugin(['name' => 'BcBlog']); + $routes = Router::createRouteBuilder('/'); + $this->BcPlugin->routes($routes); + $this->getRequest('/'); + $this->assertEquals('/news/', Router::url([ + 'plugin' => 'BcBlog', + 'controller' => 'Blog', + 'action' => 'index', + 'entityId' => 31 + ])); + } + } diff --git a/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php b/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php index 3fdebf0398..ea0b7af4e7 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 * @@ -80,4 +93,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); + } } 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('