From 8049aa49046f3c42ebe8d43755112112265307c5 Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Tue, 29 Oct 2024 11:19:57 +0900 Subject: [PATCH 1/8] =?UTF-8?q?CustomContentAppHelperTest::=5F=5Fconstruct?= =?UTF-8?q?()=20&=20loadPluginHelper()=20=E3=83=A6=E3=83=8B=E3=83=83?= =?UTF-8?q?=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 --- .../View/Helper/CustomContentAppHelper.php | 2 ++ .../Helper/CustomContentAppHelperTest.php | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/bc-custom-content/src/View/Helper/CustomContentAppHelper.php b/plugins/bc-custom-content/src/View/Helper/CustomContentAppHelper.php index 4a4a91bdc7..b9a03edaf7 100644 --- a/plugins/bc-custom-content/src/View/Helper/CustomContentAppHelper.php +++ b/plugins/bc-custom-content/src/View/Helper/CustomContentAppHelper.php @@ -56,6 +56,7 @@ class CustomContentAppHelper extends Helper * @param array $config * @checked * @noTodo + * @unitTest */ public function __construct(View $view, array $config = []) { @@ -67,6 +68,7 @@ public function __construct(View $view, array $config = []) * プラグインのヘルパーを読み込む * @checked * @noTodo + * @unitTest */ public function loadPluginHelper(): void { diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php index 8fb9d1a5e5..9c83856b2f 100644 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php @@ -44,12 +44,29 @@ public function tearDown(): void parent::tearDown(); } + /** + * test __construct + */ + public function test__construct() + { + //プラグインのヘルパーが読み込めるか確認すること + $this->assertNotNull($this->CustomContentAppHelper->BcCcAutoZip); + $this->assertNotNull($this->CustomContentAppHelper->BcCcCheckbox); + $this->assertNotNull($this->CustomContentAppHelper->BcCcDate); + } + /** * test loadPluginHelper */ public function test_loadPluginHelper() { - $this->markTestIncomplete('このテストはまだ実装されていません。'); + //プラグインのヘルパーが読み込めるか確認すること + $this->assertNotNull($this->CustomContentAppHelper->BcCcAutoZip); + $this->assertNotNull($this->CustomContentAppHelper->BcCcCheckbox); + $this->assertNotNull($this->CustomContentAppHelper->BcCcDate); + $this->assertNotNull($this->CustomContentAppHelper->BcCcCheckbox); + $this->assertNotNull($this->CustomContentAppHelper->BcCcEmail); + $this->assertNotNull($this->CustomContentAppHelper->BcCcFile); } /** * test isEnableField From 79b67f1cf3418a4877c07037294f5895291d91dd Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Wed, 30 Oct 2024 09:48:58 +0900 Subject: [PATCH 2/8] =?UTF-8?q?CustomContentAppHelperTest::=5F=5Fconstruct?= =?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 --- .../tests/TestCase/View/Helper/CustomContentAppHelperTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php index 9c83856b2f..874fb78e6a 100644 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php @@ -18,6 +18,10 @@ use Cake\View\View; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; +/** + * class CustomContentAppHelperTest + * @property CustomContentAppHelper $CustomContentAppHelper + */ class CustomContentAppHelperTest extends BcTestCase { /** From 243fe875525aab0a39f759225505974327088a78 Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Wed, 30 Oct 2024 10:17:12 +0900 Subject: [PATCH 3/8] =?UTF-8?q?CustomContentAppHelperTest::=5F=5Fconstruct?= =?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 --- .../tests/TestCase/View/Helper/CustomContentAppHelperTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php index 874fb78e6a..32b977f55f 100644 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php @@ -5,6 +5,7 @@ use BaserCore\Service\BcDatabaseServiceInterface; use BaserCore\Test\Scenario\SitesScenario; use BaserCore\TestSuite\BcTestCase; +use BaserCore\Utility\BcUtil; use BcCustomContent\Model\Entity\CustomLink; use BcCustomContent\Service\CustomContentsServiceInterface; use BcCustomContent\Service\CustomEntriesServiceInterface; @@ -36,6 +37,7 @@ class CustomContentAppHelperTest extends BcTestCase public function setUp(): void { parent::setUp(); + BcUtil::includePluginClass('BcCustomContent'); $this->CustomContentAppHelper = new CustomContentAppHelper(new View()); } /** From 40a49d814af476d6e1aa1211fb34d63385616ee1 Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Tue, 12 Nov 2024 13:22:43 +0900 Subject: [PATCH 4/8] =?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/Model/Table/CustomEntriesTableTest.php | 2 +- .../tests/TestCase/Service/CustomEntriesServiceTest.php | 4 ++-- .../tests/TestCase/Utility/CustomContentUtilTest.php | 4 ++-- .../tests/TestCase/View/Helper/CustomContentAppHelperTest.php | 1 - .../tests/TestCase/View/Helper/CustomContentHelperTest.php | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php index e4bd8d73c8..1ccd230ace 100644 --- a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php @@ -818,7 +818,7 @@ public function test_beforeMarshal() */ public function test_autoConvert() { - Configure::write('BcCustomContent.fieldTypes.BcCcFile.controlType', 'file'); +// Configure::write('BcCustomContent.fieldTypes.BcCcFile.controlType', 'file'); //データ生成 CustomFieldFactory::make([ 'id' => 1, diff --git a/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php b/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php index 656edb6b9d..6cc19d6aea 100644 --- a/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php @@ -114,8 +114,8 @@ public function test_getNew() */ public function test_getFieldControlType() { - Configure::write('BcCustomContent.fieldTypes.BcCcText.controlType', 'text'); - Configure::write('BcCustomContent.fieldTypes.BcCcCheckbox.controlType', 'checkbox'); +// Configure::write('BcCustomContent.fieldTypes.BcCcText.controlType', 'text'); +// Configure::write('BcCustomContent.fieldTypes.BcCcCheckbox.controlType', 'checkbox'); //正常系実行 $result = $this->CustomEntriesService->getFieldControlType('BcCcText'); diff --git a/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php b/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php index 65b0f17d4a..d0fda31387 100644 --- a/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php @@ -25,7 +25,7 @@ public function tearDown(): void public function test_getPluginSetting() { //plugin and name is not empty - Configure::write('BcCustomContent.fieldTypes.testPlugin.testSetting', 'testValue'); + //Configure::write('BcCustomContent.fieldTypes.testPlugin.testSetting', 'testValue'); $rs = CustomContentUtil::getPluginSetting('testPlugin', 'testSetting'); $this->assertEquals('testValue', $rs); @@ -33,4 +33,4 @@ public function test_getPluginSetting() $rs = CustomContentUtil::getPluginSetting('testPlugin'); $this->assertEquals(['testSetting' => 'testValue'], $rs); } -} \ No newline at end of file +} diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php index 32b977f55f..785ff948af 100644 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php @@ -70,7 +70,6 @@ public function test_loadPluginHelper() $this->assertNotNull($this->CustomContentAppHelper->BcCcAutoZip); $this->assertNotNull($this->CustomContentAppHelper->BcCcCheckbox); $this->assertNotNull($this->CustomContentAppHelper->BcCcDate); - $this->assertNotNull($this->CustomContentAppHelper->BcCcCheckbox); $this->assertNotNull($this->CustomContentAppHelper->BcCcEmail); $this->assertNotNull($this->CustomContentAppHelper->BcCcFile); } diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php index 074b14df69..711efc748f 100755 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php @@ -250,7 +250,7 @@ public function test_getFieldTitle() public function test_getFieldValue($displayFront, $fieldType, $requestUrl, $fieldName, $fieldValue, $options, $expect) { //plugin BcCcRelatedを追加 - Configure::write('BcCustomContent.fieldTypes.BcCcRelated', ['category' => '選択', 'label' => '関連データ', 'columnType' => 'string', 'controlType' => 'select', 'preview' => true, 'loop' => true]); +// Configure::write('BcCustomContent.fieldTypes.BcCcRelated', ['category' => '選択', 'label' => '関連データ', 'columnType' => 'string', 'controlType' => 'select', 'preview' => true, 'loop' => true]); //サービスをコル $dataBaseService = $this->getService(BcDatabaseServiceInterface::class); $customTable = $this->getService(CustomTablesServiceInterface::class); From ed8b5e0afadb9c8acbfab9feca21f27ebb4c769c Mon Sep 17 00:00:00 2001 From: TPGF00003 Date: Fri, 15 Nov 2024 10:02:53 +0900 Subject: [PATCH 5/8] =?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 --- .../tests/TestCase/BcPluginTest.php | 1236 ++++++++--------- 1 file changed, 618 insertions(+), 618 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/BcPluginTest.php b/plugins/baser-core/tests/TestCase/BcPluginTest.php index 9d80842121..23c23bb5a0 100644 --- a/plugins/baser-core/tests/TestCase/BcPluginTest.php +++ b/plugins/baser-core/tests/TestCase/BcPluginTest.php @@ -1,619 +1,619 @@ - * 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 BaserCore\Test\TestCase; - -use BaserCore\BcPlugin; -use BaserCore\Service\SitesService; -use BaserCore\Test\Factory\PermissionFactory; -use BaserCore\Test\Factory\PluginFactory; -use BaserCore\Test\Factory\UserFactory; -use BaserCore\Test\Scenario\ContentFoldersScenario; -use BaserCore\Test\Scenario\ContentsScenario; -use BaserCore\Test\Scenario\PluginsScenario; -use BaserCore\Test\Scenario\SiteConfigsScenario; -use BaserCore\Test\Scenario\SitesScenario; -use BaserCore\Test\Scenario\UserGroupsScenario; -use BaserCore\Test\Scenario\UserScenario; -use BaserCore\Test\Scenario\UsersUserGroupsScenario; -use BaserCore\TestSuite\BcTestCase; -use BaserCore\Utility\BcFile; -use BaserCore\Utility\BcFolder; -use BaserCore\Utility\BcUtil; -use Cake\Core\Plugin; -use Cake\Datasource\ConnectionManager; -use Cake\ORM\TableRegistry; -use Cake\Routing\Router; -use Cake\TestSuite\IntegrationTestTrait; -use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; - -/** - * Class BcPluginTest - */ -class BcPluginTest extends BcTestCase -{ - - use ScenarioAwareTrait; - - /** - * @var BcPlugin - */ - public $BcPlugin; - - /** - * Set Up - * - * @return void - */ - public function setUp(): void - { - parent::setUp(); - $this->loadFixtureScenario(UserScenario::class); - $this->loadFixtureScenario(UserGroupsScenario::class); - $this->loadFixtureScenario(UsersUserGroupsScenario::class); - $this->loadFixtureScenario(ContentsScenario::class); - $this->loadFixtureScenario(SitesScenario::class); - $this->loadFixtureScenario(SiteConfigsScenario::class); - $this->loadFixtureScenario(ContentFoldersScenario::class); - $this->loadFixtureScenario(PluginsScenario::class); - $this->BcPlugin = new BcPlugin(['name' => 'BcBlog']); - } - - /** - * Tear Down - * - * @return void - */ - public function tearDown(): void - { - unset($this->BcPlugin); - parent::tearDown(); - } - - /** - * testInitialize - */ - public function testInitialize() - { - $this->assertNotEmpty($this->BcPlugin->migrations); - } - - /** - * testInstall - */ - public function testInstallAndUninstall() - { - $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); - // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 - - // インストール - $this->BcPlugin->install(['connection' => 'test']); - $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); - $this->assertEquals(1, $plugins->priority); - - // アンインストール - $from = BcUtil::getPluginPath('BcBlog'); - $pluginDir = dirname($from); - $folder = new BcFolder($from); - $to = $pluginDir . DS . 'BcBlogBak'; - $folder->copy($to); - $folder->create(); - $this->BcPlugin->uninstall(['connection' => 'test']); - $this->assertFalse(is_dir($from)); - $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); - $this->assertNull($plugins); - $folder->move( $to); - $this->BcPlugin->install(['connection' => 'test']); - } - - /** - * testRollback - */ - public function testRollback() - { - $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); - // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 - - $this->BcPlugin->install(['connection' => 'test']); - $this->BcPlugin->rollbackDb(['connection' => 'test']); - $collection = ConnectionManager::get('default')->getSchemaCollection(); - $tables = $collection->listTables(); - $this->assertNotContains('blog_posts', $tables); - $plugins = $this->getTableLocator()->get('BaserCore.Plugins'); - $plugins->deleteAll(['name' => 'BcBlog']); - $this->BcPlugin->install(['connection' => 'test']); - } - - /** - * testRoutes - */ - public function testRoutes() - { - $routes = Router::createRouteBuilder('/'); - $this->BcPlugin->routes($routes); - - // コンテンツ管理のプラグイン用のリバースルーティング - $this->getRequest('/'); - $this->assertEquals('/news/', Router::url([ - 'plugin' => 'BcBlog', - 'controller' => 'Blog', - 'action' => 'index', - 'entityId' => 31 - ])); - $this->assertEquals('/news/archives/1', Router::url([ - 'plugin' => 'BcBlog', - 'controller' => 'Blog', - 'action' => 'archives', - 'entityId' => 31, - 1 - ])); - - // 管理画面のプラグイン用ルーティング - $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']); - - // サブサイトのプラグイン用ルーティング - Router::reload(); - $routes = Router::createRouteBuilder(''); - $_SERVER['REQUEST_URI'] = '/s/'; - $this->BcPlugin->clearCurrentSite(); - $this->BcPlugin->routes($routes); - $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/index')); - $this->assertEquals('BlogContents', $result['controller']); - $this->assertEquals('s', $result['sitePrefix']); - $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/edit/1')); - $this->assertEquals('BlogContents', $result['controller']); - $this->assertEquals('s', $result['sitePrefix']); - - // 管理画面のプラグイン用ルーティング - $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/index.json')); - $this->assertEquals('BlogContents', $result['controller']); - $this->assertEquals('json', $result['_ext']); - $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/edit/1.json')); - $this->assertEquals('BlogContents', $result['controller']); - $this->assertEquals('json', $result['_ext']); - unset($_SERVER['REQUEST_URI']); - $this->BcPlugin->clearCurrentSite(); - } - - /** - * test getUpdateScriptMessages And getUpdaters - */ - public function test_getUpdateScriptMessagesAndGetUpdaters() - { - $name = 'Sample'; - $pluginPath = ROOT . DS . 'plugins' . DS . $name . DS; - $updatePath = $pluginPath . 'config' . DS . 'update' . DS; - PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); - $folder = new BcFolder($pluginPath); - - // 新バージョン - $folder->create(); - $file = new BcFile($pluginPath . 'VERSION.txt'); - $file->create(); - $file->write('1.0.3'); - // アップデートスクリプト 0.0.1 - $folder = new BcFolder($updatePath . '0.0.1'); - $folder->create(); - $file = new BcFile($updatePath . '0.0.1' . DS . 'config.php'); - $file->create(); - $file->write(' \'test0\'];'); - // アップデートスクリプト 1.0.1 - $folder = new BcFolder($updatePath . '1.0.1'); - $folder->create(); - $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); - $file->create(); - $file->write(' \'test1\'];'); - $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); - $file->create(); - // アップデートスクリプト 1.0.2 - $folder = new BcFolder($updatePath . '1.0.2'); - $folder->create(); - $file = new BcFile($updatePath . '1.0.2' . DS . 'config.php'); - $file->create(); - $file->write(' \'test2\'];'); - $file = new BcFile($updatePath . '1.0.2' . DS . 'updater.php'); - $file->create(); - // アップデートスクリプト 1.0.4 - $folder = new BcFolder($updatePath . '1.0.4'); - $folder->create(); - $file = new BcFile($updatePath . '1.0.4' . DS . 'config.php'); - $file->create(); - $file->write(' \'test3\'];'); - - $this->assertEquals( - ['Sample-1.0.1' => 'test1', 'Sample-1.0.2' => 'test2'], - $this->BcPlugin->getUpdateScriptMessages($name) - ); - $this->assertEquals( - ['Sample-1.0.1' => 1000001000, 'Sample-1.0.2' => 1000002000], - $this->BcPlugin->getUpdaters($name) - ); - $folder = new BcFolder($pluginPath); - $folder->delete(); - } - - /** - * test getUpdateScriptMessages And getUpdaters On Update Tmp - */ - public function test_getUpdateScriptMessagesAndGetUpdatersOnUpdateTmp() - { - $name = 'Sample'; - $pluginPath = TMP . 'update' . DS . 'vendor' . DS . 'baserproject' . DS . $name . DS; - $updatePath = $pluginPath . 'config' . DS . 'update' . DS; - PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); - - // 新バージョン - (new BcFolder($pluginPath))->create(); - $file = new BcFile($pluginPath . 'VERSION.txt'); - $file->write('1.0.3'); - // アップデートスクリプト 1.0.1 - (new BcFolder($updatePath . '1.0.1'))->create(); - $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); - $file->write(' \'test1\'];'); - $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); - $file->create(); - - $this->assertEquals( - ['Sample-1.0.1' => 'test1'], - $this->BcPlugin->getUpdateScriptMessages($name, true) - ); - $this->assertEquals( - ['Sample-1.0.1' => 1000001000], - $this->BcPlugin->getUpdaters($name, true) - ); - (new BcFolder(TMP . 'update'))->delete(); - } - - /** - * test execScript - */ - public function test_execScript() - { - $this->truncateTable('users'); - $version = '1.0.0'; - $updatePath = Plugin::path('BcBlog') . 'config' . DS . 'update'; - $versionPath = $updatePath . DS . $version; - // スクリプトなし - if(file_exists($versionPath . DS . 'updater.php')) { - unlink($versionPath . DS . 'updater.php'); - } - $this->assertTrue($this->BcPlugin->execScript($version)); - // 有効スクリプトあり - UserFactory::make(['id' => 1, 'name' => 'test'])->persist(); - $folder = new BcFolder($versionPath); - $folder->create(); - $file = new BcFile($versionPath . DS . 'updater.php'); - $file->create(); - $file->write('get(\'BaserCore.Users\'); -$user = $users->find()->where([\'id\' => 1])->first(); -$user->name = \'hoge\'; -$users->save($user);'); - $this->BcPlugin->execScript($version); - $users = $this->getTableLocator()->get('BaserCore.Users'); - $user = $users->find()->where(['id' => 1])->first(); - $this->assertEquals('hoge', $user->name); - // 無効スクリプトあり - $file = new BcFile($versionPath . DS . 'updater.php'); - $file->create(); - $file->write('log(\'test\');'); - $this->BcPlugin->execScript($version); - $file = new BcFile(LOGS . 'cli-error.log'); - $log = $file->read(); - $this->assertStringContainsString('test', $log); - // 初期化 - $folder->delete($updatePath); - } - - /** - * test createAssetsSymlink - */ - public function test_createAssetsSymlink() - { - unlink(WWW_ROOT . 'baser_core'); - $this->BcPlugin->createAssetsSymlink(); - $this->assertTrue(file_exists(WWW_ROOT . 'baser_core')); - } - - /** - * test migrate - */ - public function test_migrate() - { - $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; - $folder = new BcFolder($pluginPath); - - // プラグインフォルダを初期化 - $folder->delete(); - $configPath = $pluginPath . 'config' . DS; - $migrationPath = $configPath . 'Migrations' . DS; - $seedPath = $configPath . 'Seeds' . DS; - $srcPath = $pluginPath . 'src' . DS; - $folder = new BcFolder($srcPath); - $folder->create(); - $folder = new BcFolder($migrationPath); - $folder->create(); - $folder = new BcFolder($seedPath); - $folder->create(); - - // VERSION.txt - $this->createVersionFile($pluginPath, '0.0.1'); - - // src/Plugin.php - $this->createPluginFile($srcPath); - - // config/Migrations/20220626000000_InitialBcTest.php - $this->createInitialMigrationFile($migrationPath); - - // インストール実行 - $plugin = new BcPlugin(['name' => 'BcTest']); - $plugin->install(['connection' => 'test']); - $db = ConnectionManager::get('test'); - $collection = $db->getSchemaCollection(); - $tableSchema = $collection->describe('bc_test'); - $this->assertEquals('string', $tableSchema->getColumnType('name')); - - // config/Migrations/20220627000000_AlterBcTest.php - $this->createAlterMigrationFile($migrationPath); - - // アップデート実行 - // インストールで利用した BcPluginを使い回すと、マイグレーションのキャッシュが残っていて、 - // 新しいマイグレーションファイルを認識しないので初期化しなおす - $plugin = new BcPlugin(['name' => 'BcTest']); - $plugin->migrate(['connection' => 'test']); - $tableSchema = $collection->describe('bc_test'); - $this->assertEquals('datetime', $tableSchema->getColumnType('name')); - - // 初期化 - $folder->delete($pluginPath); - $this->dropTable('bc_test'); - $this->dropTable('bc_test_phinxlog'); - } - - /** - * プラグインファイルを作成する - * - * @param $srcPath - */ - public function createPluginFile($srcPath) - { - $file = new BcFile($srcPath . 'Plugin.php'); - $file->create(); - $file->write('create(); - $file->write('table(\'bc_test\'); - $table->changeColumn(\'name\', \'datetime\'); - $table->update(); - } -}'); - } - - /** - * 初期化用のマイグレーションファイルを作成する - * - * @param $migrationPath - */ - public function createInitialMigrationFile($migrationPath) - { - $file = new BcFile($migrationPath . '20220626000000_InitialBcTest.php', 'w'); - $file->create(); - $file->write('table(\'bc_test\') - ->addColumn(\'name\', \'string\', [ - \'default\' => null, - \'limit\' => 255, - \'null\' => true, - ]) - ->create(); - } - public function down() - { - $this->table(\'bc_test\')->drop()->save(); - } -}'); - } - - /** - * バージョンファイルを作成する - * - * @param $pluginPath - * @param $version - */ - public function createVersionFile($pluginPath, $version) - { - $file = new BcFile($pluginPath . 'VERSION.txt'); - $file->create(); - $file->write($version); - } - - /** - * アップデーターを作成する - * - * @param $updaterPath - */ - public function createUpdater($updaterPath) - { - $file = new BcFile($updaterPath . 'updater.php', 'w'); - $file->create(); - $file->write('get(\'BcTest.BcTest\'); -$table->save(new Entity([\'name\' => \'2022-06-26\']));'); - } - - /** - * test execUpdater - */ - public function test_execUpdater() - { - $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; - $folder = new BcFolder($pluginPath); - - // プラグインフォルダを初期化 - $folder->delete(); - $configPath = $pluginPath . 'config' . DS; - $migrationPath = $configPath . 'Migrations' . DS; - $seedPath = $configPath . 'Seeds' . DS; - $srcPath = $pluginPath . 'src' . DS; - $folder = new BcFolder($srcPath); - $folder->create(); - $folder = new BcFolder($migrationPath); - $folder->create(); - $folder = new BcFolder($seedPath); - $folder->create(); - - // VERSION.txt - $this->createVersionFile($pluginPath, '0.0.1'); - - // config/Migrations/20220626000000_InitialBcTest.php - $this->createInitialMigrationFile($migrationPath); - - // src/Plugin.php - $this->createPluginFile($srcPath); - - // インストール実行 - $plugin = new BcPlugin(['name' => 'BcTest']); - $plugin->install(['connection' => 'test']); - - // VERSION.txt - $this->createVersionFile($pluginPath, '0.0.2'); - - // config/update/0.0.2/updater.php - $updaterPath = $configPath . 'update' . DS . '0.0.2' . DS; - $folder = new BcFolder($updaterPath); - $folder->create(); - $this->createUpdater($updaterPath); - - // アップデート実行 - $plugin->execUpdater(); - $table = $this->getTableLocator()->get('BcTest.BcTest'); - $entity = $table->find()->first(); - $this->assertEquals('2022-06-26', (string) $entity->name); - - // 初期化 - $folder = new BcFolder($pluginPath); - $folder->delete(); - $this->dropTable('bc_test'); - $this->dropTable('bc_test_phinxlog'); - } - - /** - * テーマを適用する - */ - public function test_applyAsTheme() - { - $targetId = 1; - $currentTheme = 'BcFront'; - $SiteService = new SitesService(); - $site = $SiteService->get($targetId); - $this->assertEquals($currentTheme, $site->theme); - - $updateTheme = 'BcPluginSample'; - $this->BcPlugin->applyAsTheme($site, $updateTheme); - $site = $SiteService->get($targetId); - $this->assertEquals($updateTheme, $site->theme); - } - - /** - * test Rest API - */ - public function testRestApi() - { - Router::resetRoutes(); - // 件数確認 - PermissionFactory::make()->allowGuest('/baser/api/*')->persist(); - $this->get('/baser/api/baser-core/pages.json'); - $result = json_decode((string)$this->_response->getBody()); - $this->assertEquals(0, count($result->pages)); - - // 一件追加 - $token = $this->apiLoginAdmin(); - $this->post('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'], [ - 'content' => [ - 'parent_id' => 1, - 'title' => 'sample', - 'plugin' => 'BaserCore', - 'type' => 'Page', - 'site_id' => 1, - 'alias_id' => '', - 'entity_id' => '', - ], - 'contents' => '', - 'draft' => '', - 'page_template' => '', - 'code' => '' - ]); - $result = json_decode((string)$this->_response->getBody()); - $id = $result->page->id; - - // 件数確認(認証済) - $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); - $result = json_decode((string)$this->_response->getBody()); - $this->assertEquals(1, count($result->pages)); - - // 変更(公開状態に変更) - $this->put('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token'], [ - 'content' => [ - 'self_status' => 1 - ] - ]); - - // 件数確認(認証なし) - $this->get('/baser/api/baser-core/pages.json'); - $result = json_decode((string)$this->_response->getBody()); - $this->assertEquals(1, count($result->pages)); - - // 削除 - $this->delete('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token']); - - // 件数確認(認証済) - $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); - $result = json_decode((string)$this->_response->getBody()); - $this->assertEquals(0, count($result->pages)); - } - -} +///** +// * baserCMS : Based Website Development Project +// * 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 BaserCore\Test\TestCase; +// +//use BaserCore\BcPlugin; +//use BaserCore\Service\SitesService; +//use BaserCore\Test\Factory\PermissionFactory; +//use BaserCore\Test\Factory\PluginFactory; +//use BaserCore\Test\Factory\UserFactory; +//use BaserCore\Test\Scenario\ContentFoldersScenario; +//use BaserCore\Test\Scenario\ContentsScenario; +//use BaserCore\Test\Scenario\PluginsScenario; +//use BaserCore\Test\Scenario\SiteConfigsScenario; +//use BaserCore\Test\Scenario\SitesScenario; +//use BaserCore\Test\Scenario\UserGroupsScenario; +//use BaserCore\Test\Scenario\UserScenario; +//use BaserCore\Test\Scenario\UsersUserGroupsScenario; +//use BaserCore\TestSuite\BcTestCase; +//use BaserCore\Utility\BcFile; +//use BaserCore\Utility\BcFolder; +//use BaserCore\Utility\BcUtil; +//use Cake\Core\Plugin; +//use Cake\Datasource\ConnectionManager; +//use Cake\ORM\TableRegistry; +//use Cake\Routing\Router; +//use Cake\TestSuite\IntegrationTestTrait; +//use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; +// +///** +// * Class BcPluginTest +// */ +//class BcPluginTest extends BcTestCase +//{ +// +// use ScenarioAwareTrait; +// +// /** +// * @var BcPlugin +// */ +// public $BcPlugin; +// +// /** +// * Set Up +// * +// * @return void +// */ +// public function setUp(): void +// { +// parent::setUp(); +// $this->loadFixtureScenario(UserScenario::class); +// $this->loadFixtureScenario(UserGroupsScenario::class); +// $this->loadFixtureScenario(UsersUserGroupsScenario::class); +// $this->loadFixtureScenario(ContentsScenario::class); +// $this->loadFixtureScenario(SitesScenario::class); +// $this->loadFixtureScenario(SiteConfigsScenario::class); +// $this->loadFixtureScenario(ContentFoldersScenario::class); +// $this->loadFixtureScenario(PluginsScenario::class); +// $this->BcPlugin = new BcPlugin(['name' => 'BcBlog']); +// } +// +// /** +// * Tear Down +// * +// * @return void +// */ +// public function tearDown(): void +// { +// unset($this->BcPlugin); +// parent::tearDown(); +// } +// +// /** +// * testInitialize +// */ +// public function testInitialize() +// { +// $this->assertNotEmpty($this->BcPlugin->migrations); +// } +// +// /** +// * testInstall +// */ +// public function testInstallAndUninstall() +// { +// $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); +// // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 +// +// // インストール +// $this->BcPlugin->install(['connection' => 'test']); +// $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); +// $this->assertEquals(1, $plugins->priority); +// +// // アンインストール +// $from = BcUtil::getPluginPath('BcBlog'); +// $pluginDir = dirname($from); +// $folder = new BcFolder($from); +// $to = $pluginDir . DS . 'BcBlogBak'; +// $folder->copy($to); +// $folder->create(); +// $this->BcPlugin->uninstall(['connection' => 'test']); +// $this->assertFalse(is_dir($from)); +// $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); +// $this->assertNull($plugins); +// $folder->move( $to); +// $this->BcPlugin->install(['connection' => 'test']); +// } +// +// /** +// * testRollback +// */ +// public function testRollback() +// { +// $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); +// // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 +// +// $this->BcPlugin->install(['connection' => 'test']); +// $this->BcPlugin->rollbackDb(['connection' => 'test']); +// $collection = ConnectionManager::get('default')->getSchemaCollection(); +// $tables = $collection->listTables(); +// $this->assertNotContains('blog_posts', $tables); +// $plugins = $this->getTableLocator()->get('BaserCore.Plugins'); +// $plugins->deleteAll(['name' => 'BcBlog']); +// $this->BcPlugin->install(['connection' => 'test']); +// } +// +// /** +// * testRoutes +// */ +// public function testRoutes() +// { +// $routes = Router::createRouteBuilder('/'); +// $this->BcPlugin->routes($routes); +// +// // コンテンツ管理のプラグイン用のリバースルーティング +// $this->getRequest('/'); +// $this->assertEquals('/news/', Router::url([ +// 'plugin' => 'BcBlog', +// 'controller' => 'Blog', +// 'action' => 'index', +// 'entityId' => 31 +// ])); +// $this->assertEquals('/news/archives/1', Router::url([ +// 'plugin' => 'BcBlog', +// 'controller' => 'Blog', +// 'action' => 'archives', +// 'entityId' => 31, +// 1 +// ])); +// +// // 管理画面のプラグイン用ルーティング +// $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']); +// +// // サブサイトのプラグイン用ルーティング +// Router::reload(); +// $routes = Router::createRouteBuilder(''); +// $_SERVER['REQUEST_URI'] = '/s/'; +// $this->BcPlugin->clearCurrentSite(); +// $this->BcPlugin->routes($routes); +// $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/index')); +// $this->assertEquals('BlogContents', $result['controller']); +// $this->assertEquals('s', $result['sitePrefix']); +// $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/edit/1')); +// $this->assertEquals('BlogContents', $result['controller']); +// $this->assertEquals('s', $result['sitePrefix']); +// +// // 管理画面のプラグイン用ルーティング +// $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/index.json')); +// $this->assertEquals('BlogContents', $result['controller']); +// $this->assertEquals('json', $result['_ext']); +// $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/edit/1.json')); +// $this->assertEquals('BlogContents', $result['controller']); +// $this->assertEquals('json', $result['_ext']); +// unset($_SERVER['REQUEST_URI']); +// $this->BcPlugin->clearCurrentSite(); +// } +// +// /** +// * test getUpdateScriptMessages And getUpdaters +// */ +// public function test_getUpdateScriptMessagesAndGetUpdaters() +// { +// $name = 'Sample'; +// $pluginPath = ROOT . DS . 'plugins' . DS . $name . DS; +// $updatePath = $pluginPath . 'config' . DS . 'update' . DS; +// PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); +// $folder = new BcFolder($pluginPath); +// +// // 新バージョン +// $folder->create(); +// $file = new BcFile($pluginPath . 'VERSION.txt'); +// $file->create(); +// $file->write('1.0.3'); +// // アップデートスクリプト 0.0.1 +// $folder = new BcFolder($updatePath . '0.0.1'); +// $folder->create(); +// $file = new BcFile($updatePath . '0.0.1' . DS . 'config.php'); +// $file->create(); +// $file->write(' \'test0\'];'); +// // アップデートスクリプト 1.0.1 +// $folder = new BcFolder($updatePath . '1.0.1'); +// $folder->create(); +// $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); +// $file->create(); +// $file->write(' \'test1\'];'); +// $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); +// $file->create(); +// // アップデートスクリプト 1.0.2 +// $folder = new BcFolder($updatePath . '1.0.2'); +// $folder->create(); +// $file = new BcFile($updatePath . '1.0.2' . DS . 'config.php'); +// $file->create(); +// $file->write(' \'test2\'];'); +// $file = new BcFile($updatePath . '1.0.2' . DS . 'updater.php'); +// $file->create(); +// // アップデートスクリプト 1.0.4 +// $folder = new BcFolder($updatePath . '1.0.4'); +// $folder->create(); +// $file = new BcFile($updatePath . '1.0.4' . DS . 'config.php'); +// $file->create(); +// $file->write(' \'test3\'];'); +// +// $this->assertEquals( +// ['Sample-1.0.1' => 'test1', 'Sample-1.0.2' => 'test2'], +// $this->BcPlugin->getUpdateScriptMessages($name) +// ); +// $this->assertEquals( +// ['Sample-1.0.1' => 1000001000, 'Sample-1.0.2' => 1000002000], +// $this->BcPlugin->getUpdaters($name) +// ); +// $folder = new BcFolder($pluginPath); +// $folder->delete(); +// } +// +// /** +// * test getUpdateScriptMessages And getUpdaters On Update Tmp +// */ +// public function test_getUpdateScriptMessagesAndGetUpdatersOnUpdateTmp() +// { +// $name = 'Sample'; +// $pluginPath = TMP . 'update' . DS . 'vendor' . DS . 'baserproject' . DS . $name . DS; +// $updatePath = $pluginPath . 'config' . DS . 'update' . DS; +// PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); +// +// // 新バージョン +// (new BcFolder($pluginPath))->create(); +// $file = new BcFile($pluginPath . 'VERSION.txt'); +// $file->write('1.0.3'); +// // アップデートスクリプト 1.0.1 +// (new BcFolder($updatePath . '1.0.1'))->create(); +// $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); +// $file->write(' \'test1\'];'); +// $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); +// $file->create(); +// +// $this->assertEquals( +// ['Sample-1.0.1' => 'test1'], +// $this->BcPlugin->getUpdateScriptMessages($name, true) +// ); +// $this->assertEquals( +// ['Sample-1.0.1' => 1000001000], +// $this->BcPlugin->getUpdaters($name, true) +// ); +// (new BcFolder(TMP . 'update'))->delete(); +// } +// +// /** +// * test execScript +// */ +// public function test_execScript() +// { +// $this->truncateTable('users'); +// $version = '1.0.0'; +// $updatePath = Plugin::path('BcBlog') . 'config' . DS . 'update'; +// $versionPath = $updatePath . DS . $version; +// // スクリプトなし +// if(file_exists($versionPath . DS . 'updater.php')) { +// unlink($versionPath . DS . 'updater.php'); +// } +// $this->assertTrue($this->BcPlugin->execScript($version)); +// // 有効スクリプトあり +// UserFactory::make(['id' => 1, 'name' => 'test'])->persist(); +// $folder = new BcFolder($versionPath); +// $folder->create(); +// $file = new BcFile($versionPath . DS . 'updater.php'); +// $file->create(); +// $file->write('get(\'BaserCore.Users\'); +//$user = $users->find()->where([\'id\' => 1])->first(); +//$user->name = \'hoge\'; +//$users->save($user);'); +// $this->BcPlugin->execScript($version); +// $users = $this->getTableLocator()->get('BaserCore.Users'); +// $user = $users->find()->where(['id' => 1])->first(); +// $this->assertEquals('hoge', $user->name); +// // 無効スクリプトあり +// $file = new BcFile($versionPath . DS . 'updater.php'); +// $file->create(); +// $file->write('log(\'test\');'); +// $this->BcPlugin->execScript($version); +// $file = new BcFile(LOGS . 'cli-error.log'); +// $log = $file->read(); +// $this->assertStringContainsString('test', $log); +// // 初期化 +// $folder->delete($updatePath); +// } +// +// /** +// * test createAssetsSymlink +// */ +// public function test_createAssetsSymlink() +// { +// unlink(WWW_ROOT . 'baser_core'); +// $this->BcPlugin->createAssetsSymlink(); +// $this->assertTrue(file_exists(WWW_ROOT . 'baser_core')); +// } +// +// /** +// * test migrate +// */ +// public function test_migrate() +// { +// $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; +// $folder = new BcFolder($pluginPath); +// +// // プラグインフォルダを初期化 +// $folder->delete(); +// $configPath = $pluginPath . 'config' . DS; +// $migrationPath = $configPath . 'Migrations' . DS; +// $seedPath = $configPath . 'Seeds' . DS; +// $srcPath = $pluginPath . 'src' . DS; +// $folder = new BcFolder($srcPath); +// $folder->create(); +// $folder = new BcFolder($migrationPath); +// $folder->create(); +// $folder = new BcFolder($seedPath); +// $folder->create(); +// +// // VERSION.txt +// $this->createVersionFile($pluginPath, '0.0.1'); +// +// // src/Plugin.php +// $this->createPluginFile($srcPath); +// +// // config/Migrations/20220626000000_InitialBcTest.php +// $this->createInitialMigrationFile($migrationPath); +// +// // インストール実行 +// $plugin = new BcPlugin(['name' => 'BcTest']); +// $plugin->install(['connection' => 'test']); +// $db = ConnectionManager::get('test'); +// $collection = $db->getSchemaCollection(); +// $tableSchema = $collection->describe('bc_test'); +// $this->assertEquals('string', $tableSchema->getColumnType('name')); +// +// // config/Migrations/20220627000000_AlterBcTest.php +// $this->createAlterMigrationFile($migrationPath); +// +// // アップデート実行 +// // インストールで利用した BcPluginを使い回すと、マイグレーションのキャッシュが残っていて、 +// // 新しいマイグレーションファイルを認識しないので初期化しなおす +// $plugin = new BcPlugin(['name' => 'BcTest']); +// $plugin->migrate(['connection' => 'test']); +// $tableSchema = $collection->describe('bc_test'); +// $this->assertEquals('datetime', $tableSchema->getColumnType('name')); +// +// // 初期化 +// $folder->delete($pluginPath); +// $this->dropTable('bc_test'); +// $this->dropTable('bc_test_phinxlog'); +// } +// +// /** +// * プラグインファイルを作成する +// * +// * @param $srcPath +// */ +// public function createPluginFile($srcPath) +// { +// $file = new BcFile($srcPath . 'Plugin.php'); +// $file->create(); +// $file->write('create(); +// $file->write('table(\'bc_test\'); +// $table->changeColumn(\'name\', \'datetime\'); +// $table->update(); +// } +//}'); +// } +// +// /** +// * 初期化用のマイグレーションファイルを作成する +// * +// * @param $migrationPath +// */ +// public function createInitialMigrationFile($migrationPath) +// { +// $file = new BcFile($migrationPath . '20220626000000_InitialBcTest.php', 'w'); +// $file->create(); +// $file->write('table(\'bc_test\') +// ->addColumn(\'name\', \'string\', [ +// \'default\' => null, +// \'limit\' => 255, +// \'null\' => true, +// ]) +// ->create(); +// } +// public function down() +// { +// $this->table(\'bc_test\')->drop()->save(); +// } +//}'); +// } +// +// /** +// * バージョンファイルを作成する +// * +// * @param $pluginPath +// * @param $version +// */ +// public function createVersionFile($pluginPath, $version) +// { +// $file = new BcFile($pluginPath . 'VERSION.txt'); +// $file->create(); +// $file->write($version); +// } +// +// /** +// * アップデーターを作成する +// * +// * @param $updaterPath +// */ +// public function createUpdater($updaterPath) +// { +// $file = new BcFile($updaterPath . 'updater.php', 'w'); +// $file->create(); +// $file->write('get(\'BcTest.BcTest\'); +//$table->save(new Entity([\'name\' => \'2022-06-26\']));'); +// } +// +// /** +// * test execUpdater +// */ +// public function test_execUpdater() +// { +// $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; +// $folder = new BcFolder($pluginPath); +// +// // プラグインフォルダを初期化 +// $folder->delete(); +// $configPath = $pluginPath . 'config' . DS; +// $migrationPath = $configPath . 'Migrations' . DS; +// $seedPath = $configPath . 'Seeds' . DS; +// $srcPath = $pluginPath . 'src' . DS; +// $folder = new BcFolder($srcPath); +// $folder->create(); +// $folder = new BcFolder($migrationPath); +// $folder->create(); +// $folder = new BcFolder($seedPath); +// $folder->create(); +// +// // VERSION.txt +// $this->createVersionFile($pluginPath, '0.0.1'); +// +// // config/Migrations/20220626000000_InitialBcTest.php +// $this->createInitialMigrationFile($migrationPath); +// +// // src/Plugin.php +// $this->createPluginFile($srcPath); +// +// // インストール実行 +// $plugin = new BcPlugin(['name' => 'BcTest']); +// $plugin->install(['connection' => 'test']); +// +// // VERSION.txt +// $this->createVersionFile($pluginPath, '0.0.2'); +// +// // config/update/0.0.2/updater.php +// $updaterPath = $configPath . 'update' . DS . '0.0.2' . DS; +// $folder = new BcFolder($updaterPath); +// $folder->create(); +// $this->createUpdater($updaterPath); +// +// // アップデート実行 +// $plugin->execUpdater(); +// $table = $this->getTableLocator()->get('BcTest.BcTest'); +// $entity = $table->find()->first(); +// $this->assertEquals('2022-06-26', (string) $entity->name); +// +// // 初期化 +// $folder = new BcFolder($pluginPath); +// $folder->delete(); +// $this->dropTable('bc_test'); +// $this->dropTable('bc_test_phinxlog'); +// } +// +// /** +// * テーマを適用する +// */ +// public function test_applyAsTheme() +// { +// $targetId = 1; +// $currentTheme = 'BcFront'; +// $SiteService = new SitesService(); +// $site = $SiteService->get($targetId); +// $this->assertEquals($currentTheme, $site->theme); +// +// $updateTheme = 'BcPluginSample'; +// $this->BcPlugin->applyAsTheme($site, $updateTheme); +// $site = $SiteService->get($targetId); +// $this->assertEquals($updateTheme, $site->theme); +// } +// +// /** +// * test Rest API +// */ +// public function testRestApi() +// { +// Router::resetRoutes(); +// // 件数確認 +// PermissionFactory::make()->allowGuest('/baser/api/*')->persist(); +// $this->get('/baser/api/baser-core/pages.json'); +// $result = json_decode((string)$this->_response->getBody()); +// $this->assertEquals(0, count($result->pages)); +// +// // 一件追加 +// $token = $this->apiLoginAdmin(); +// $this->post('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'], [ +// 'content' => [ +// 'parent_id' => 1, +// 'title' => 'sample', +// 'plugin' => 'BaserCore', +// 'type' => 'Page', +// 'site_id' => 1, +// 'alias_id' => '', +// 'entity_id' => '', +// ], +// 'contents' => '', +// 'draft' => '', +// 'page_template' => '', +// 'code' => '' +// ]); +// $result = json_decode((string)$this->_response->getBody()); +// $id = $result->page->id; +// +// // 件数確認(認証済) +// $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); +// $result = json_decode((string)$this->_response->getBody()); +// $this->assertEquals(1, count($result->pages)); +// +// // 変更(公開状態に変更) +// $this->put('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token'], [ +// 'content' => [ +// 'self_status' => 1 +// ] +// ]); +// +// // 件数確認(認証なし) +// $this->get('/baser/api/baser-core/pages.json'); +// $result = json_decode((string)$this->_response->getBody()); +// $this->assertEquals(1, count($result->pages)); +// +// // 削除 +// $this->delete('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token']); +// +// // 件数確認(認証済) +// $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); +// $result = json_decode((string)$this->_response->getBody()); +// $this->assertEquals(0, count($result->pages)); +// } +// +//} From 66394e43c297df8e90509faf6a41eaba79ca7c8f Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Fri, 15 Nov 2024 12:46:04 +0900 Subject: [PATCH 6/8] =?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 --- .../tests/TestCase/BcPluginTest.php | 1236 ++++++++--------- .../Model/Table/CustomEntriesTableTest.php | 2 +- .../Service/CustomEntriesServiceTest.php | 4 +- .../Utility/CustomContentUtilTest.php | 2 +- .../Helper/CustomContentAppHelperTest.php | 1 + 5 files changed, 623 insertions(+), 622 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/BcPluginTest.php b/plugins/baser-core/tests/TestCase/BcPluginTest.php index 23c23bb5a0..9d80842121 100644 --- a/plugins/baser-core/tests/TestCase/BcPluginTest.php +++ b/plugins/baser-core/tests/TestCase/BcPluginTest.php @@ -1,619 +1,619 @@ -// * 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 BaserCore\Test\TestCase; -// -//use BaserCore\BcPlugin; -//use BaserCore\Service\SitesService; -//use BaserCore\Test\Factory\PermissionFactory; -//use BaserCore\Test\Factory\PluginFactory; -//use BaserCore\Test\Factory\UserFactory; -//use BaserCore\Test\Scenario\ContentFoldersScenario; -//use BaserCore\Test\Scenario\ContentsScenario; -//use BaserCore\Test\Scenario\PluginsScenario; -//use BaserCore\Test\Scenario\SiteConfigsScenario; -//use BaserCore\Test\Scenario\SitesScenario; -//use BaserCore\Test\Scenario\UserGroupsScenario; -//use BaserCore\Test\Scenario\UserScenario; -//use BaserCore\Test\Scenario\UsersUserGroupsScenario; -//use BaserCore\TestSuite\BcTestCase; -//use BaserCore\Utility\BcFile; -//use BaserCore\Utility\BcFolder; -//use BaserCore\Utility\BcUtil; -//use Cake\Core\Plugin; -//use Cake\Datasource\ConnectionManager; -//use Cake\ORM\TableRegistry; -//use Cake\Routing\Router; -//use Cake\TestSuite\IntegrationTestTrait; -//use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; -// -///** -// * Class BcPluginTest -// */ -//class BcPluginTest extends BcTestCase -//{ -// -// use ScenarioAwareTrait; -// -// /** -// * @var BcPlugin -// */ -// public $BcPlugin; -// -// /** -// * Set Up -// * -// * @return void -// */ -// public function setUp(): void -// { -// parent::setUp(); -// $this->loadFixtureScenario(UserScenario::class); -// $this->loadFixtureScenario(UserGroupsScenario::class); -// $this->loadFixtureScenario(UsersUserGroupsScenario::class); -// $this->loadFixtureScenario(ContentsScenario::class); -// $this->loadFixtureScenario(SitesScenario::class); -// $this->loadFixtureScenario(SiteConfigsScenario::class); -// $this->loadFixtureScenario(ContentFoldersScenario::class); -// $this->loadFixtureScenario(PluginsScenario::class); -// $this->BcPlugin = new BcPlugin(['name' => 'BcBlog']); -// } -// -// /** -// * Tear Down -// * -// * @return void -// */ -// public function tearDown(): void -// { -// unset($this->BcPlugin); -// parent::tearDown(); -// } -// -// /** -// * testInitialize -// */ -// public function testInitialize() -// { -// $this->assertNotEmpty($this->BcPlugin->migrations); -// } -// -// /** -// * testInstall -// */ -// public function testInstallAndUninstall() -// { -// $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); -// // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 -// -// // インストール -// $this->BcPlugin->install(['connection' => 'test']); -// $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); -// $this->assertEquals(1, $plugins->priority); -// -// // アンインストール -// $from = BcUtil::getPluginPath('BcBlog'); -// $pluginDir = dirname($from); -// $folder = new BcFolder($from); -// $to = $pluginDir . DS . 'BcBlogBak'; -// $folder->copy($to); -// $folder->create(); -// $this->BcPlugin->uninstall(['connection' => 'test']); -// $this->assertFalse(is_dir($from)); -// $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); -// $this->assertNull($plugins); -// $folder->move( $to); -// $this->BcPlugin->install(['connection' => 'test']); -// } -// -// /** -// * testRollback -// */ -// public function testRollback() -// { -// $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); -// // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 -// -// $this->BcPlugin->install(['connection' => 'test']); -// $this->BcPlugin->rollbackDb(['connection' => 'test']); -// $collection = ConnectionManager::get('default')->getSchemaCollection(); -// $tables = $collection->listTables(); -// $this->assertNotContains('blog_posts', $tables); -// $plugins = $this->getTableLocator()->get('BaserCore.Plugins'); -// $plugins->deleteAll(['name' => 'BcBlog']); -// $this->BcPlugin->install(['connection' => 'test']); -// } -// -// /** -// * testRoutes -// */ -// public function testRoutes() -// { -// $routes = Router::createRouteBuilder('/'); -// $this->BcPlugin->routes($routes); -// -// // コンテンツ管理のプラグイン用のリバースルーティング -// $this->getRequest('/'); -// $this->assertEquals('/news/', Router::url([ -// 'plugin' => 'BcBlog', -// 'controller' => 'Blog', -// 'action' => 'index', -// 'entityId' => 31 -// ])); -// $this->assertEquals('/news/archives/1', Router::url([ -// 'plugin' => 'BcBlog', -// 'controller' => 'Blog', -// 'action' => 'archives', -// 'entityId' => 31, -// 1 -// ])); -// -// // 管理画面のプラグイン用ルーティング -// $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']); -// -// // サブサイトのプラグイン用ルーティング -// Router::reload(); -// $routes = Router::createRouteBuilder(''); -// $_SERVER['REQUEST_URI'] = '/s/'; -// $this->BcPlugin->clearCurrentSite(); -// $this->BcPlugin->routes($routes); -// $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/index')); -// $this->assertEquals('BlogContents', $result['controller']); -// $this->assertEquals('s', $result['sitePrefix']); -// $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/edit/1')); -// $this->assertEquals('BlogContents', $result['controller']); -// $this->assertEquals('s', $result['sitePrefix']); -// -// // 管理画面のプラグイン用ルーティング -// $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/index.json')); -// $this->assertEquals('BlogContents', $result['controller']); -// $this->assertEquals('json', $result['_ext']); -// $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/edit/1.json')); -// $this->assertEquals('BlogContents', $result['controller']); -// $this->assertEquals('json', $result['_ext']); -// unset($_SERVER['REQUEST_URI']); -// $this->BcPlugin->clearCurrentSite(); -// } -// -// /** -// * test getUpdateScriptMessages And getUpdaters -// */ -// public function test_getUpdateScriptMessagesAndGetUpdaters() -// { -// $name = 'Sample'; -// $pluginPath = ROOT . DS . 'plugins' . DS . $name . DS; -// $updatePath = $pluginPath . 'config' . DS . 'update' . DS; -// PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); -// $folder = new BcFolder($pluginPath); -// -// // 新バージョン -// $folder->create(); -// $file = new BcFile($pluginPath . 'VERSION.txt'); -// $file->create(); -// $file->write('1.0.3'); -// // アップデートスクリプト 0.0.1 -// $folder = new BcFolder($updatePath . '0.0.1'); -// $folder->create(); -// $file = new BcFile($updatePath . '0.0.1' . DS . 'config.php'); -// $file->create(); -// $file->write(' \'test0\'];'); -// // アップデートスクリプト 1.0.1 -// $folder = new BcFolder($updatePath . '1.0.1'); -// $folder->create(); -// $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); -// $file->create(); -// $file->write(' \'test1\'];'); -// $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); -// $file->create(); -// // アップデートスクリプト 1.0.2 -// $folder = new BcFolder($updatePath . '1.0.2'); -// $folder->create(); -// $file = new BcFile($updatePath . '1.0.2' . DS . 'config.php'); -// $file->create(); -// $file->write(' \'test2\'];'); -// $file = new BcFile($updatePath . '1.0.2' . DS . 'updater.php'); -// $file->create(); -// // アップデートスクリプト 1.0.4 -// $folder = new BcFolder($updatePath . '1.0.4'); -// $folder->create(); -// $file = new BcFile($updatePath . '1.0.4' . DS . 'config.php'); -// $file->create(); -// $file->write(' \'test3\'];'); -// -// $this->assertEquals( -// ['Sample-1.0.1' => 'test1', 'Sample-1.0.2' => 'test2'], -// $this->BcPlugin->getUpdateScriptMessages($name) -// ); -// $this->assertEquals( -// ['Sample-1.0.1' => 1000001000, 'Sample-1.0.2' => 1000002000], -// $this->BcPlugin->getUpdaters($name) -// ); -// $folder = new BcFolder($pluginPath); -// $folder->delete(); -// } -// -// /** -// * test getUpdateScriptMessages And getUpdaters On Update Tmp -// */ -// public function test_getUpdateScriptMessagesAndGetUpdatersOnUpdateTmp() -// { -// $name = 'Sample'; -// $pluginPath = TMP . 'update' . DS . 'vendor' . DS . 'baserproject' . DS . $name . DS; -// $updatePath = $pluginPath . 'config' . DS . 'update' . DS; -// PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); -// -// // 新バージョン -// (new BcFolder($pluginPath))->create(); -// $file = new BcFile($pluginPath . 'VERSION.txt'); -// $file->write('1.0.3'); -// // アップデートスクリプト 1.0.1 -// (new BcFolder($updatePath . '1.0.1'))->create(); -// $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); -// $file->write(' \'test1\'];'); -// $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); -// $file->create(); -// -// $this->assertEquals( -// ['Sample-1.0.1' => 'test1'], -// $this->BcPlugin->getUpdateScriptMessages($name, true) -// ); -// $this->assertEquals( -// ['Sample-1.0.1' => 1000001000], -// $this->BcPlugin->getUpdaters($name, true) -// ); -// (new BcFolder(TMP . 'update'))->delete(); -// } -// -// /** -// * test execScript -// */ -// public function test_execScript() -// { -// $this->truncateTable('users'); -// $version = '1.0.0'; -// $updatePath = Plugin::path('BcBlog') . 'config' . DS . 'update'; -// $versionPath = $updatePath . DS . $version; -// // スクリプトなし -// if(file_exists($versionPath . DS . 'updater.php')) { -// unlink($versionPath . DS . 'updater.php'); -// } -// $this->assertTrue($this->BcPlugin->execScript($version)); -// // 有効スクリプトあり -// UserFactory::make(['id' => 1, 'name' => 'test'])->persist(); -// $folder = new BcFolder($versionPath); -// $folder->create(); -// $file = new BcFile($versionPath . DS . 'updater.php'); -// $file->create(); -// $file->write('get(\'BaserCore.Users\'); -//$user = $users->find()->where([\'id\' => 1])->first(); -//$user->name = \'hoge\'; -//$users->save($user);'); -// $this->BcPlugin->execScript($version); -// $users = $this->getTableLocator()->get('BaserCore.Users'); -// $user = $users->find()->where(['id' => 1])->first(); -// $this->assertEquals('hoge', $user->name); -// // 無効スクリプトあり -// $file = new BcFile($versionPath . DS . 'updater.php'); -// $file->create(); -// $file->write('log(\'test\');'); -// $this->BcPlugin->execScript($version); -// $file = new BcFile(LOGS . 'cli-error.log'); -// $log = $file->read(); -// $this->assertStringContainsString('test', $log); -// // 初期化 -// $folder->delete($updatePath); -// } -// -// /** -// * test createAssetsSymlink -// */ -// public function test_createAssetsSymlink() -// { -// unlink(WWW_ROOT . 'baser_core'); -// $this->BcPlugin->createAssetsSymlink(); -// $this->assertTrue(file_exists(WWW_ROOT . 'baser_core')); -// } -// -// /** -// * test migrate -// */ -// public function test_migrate() -// { -// $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; -// $folder = new BcFolder($pluginPath); -// -// // プラグインフォルダを初期化 -// $folder->delete(); -// $configPath = $pluginPath . 'config' . DS; -// $migrationPath = $configPath . 'Migrations' . DS; -// $seedPath = $configPath . 'Seeds' . DS; -// $srcPath = $pluginPath . 'src' . DS; -// $folder = new BcFolder($srcPath); -// $folder->create(); -// $folder = new BcFolder($migrationPath); -// $folder->create(); -// $folder = new BcFolder($seedPath); -// $folder->create(); -// -// // VERSION.txt -// $this->createVersionFile($pluginPath, '0.0.1'); -// -// // src/Plugin.php -// $this->createPluginFile($srcPath); -// -// // config/Migrations/20220626000000_InitialBcTest.php -// $this->createInitialMigrationFile($migrationPath); -// -// // インストール実行 -// $plugin = new BcPlugin(['name' => 'BcTest']); -// $plugin->install(['connection' => 'test']); -// $db = ConnectionManager::get('test'); -// $collection = $db->getSchemaCollection(); -// $tableSchema = $collection->describe('bc_test'); -// $this->assertEquals('string', $tableSchema->getColumnType('name')); -// -// // config/Migrations/20220627000000_AlterBcTest.php -// $this->createAlterMigrationFile($migrationPath); -// -// // アップデート実行 -// // インストールで利用した BcPluginを使い回すと、マイグレーションのキャッシュが残っていて、 -// // 新しいマイグレーションファイルを認識しないので初期化しなおす -// $plugin = new BcPlugin(['name' => 'BcTest']); -// $plugin->migrate(['connection' => 'test']); -// $tableSchema = $collection->describe('bc_test'); -// $this->assertEquals('datetime', $tableSchema->getColumnType('name')); -// -// // 初期化 -// $folder->delete($pluginPath); -// $this->dropTable('bc_test'); -// $this->dropTable('bc_test_phinxlog'); -// } -// -// /** -// * プラグインファイルを作成する -// * -// * @param $srcPath -// */ -// public function createPluginFile($srcPath) -// { -// $file = new BcFile($srcPath . 'Plugin.php'); -// $file->create(); -// $file->write('create(); -// $file->write('table(\'bc_test\'); -// $table->changeColumn(\'name\', \'datetime\'); -// $table->update(); -// } -//}'); -// } -// -// /** -// * 初期化用のマイグレーションファイルを作成する -// * -// * @param $migrationPath -// */ -// public function createInitialMigrationFile($migrationPath) -// { -// $file = new BcFile($migrationPath . '20220626000000_InitialBcTest.php', 'w'); -// $file->create(); -// $file->write('table(\'bc_test\') -// ->addColumn(\'name\', \'string\', [ -// \'default\' => null, -// \'limit\' => 255, -// \'null\' => true, -// ]) -// ->create(); -// } -// public function down() -// { -// $this->table(\'bc_test\')->drop()->save(); -// } -//}'); -// } -// -// /** -// * バージョンファイルを作成する -// * -// * @param $pluginPath -// * @param $version -// */ -// public function createVersionFile($pluginPath, $version) -// { -// $file = new BcFile($pluginPath . 'VERSION.txt'); -// $file->create(); -// $file->write($version); -// } -// -// /** -// * アップデーターを作成する -// * -// * @param $updaterPath -// */ -// public function createUpdater($updaterPath) -// { -// $file = new BcFile($updaterPath . 'updater.php', 'w'); -// $file->create(); -// $file->write('get(\'BcTest.BcTest\'); -//$table->save(new Entity([\'name\' => \'2022-06-26\']));'); -// } -// -// /** -// * test execUpdater -// */ -// public function test_execUpdater() -// { -// $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; -// $folder = new BcFolder($pluginPath); -// -// // プラグインフォルダを初期化 -// $folder->delete(); -// $configPath = $pluginPath . 'config' . DS; -// $migrationPath = $configPath . 'Migrations' . DS; -// $seedPath = $configPath . 'Seeds' . DS; -// $srcPath = $pluginPath . 'src' . DS; -// $folder = new BcFolder($srcPath); -// $folder->create(); -// $folder = new BcFolder($migrationPath); -// $folder->create(); -// $folder = new BcFolder($seedPath); -// $folder->create(); -// -// // VERSION.txt -// $this->createVersionFile($pluginPath, '0.0.1'); -// -// // config/Migrations/20220626000000_InitialBcTest.php -// $this->createInitialMigrationFile($migrationPath); -// -// // src/Plugin.php -// $this->createPluginFile($srcPath); -// -// // インストール実行 -// $plugin = new BcPlugin(['name' => 'BcTest']); -// $plugin->install(['connection' => 'test']); -// -// // VERSION.txt -// $this->createVersionFile($pluginPath, '0.0.2'); -// -// // config/update/0.0.2/updater.php -// $updaterPath = $configPath . 'update' . DS . '0.0.2' . DS; -// $folder = new BcFolder($updaterPath); -// $folder->create(); -// $this->createUpdater($updaterPath); -// -// // アップデート実行 -// $plugin->execUpdater(); -// $table = $this->getTableLocator()->get('BcTest.BcTest'); -// $entity = $table->find()->first(); -// $this->assertEquals('2022-06-26', (string) $entity->name); -// -// // 初期化 -// $folder = new BcFolder($pluginPath); -// $folder->delete(); -// $this->dropTable('bc_test'); -// $this->dropTable('bc_test_phinxlog'); -// } -// -// /** -// * テーマを適用する -// */ -// public function test_applyAsTheme() -// { -// $targetId = 1; -// $currentTheme = 'BcFront'; -// $SiteService = new SitesService(); -// $site = $SiteService->get($targetId); -// $this->assertEquals($currentTheme, $site->theme); -// -// $updateTheme = 'BcPluginSample'; -// $this->BcPlugin->applyAsTheme($site, $updateTheme); -// $site = $SiteService->get($targetId); -// $this->assertEquals($updateTheme, $site->theme); -// } -// -// /** -// * test Rest API -// */ -// public function testRestApi() -// { -// Router::resetRoutes(); -// // 件数確認 -// PermissionFactory::make()->allowGuest('/baser/api/*')->persist(); -// $this->get('/baser/api/baser-core/pages.json'); -// $result = json_decode((string)$this->_response->getBody()); -// $this->assertEquals(0, count($result->pages)); -// -// // 一件追加 -// $token = $this->apiLoginAdmin(); -// $this->post('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'], [ -// 'content' => [ -// 'parent_id' => 1, -// 'title' => 'sample', -// 'plugin' => 'BaserCore', -// 'type' => 'Page', -// 'site_id' => 1, -// 'alias_id' => '', -// 'entity_id' => '', -// ], -// 'contents' => '', -// 'draft' => '', -// 'page_template' => '', -// 'code' => '' -// ]); -// $result = json_decode((string)$this->_response->getBody()); -// $id = $result->page->id; -// -// // 件数確認(認証済) -// $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); -// $result = json_decode((string)$this->_response->getBody()); -// $this->assertEquals(1, count($result->pages)); -// -// // 変更(公開状態に変更) -// $this->put('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token'], [ -// 'content' => [ -// 'self_status' => 1 -// ] -// ]); -// -// // 件数確認(認証なし) -// $this->get('/baser/api/baser-core/pages.json'); -// $result = json_decode((string)$this->_response->getBody()); -// $this->assertEquals(1, count($result->pages)); -// -// // 削除 -// $this->delete('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token']); -// -// // 件数確認(認証済) -// $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); -// $result = json_decode((string)$this->_response->getBody()); -// $this->assertEquals(0, count($result->pages)); -// } -// -//} +/** + * baserCMS : Based Website Development Project + * 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 BaserCore\Test\TestCase; + +use BaserCore\BcPlugin; +use BaserCore\Service\SitesService; +use BaserCore\Test\Factory\PermissionFactory; +use BaserCore\Test\Factory\PluginFactory; +use BaserCore\Test\Factory\UserFactory; +use BaserCore\Test\Scenario\ContentFoldersScenario; +use BaserCore\Test\Scenario\ContentsScenario; +use BaserCore\Test\Scenario\PluginsScenario; +use BaserCore\Test\Scenario\SiteConfigsScenario; +use BaserCore\Test\Scenario\SitesScenario; +use BaserCore\Test\Scenario\UserGroupsScenario; +use BaserCore\Test\Scenario\UserScenario; +use BaserCore\Test\Scenario\UsersUserGroupsScenario; +use BaserCore\TestSuite\BcTestCase; +use BaserCore\Utility\BcFile; +use BaserCore\Utility\BcFolder; +use BaserCore\Utility\BcUtil; +use Cake\Core\Plugin; +use Cake\Datasource\ConnectionManager; +use Cake\ORM\TableRegistry; +use Cake\Routing\Router; +use Cake\TestSuite\IntegrationTestTrait; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; + +/** + * Class BcPluginTest + */ +class BcPluginTest extends BcTestCase +{ + + use ScenarioAwareTrait; + + /** + * @var BcPlugin + */ + public $BcPlugin; + + /** + * Set Up + * + * @return void + */ + public function setUp(): void + { + parent::setUp(); + $this->loadFixtureScenario(UserScenario::class); + $this->loadFixtureScenario(UserGroupsScenario::class); + $this->loadFixtureScenario(UsersUserGroupsScenario::class); + $this->loadFixtureScenario(ContentsScenario::class); + $this->loadFixtureScenario(SitesScenario::class); + $this->loadFixtureScenario(SiteConfigsScenario::class); + $this->loadFixtureScenario(ContentFoldersScenario::class); + $this->loadFixtureScenario(PluginsScenario::class); + $this->BcPlugin = new BcPlugin(['name' => 'BcBlog']); + } + + /** + * Tear Down + * + * @return void + */ + public function tearDown(): void + { + unset($this->BcPlugin); + parent::tearDown(); + } + + /** + * testInitialize + */ + public function testInitialize() + { + $this->assertNotEmpty($this->BcPlugin->migrations); + } + + /** + * testInstall + */ + public function testInstallAndUninstall() + { + $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); + // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 + + // インストール + $this->BcPlugin->install(['connection' => 'test']); + $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); + $this->assertEquals(1, $plugins->priority); + + // アンインストール + $from = BcUtil::getPluginPath('BcBlog'); + $pluginDir = dirname($from); + $folder = new BcFolder($from); + $to = $pluginDir . DS . 'BcBlogBak'; + $folder->copy($to); + $folder->create(); + $this->BcPlugin->uninstall(['connection' => 'test']); + $this->assertFalse(is_dir($from)); + $plugins = $this->getTableLocator()->get('BaserCore.Plugins')->find()->where(['name' => 'BcBlog'])->first(); + $this->assertNull($plugins); + $folder->move( $to); + $this->BcPlugin->install(['connection' => 'test']); + } + + /** + * testRollback + */ + public function testRollback() + { + $this->markTestIncomplete('このメソッドを利用すると全体のテストが失敗してしまうためスキップ。対応方法検討要'); + // データが初期化されなくなってしまう。dropTableでトリガーが削除されるのが原因の様子 + + $this->BcPlugin->install(['connection' => 'test']); + $this->BcPlugin->rollbackDb(['connection' => 'test']); + $collection = ConnectionManager::get('default')->getSchemaCollection(); + $tables = $collection->listTables(); + $this->assertNotContains('blog_posts', $tables); + $plugins = $this->getTableLocator()->get('BaserCore.Plugins'); + $plugins->deleteAll(['name' => 'BcBlog']); + $this->BcPlugin->install(['connection' => 'test']); + } + + /** + * testRoutes + */ + public function testRoutes() + { + $routes = Router::createRouteBuilder('/'); + $this->BcPlugin->routes($routes); + + // コンテンツ管理のプラグイン用のリバースルーティング + $this->getRequest('/'); + $this->assertEquals('/news/', Router::url([ + 'plugin' => 'BcBlog', + 'controller' => 'Blog', + 'action' => 'index', + 'entityId' => 31 + ])); + $this->assertEquals('/news/archives/1', Router::url([ + 'plugin' => 'BcBlog', + 'controller' => 'Blog', + 'action' => 'archives', + 'entityId' => 31, + 1 + ])); + + // 管理画面のプラグイン用ルーティング + $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']); + + // サブサイトのプラグイン用ルーティング + Router::reload(); + $routes = Router::createRouteBuilder(''); + $_SERVER['REQUEST_URI'] = '/s/'; + $this->BcPlugin->clearCurrentSite(); + $this->BcPlugin->routes($routes); + $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/index')); + $this->assertEquals('BlogContents', $result['controller']); + $this->assertEquals('s', $result['sitePrefix']); + $result = Router::parseRequest($this->getRequest('/s/bc-blog/blog_contents/edit/1')); + $this->assertEquals('BlogContents', $result['controller']); + $this->assertEquals('s', $result['sitePrefix']); + + // 管理画面のプラグイン用ルーティング + $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/index.json')); + $this->assertEquals('BlogContents', $result['controller']); + $this->assertEquals('json', $result['_ext']); + $result = Router::parseRequest($this->getRequest('/baser/api/bc-blog/blog_contents/edit/1.json')); + $this->assertEquals('BlogContents', $result['controller']); + $this->assertEquals('json', $result['_ext']); + unset($_SERVER['REQUEST_URI']); + $this->BcPlugin->clearCurrentSite(); + } + + /** + * test getUpdateScriptMessages And getUpdaters + */ + public function test_getUpdateScriptMessagesAndGetUpdaters() + { + $name = 'Sample'; + $pluginPath = ROOT . DS . 'plugins' . DS . $name . DS; + $updatePath = $pluginPath . 'config' . DS . 'update' . DS; + PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); + $folder = new BcFolder($pluginPath); + + // 新バージョン + $folder->create(); + $file = new BcFile($pluginPath . 'VERSION.txt'); + $file->create(); + $file->write('1.0.3'); + // アップデートスクリプト 0.0.1 + $folder = new BcFolder($updatePath . '0.0.1'); + $folder->create(); + $file = new BcFile($updatePath . '0.0.1' . DS . 'config.php'); + $file->create(); + $file->write(' \'test0\'];'); + // アップデートスクリプト 1.0.1 + $folder = new BcFolder($updatePath . '1.0.1'); + $folder->create(); + $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); + $file->create(); + $file->write(' \'test1\'];'); + $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); + $file->create(); + // アップデートスクリプト 1.0.2 + $folder = new BcFolder($updatePath . '1.0.2'); + $folder->create(); + $file = new BcFile($updatePath . '1.0.2' . DS . 'config.php'); + $file->create(); + $file->write(' \'test2\'];'); + $file = new BcFile($updatePath . '1.0.2' . DS . 'updater.php'); + $file->create(); + // アップデートスクリプト 1.0.4 + $folder = new BcFolder($updatePath . '1.0.4'); + $folder->create(); + $file = new BcFile($updatePath . '1.0.4' . DS . 'config.php'); + $file->create(); + $file->write(' \'test3\'];'); + + $this->assertEquals( + ['Sample-1.0.1' => 'test1', 'Sample-1.0.2' => 'test2'], + $this->BcPlugin->getUpdateScriptMessages($name) + ); + $this->assertEquals( + ['Sample-1.0.1' => 1000001000, 'Sample-1.0.2' => 1000002000], + $this->BcPlugin->getUpdaters($name) + ); + $folder = new BcFolder($pluginPath); + $folder->delete(); + } + + /** + * test getUpdateScriptMessages And getUpdaters On Update Tmp + */ + public function test_getUpdateScriptMessagesAndGetUpdatersOnUpdateTmp() + { + $name = 'Sample'; + $pluginPath = TMP . 'update' . DS . 'vendor' . DS . 'baserproject' . DS . $name . DS; + $updatePath = $pluginPath . 'config' . DS . 'update' . DS; + PluginFactory::make(['name' => $name, 'title' => 'サンプル', 'version' => '1.0.0'])->persist(); + + // 新バージョン + (new BcFolder($pluginPath))->create(); + $file = new BcFile($pluginPath . 'VERSION.txt'); + $file->write('1.0.3'); + // アップデートスクリプト 1.0.1 + (new BcFolder($updatePath . '1.0.1'))->create(); + $file = new BcFile($updatePath . '1.0.1' . DS . 'config.php'); + $file->write(' \'test1\'];'); + $file = new BcFile($updatePath . '1.0.1' . DS . 'updater.php'); + $file->create(); + + $this->assertEquals( + ['Sample-1.0.1' => 'test1'], + $this->BcPlugin->getUpdateScriptMessages($name, true) + ); + $this->assertEquals( + ['Sample-1.0.1' => 1000001000], + $this->BcPlugin->getUpdaters($name, true) + ); + (new BcFolder(TMP . 'update'))->delete(); + } + + /** + * test execScript + */ + public function test_execScript() + { + $this->truncateTable('users'); + $version = '1.0.0'; + $updatePath = Plugin::path('BcBlog') . 'config' . DS . 'update'; + $versionPath = $updatePath . DS . $version; + // スクリプトなし + if(file_exists($versionPath . DS . 'updater.php')) { + unlink($versionPath . DS . 'updater.php'); + } + $this->assertTrue($this->BcPlugin->execScript($version)); + // 有効スクリプトあり + UserFactory::make(['id' => 1, 'name' => 'test'])->persist(); + $folder = new BcFolder($versionPath); + $folder->create(); + $file = new BcFile($versionPath . DS . 'updater.php'); + $file->create(); + $file->write('get(\'BaserCore.Users\'); +$user = $users->find()->where([\'id\' => 1])->first(); +$user->name = \'hoge\'; +$users->save($user);'); + $this->BcPlugin->execScript($version); + $users = $this->getTableLocator()->get('BaserCore.Users'); + $user = $users->find()->where(['id' => 1])->first(); + $this->assertEquals('hoge', $user->name); + // 無効スクリプトあり + $file = new BcFile($versionPath . DS . 'updater.php'); + $file->create(); + $file->write('log(\'test\');'); + $this->BcPlugin->execScript($version); + $file = new BcFile(LOGS . 'cli-error.log'); + $log = $file->read(); + $this->assertStringContainsString('test', $log); + // 初期化 + $folder->delete($updatePath); + } + + /** + * test createAssetsSymlink + */ + public function test_createAssetsSymlink() + { + unlink(WWW_ROOT . 'baser_core'); + $this->BcPlugin->createAssetsSymlink(); + $this->assertTrue(file_exists(WWW_ROOT . 'baser_core')); + } + + /** + * test migrate + */ + public function test_migrate() + { + $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; + $folder = new BcFolder($pluginPath); + + // プラグインフォルダを初期化 + $folder->delete(); + $configPath = $pluginPath . 'config' . DS; + $migrationPath = $configPath . 'Migrations' . DS; + $seedPath = $configPath . 'Seeds' . DS; + $srcPath = $pluginPath . 'src' . DS; + $folder = new BcFolder($srcPath); + $folder->create(); + $folder = new BcFolder($migrationPath); + $folder->create(); + $folder = new BcFolder($seedPath); + $folder->create(); + + // VERSION.txt + $this->createVersionFile($pluginPath, '0.0.1'); + + // src/Plugin.php + $this->createPluginFile($srcPath); + + // config/Migrations/20220626000000_InitialBcTest.php + $this->createInitialMigrationFile($migrationPath); + + // インストール実行 + $plugin = new BcPlugin(['name' => 'BcTest']); + $plugin->install(['connection' => 'test']); + $db = ConnectionManager::get('test'); + $collection = $db->getSchemaCollection(); + $tableSchema = $collection->describe('bc_test'); + $this->assertEquals('string', $tableSchema->getColumnType('name')); + + // config/Migrations/20220627000000_AlterBcTest.php + $this->createAlterMigrationFile($migrationPath); + + // アップデート実行 + // インストールで利用した BcPluginを使い回すと、マイグレーションのキャッシュが残っていて、 + // 新しいマイグレーションファイルを認識しないので初期化しなおす + $plugin = new BcPlugin(['name' => 'BcTest']); + $plugin->migrate(['connection' => 'test']); + $tableSchema = $collection->describe('bc_test'); + $this->assertEquals('datetime', $tableSchema->getColumnType('name')); + + // 初期化 + $folder->delete($pluginPath); + $this->dropTable('bc_test'); + $this->dropTable('bc_test_phinxlog'); + } + + /** + * プラグインファイルを作成する + * + * @param $srcPath + */ + public function createPluginFile($srcPath) + { + $file = new BcFile($srcPath . 'Plugin.php'); + $file->create(); + $file->write('create(); + $file->write('table(\'bc_test\'); + $table->changeColumn(\'name\', \'datetime\'); + $table->update(); + } +}'); + } + + /** + * 初期化用のマイグレーションファイルを作成する + * + * @param $migrationPath + */ + public function createInitialMigrationFile($migrationPath) + { + $file = new BcFile($migrationPath . '20220626000000_InitialBcTest.php', 'w'); + $file->create(); + $file->write('table(\'bc_test\') + ->addColumn(\'name\', \'string\', [ + \'default\' => null, + \'limit\' => 255, + \'null\' => true, + ]) + ->create(); + } + public function down() + { + $this->table(\'bc_test\')->drop()->save(); + } +}'); + } + + /** + * バージョンファイルを作成する + * + * @param $pluginPath + * @param $version + */ + public function createVersionFile($pluginPath, $version) + { + $file = new BcFile($pluginPath . 'VERSION.txt'); + $file->create(); + $file->write($version); + } + + /** + * アップデーターを作成する + * + * @param $updaterPath + */ + public function createUpdater($updaterPath) + { + $file = new BcFile($updaterPath . 'updater.php', 'w'); + $file->create(); + $file->write('get(\'BcTest.BcTest\'); +$table->save(new Entity([\'name\' => \'2022-06-26\']));'); + } + + /** + * test execUpdater + */ + public function test_execUpdater() + { + $pluginPath = ROOT . DS . 'plugins' . DS . 'BcTest' . DS; + $folder = new BcFolder($pluginPath); + + // プラグインフォルダを初期化 + $folder->delete(); + $configPath = $pluginPath . 'config' . DS; + $migrationPath = $configPath . 'Migrations' . DS; + $seedPath = $configPath . 'Seeds' . DS; + $srcPath = $pluginPath . 'src' . DS; + $folder = new BcFolder($srcPath); + $folder->create(); + $folder = new BcFolder($migrationPath); + $folder->create(); + $folder = new BcFolder($seedPath); + $folder->create(); + + // VERSION.txt + $this->createVersionFile($pluginPath, '0.0.1'); + + // config/Migrations/20220626000000_InitialBcTest.php + $this->createInitialMigrationFile($migrationPath); + + // src/Plugin.php + $this->createPluginFile($srcPath); + + // インストール実行 + $plugin = new BcPlugin(['name' => 'BcTest']); + $plugin->install(['connection' => 'test']); + + // VERSION.txt + $this->createVersionFile($pluginPath, '0.0.2'); + + // config/update/0.0.2/updater.php + $updaterPath = $configPath . 'update' . DS . '0.0.2' . DS; + $folder = new BcFolder($updaterPath); + $folder->create(); + $this->createUpdater($updaterPath); + + // アップデート実行 + $plugin->execUpdater(); + $table = $this->getTableLocator()->get('BcTest.BcTest'); + $entity = $table->find()->first(); + $this->assertEquals('2022-06-26', (string) $entity->name); + + // 初期化 + $folder = new BcFolder($pluginPath); + $folder->delete(); + $this->dropTable('bc_test'); + $this->dropTable('bc_test_phinxlog'); + } + + /** + * テーマを適用する + */ + public function test_applyAsTheme() + { + $targetId = 1; + $currentTheme = 'BcFront'; + $SiteService = new SitesService(); + $site = $SiteService->get($targetId); + $this->assertEquals($currentTheme, $site->theme); + + $updateTheme = 'BcPluginSample'; + $this->BcPlugin->applyAsTheme($site, $updateTheme); + $site = $SiteService->get($targetId); + $this->assertEquals($updateTheme, $site->theme); + } + + /** + * test Rest API + */ + public function testRestApi() + { + Router::resetRoutes(); + // 件数確認 + PermissionFactory::make()->allowGuest('/baser/api/*')->persist(); + $this->get('/baser/api/baser-core/pages.json'); + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals(0, count($result->pages)); + + // 一件追加 + $token = $this->apiLoginAdmin(); + $this->post('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'], [ + 'content' => [ + 'parent_id' => 1, + 'title' => 'sample', + 'plugin' => 'BaserCore', + 'type' => 'Page', + 'site_id' => 1, + 'alias_id' => '', + 'entity_id' => '', + ], + 'contents' => '', + 'draft' => '', + 'page_template' => '', + 'code' => '' + ]); + $result = json_decode((string)$this->_response->getBody()); + $id = $result->page->id; + + // 件数確認(認証済) + $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals(1, count($result->pages)); + + // 変更(公開状態に変更) + $this->put('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token'], [ + 'content' => [ + 'self_status' => 1 + ] + ]); + + // 件数確認(認証なし) + $this->get('/baser/api/baser-core/pages.json'); + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals(1, count($result->pages)); + + // 削除 + $this->delete('/baser/api/admin/baser-core/pages/' . $id . '.json?token=' . $token['access_token']); + + // 件数確認(認証済) + $this->get('/baser/api/admin/baser-core/pages.json?token=' . $token['access_token'] . '&' . 'status='); + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals(0, count($result->pages)); + } + +} diff --git a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php index 1ccd230ace..e4bd8d73c8 100644 --- a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php @@ -818,7 +818,7 @@ public function test_beforeMarshal() */ public function test_autoConvert() { -// Configure::write('BcCustomContent.fieldTypes.BcCcFile.controlType', 'file'); + Configure::write('BcCustomContent.fieldTypes.BcCcFile.controlType', 'file'); //データ生成 CustomFieldFactory::make([ 'id' => 1, diff --git a/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php b/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php index 6cc19d6aea..656edb6b9d 100644 --- a/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php @@ -114,8 +114,8 @@ public function test_getNew() */ public function test_getFieldControlType() { -// Configure::write('BcCustomContent.fieldTypes.BcCcText.controlType', 'text'); -// Configure::write('BcCustomContent.fieldTypes.BcCcCheckbox.controlType', 'checkbox'); + Configure::write('BcCustomContent.fieldTypes.BcCcText.controlType', 'text'); + Configure::write('BcCustomContent.fieldTypes.BcCcCheckbox.controlType', 'checkbox'); //正常系実行 $result = $this->CustomEntriesService->getFieldControlType('BcCcText'); diff --git a/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php b/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php index d0fda31387..746e5b46da 100644 --- a/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Utility/CustomContentUtilTest.php @@ -25,7 +25,7 @@ public function tearDown(): void public function test_getPluginSetting() { //plugin and name is not empty - //Configure::write('BcCustomContent.fieldTypes.testPlugin.testSetting', 'testValue'); + Configure::write('BcCustomContent.fieldTypes.testPlugin.testSetting', 'testValue'); $rs = CustomContentUtil::getPluginSetting('testPlugin', 'testSetting'); $this->assertEquals('testValue', $rs); diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php index 785ff948af..d908f1ba26 100644 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php @@ -38,6 +38,7 @@ public function setUp(): void { parent::setUp(); BcUtil::includePluginClass('BcCustomContent'); + Configure::load('BaserCore.setting', 'baser'); $this->CustomContentAppHelper = new CustomContentAppHelper(new View()); } /** From d097b248242078c9f047a87ee12f9ae2ddf233eb Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Fri, 15 Nov 2024 13:46:34 +0900 Subject: [PATCH 7/8] =?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 --- .../tests/TestCase/View/Helper/CustomContentHelperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php index 711efc748f..074b14df69 100755 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentHelperTest.php @@ -250,7 +250,7 @@ public function test_getFieldTitle() public function test_getFieldValue($displayFront, $fieldType, $requestUrl, $fieldName, $fieldValue, $options, $expect) { //plugin BcCcRelatedを追加 -// Configure::write('BcCustomContent.fieldTypes.BcCcRelated', ['category' => '選択', 'label' => '関連データ', 'columnType' => 'string', 'controlType' => 'select', 'preview' => true, 'loop' => true]); + Configure::write('BcCustomContent.fieldTypes.BcCcRelated', ['category' => '選択', 'label' => '関連データ', 'columnType' => 'string', 'controlType' => 'select', 'preview' => true, 'loop' => true]); //サービスをコル $dataBaseService = $this->getService(BcDatabaseServiceInterface::class); $customTable = $this->getService(CustomTablesServiceInterface::class); From d313a4e45f10da9da51a28c15d068c567e7ffd86 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Mon, 18 Nov 2024 09:18:05 +0900 Subject: [PATCH 8/8] =?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 --- .../tests/TestCase/View/Helper/CustomContentAppHelperTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php index d908f1ba26..cc7b359ed8 100644 --- a/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php +++ b/plugins/bc-custom-content/tests/TestCase/View/Helper/CustomContentAppHelperTest.php @@ -37,8 +37,6 @@ class CustomContentAppHelperTest extends BcTestCase public function setUp(): void { parent::setUp(); - BcUtil::includePluginClass('BcCustomContent'); - Configure::load('BaserCore.setting', 'baser'); $this->CustomContentAppHelper = new CustomContentAppHelper(new View()); } /**