diff --git a/plugins/bc-custom-content/src/Controller/CustomContentController.php b/plugins/bc-custom-content/src/Controller/CustomContentController.php index 09c1212ca9..37b800d3ed 100644 --- a/plugins/bc-custom-content/src/Controller/CustomContentController.php +++ b/plugins/bc-custom-content/src/Controller/CustomContentController.php @@ -44,6 +44,9 @@ public function initialize(): void * * @param CustomContentFrontServiceInterface $service * @return \Cake\Http\Response + * @checked + * @noTodo + * @unitTest */ public function index(CustomContentFrontServiceInterface $service) { diff --git a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php index 4bbce89a21..896cd48c88 100644 --- a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php +++ b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php @@ -32,12 +32,16 @@ public function load(...$args) 'id' => 1, 'custom_table_id' => 1, 'description' => 'サービステスト', - 'template' => 'template_1', + 'template' => 'default', + "widget_area" => null, + "list_count" => 10, + "list_order" => "id", + "list_direction" => "DESC" ])->persist(); ContentFactory::make([ - 'id' => 1, - 'url' => '/', - 'name' => '', + 'id' => 100, + 'url' => '/test/', + 'name' => 'test', 'plugin' => 'BcCustomContent', 'type' => 'CustomContent', 'site_id' => 1, @@ -46,6 +50,8 @@ public function load(...$args) 'lft' => 1, 'rght' => 2, 'entity_id' => 1, + "level" => 1, + 'layout_template' => 'default', 'status' => true ])->persist(); @@ -53,10 +59,10 @@ public function load(...$args) 'id' => 2, 'custom_table_id' => 2, 'description' => '求人', - 'template' => 'template_2', + 'template' => 'default', ])->persist(); ContentFactory::make([ - 'id' => 2, + 'id' => 102, 'url' => '/recruit/', 'plugin' => 'BcCustomContent', 'type' => 'CustomContent', @@ -66,6 +72,32 @@ public function load(...$args) 'lft' => 3, 'rght' => 4, 'entity_id' => 2, + 'layout_template' => 'default', + 'status' => true + ])->persist(); + + CustomContentFactory::make([ + 'id' => 3, + 'description' => 'サービステスト', + 'template' => 'default', + "widget_area" => null, + "list_count" => 10, + "list_order" => "id", + "list_direction" => "DESC" + ])->persist(); + ContentFactory::make([ + 'url' => '/test-false/', + 'name' => 'test-false', + 'plugin' => 'BcCustomContent', + 'type' => 'CustomContent', + 'site_id' => 1, + 'parent_id' => null, + 'title' => 'サービスタイトル', + 'lft' => 11, + 'rght' => 21, + 'entity_id' => 3, + "level" => 1, + 'layout_template' => 'default', 'status' => true ])->persist(); } diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php index dbfeb027d5..901fc83398 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php @@ -11,9 +11,16 @@ namespace BcCustomContent\Test\TestCase\Controller; +use BaserCore\Service\BcDatabaseServiceInterface; +use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BaserCore\Utility\BcContainerTrait; use BcCustomContent\Controller\CustomContentController; +use BcCustomContent\Service\CustomTablesServiceInterface; +use BcCustomContent\Test\Factory\CustomLinkFactory; +use BcCustomContent\Test\Scenario\CustomContentsScenario; +use BcCustomContent\Test\Scenario\CustomEntriesScenario; +use BcCustomContent\Test\Scenario\CustomFieldsScenario; use Cake\Http\ServerRequest; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -74,7 +81,45 @@ public function test_initialize() */ public function test_index() { - $this->markTestIncomplete('テストが未実装です'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + //データーを生成 + $this->loadFixtureScenario(InitAppScenario::class); + $dataBaseService = $this->getService(BcDatabaseServiceInterface::class); + $customTable = $this->getService(CustomTablesServiceInterface::class); + + //カスタムテーブルとカスタムエントリテーブルを生成 + $customTable->create([ + 'id' => 1, + 'name' => 'recruit_categories', + 'title' => '求人情報', + 'type' => '1', + 'display_field' => 'title', + 'publish_begin' => '2021-10-01 00:00:00', + 'publish_end' => '9999-11-30 23:59:59', + 'has_child' => 0 + ]); + $this->loadFixtureScenario(CustomContentsScenario::class); + $this->loadFixtureScenario(CustomEntriesScenario::class); + $this->loadFixtureScenario(CustomFieldsScenario::class); + + //対象URLをコル + $this->get('/test/'); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertResponseCode(200); + $this->assertEquals('サービスタイトル', $vars['title']); + $this->assertNotNull($vars['customContent']); + $this->assertNotNull($vars['customEntries']); + + //存在しないURLを指定した場合、 + $this->get('/test-false/'); + $this->assertResponseCode(404); + $this->assertEquals( + 'カスタムコンテンツにカスタムテーブルが紐付けられていません。カスタムコンテンツの編集画面よりカスタムテーブルを選択してください。', + $_SESSION['Flash']['flash'][0]['message'] + ); + //不要なテーブルを削除 + $dataBaseService->dropTable('custom_entry_1_recruit_categories'); } /**