From e4eec770c3275842b67e6df8ec584edb11c71649 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Mon, 25 Sep 2023 07:45:17 +0700 Subject: [PATCH] =?UTF-8?q?CustomContentsController::view=20=20=E3=81=AE?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#2756)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng Co-authored-by: ryuring --- .../Controller/CustomContentController.php | 3 ++ .../CustomContentsControllerTest.php | 40 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) 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'); } }