Skip to content

Commit

Permalink
Merge pull request #4022 from HungDV2022/unittest_BcPlugin_bootstrap
Browse files Browse the repository at this point in the history
BcPlugin::bootstrap()ユニットテスト
  • Loading branch information
HungDV2022 authored Nov 18, 2024
2 parents d6831d6 + 81718c8 commit 32f5f6e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
1 change: 1 addition & 0 deletions plugins/baser-core/src/BcPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function initialize(): void
* @param PluginApplicationInterface $app
* @checked
* @noTodo
* @unitTest
*/
public function bootstrap(PluginApplicationInterface $app): void
{
Expand Down
66 changes: 48 additions & 18 deletions plugins/baser-core/tests/TestCase/BcPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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']);
}

Expand All @@ -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
*/
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 32f5f6e

Please sign in to comment.