diff --git a/plugins/bc-custom-content/src/Controller/CustomContentController.php b/plugins/bc-custom-content/src/Controller/CustomContentController.php index 37b800d3ed..19f2b55d95 100644 --- a/plugins/bc-custom-content/src/Controller/CustomContentController.php +++ b/plugins/bc-custom-content/src/Controller/CustomContentController.php @@ -78,6 +78,9 @@ public function index(CustomContentFrontServiceInterface $service) * * @param CustomContentFrontServiceInterface $service * @return \Cake\Http\Response + * @checked + * @noTodo + * @unitTest */ public function view(CustomContentFrontServiceInterface $service, $entryId) { diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php index 901fc83398..3de5fb4dc7 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php @@ -127,6 +127,44 @@ public function test_index() */ public function test_view() { - $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/view/プログラマー'); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertResponseCode(200); + $this->assertEquals('サービスタイトル', $vars['title']); + $this->assertNotNull($vars['customContent']); + $this->assertNotNull($vars['customEntry']); + + //存在しないURLを指定した場合、 + $this->get('/test-false/view/プログラマー'); + $this->assertResponseCode(404); + $this->assertEquals( + 'カスタムコンテンツにカスタムテーブルが紐付けられていません。カスタムコンテンツの編集画面よりカスタムテーブルを選択してください。', + $_SESSION['Flash']['flash'][0]['message'] + ); + //不要なテーブルを削除 + $dataBaseService->dropTable('custom_entry_1_recruit_categories'); } }