diff --git a/plugins/baser-core/src/BcPlugin.php b/plugins/baser-core/src/BcPlugin.php index 4cdc826ca5..9560e58a1c 100644 --- a/plugins/baser-core/src/BcPlugin.php +++ b/plugins/baser-core/src/BcPlugin.php @@ -83,6 +83,7 @@ public function initialize(): void * @param PluginApplicationInterface $app * @checked * @noTodo + * @unitTest */ public function bootstrap(PluginApplicationInterface $app): void { diff --git a/plugins/baser-core/tests/TestCase/BcPluginTest.php b/plugins/baser-core/tests/TestCase/BcPluginTest.php index 9d80842121..10eaf6d11e 100644 --- a/plugins/baser-core/tests/TestCase/BcPluginTest.php +++ b/plugins/baser-core/tests/TestCase/BcPluginTest.php @@ -11,28 +11,24 @@ namespace BaserCore\Test\TestCase; +use App\Application; use BaserCore\BcPlugin; use BaserCore\Service\SitesService; +use BaserCore\Test\Factory\ContentFactory; +use BaserCore\Test\Factory\ContentFolderFactory; use BaserCore\Test\Factory\PermissionFactory; use BaserCore\Test\Factory\PluginFactory; +use BaserCore\Test\Factory\SiteFactory; 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\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcFile; use BaserCore\Utility\BcFolder; use BaserCore\Utility\BcUtil; +use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Datasource\ConnectionManager; -use Cake\ORM\TableRegistry; use Cake\Routing\Router; -use Cake\TestSuite\IntegrationTestTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** @@ -56,14 +52,6 @@ class BcPluginTest extends BcTestCase 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']); } @@ -86,6 +74,16 @@ public function testInitialize() $this->assertNotEmpty($this->BcPlugin->migrations); } + /** + * test bootstrap + */ + public function testBootstrap() + { + $app = new Application(CONFIG); + $this->BcPlugin->bootstrap($app); + $this->assertTrue(Configure::isConfigured('baser')); + } + /** * testInstall */ @@ -137,6 +135,10 @@ public function testRollback() */ public function testRoutes() { + 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); @@ -310,7 +312,7 @@ public function test_execScript() $this->BcPlugin->execScript($version); $users = $this->getTableLocator()->get('BaserCore.Users'); $user = $users->find()->where(['id' => 1])->first(); - $this->assertEquals('hoge', $user->name); + $this->assertEquals('test', $user->name); // 無効スクリプトあり $file = new BcFile($versionPath . DS . 'updater.php'); $file->create(); @@ -546,6 +548,22 @@ public function test_execUpdater() */ public function test_applyAsTheme() { + SiteFactory::make(['id' => '1', 'theme' => 'BcFront', 'main_site_id' => null])->persist(); + ContentFactory::make([ + 'id' => 1, + 'plugin' => 'BaserCore', + 'type' => 'ContentFolder', + 'entity_id' => 1, + 'site_id' => 1, + 'parent_id' => 0, + 'lft' => 1, + 'rght' => 2, + 'level' => 0, + 'status' => true, + 'site_root' => true, + ])->persist(); + ContentFolderFactory::make(['id' => '1', 'folder_template' => 'baserCMSサンプル'])->persist(); + $targetId = 1; $currentTheme = 'BcFront'; $SiteService = new SitesService(); @@ -563,6 +581,18 @@ public function test_applyAsTheme() */ public function testRestApi() { + $this->loadFixtureScenario(InitAppScenario::class); + ContentFactory::make( + [ + 'id' => 1, + 'plugin' => 'BaserCore', + 'type' => 'ContentFolder', + 'site_id' => 1, + 'parent_id' => 0, + 'lft' => 1, + 'rght' => 2, + ] + )->persist(); Router::resetRoutes(); // 件数確認 PermissionFactory::make()->allowGuest('/baser/api/*')->persist();