From 48fb9d9e152a33895df4611e61b992cfd36a7633 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Mon, 25 Sep 2023 07:46:09 +0700 Subject: [PATCH] =?UTF-8?q?CustomContentsController::view=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(#2759)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../Api/Admin/CustomContentsController.php | 1 + .../Api/CustomContentsControllerTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/plugins/bc-custom-content/src/Controller/Api/Admin/CustomContentsController.php b/plugins/bc-custom-content/src/Controller/Api/Admin/CustomContentsController.php index 60865659a3..0b45dbc473 100644 --- a/plugins/bc-custom-content/src/Controller/Api/Admin/CustomContentsController.php +++ b/plugins/bc-custom-content/src/Controller/Api/Admin/CustomContentsController.php @@ -58,6 +58,7 @@ public function index(CustomContentsServiceInterface $service) * * @checked * @noTodo + * @unitTest */ public function view(CustomContentsServiceInterface $service, int $id) { diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomContentsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomContentsControllerTest.php index 1ea73eb071..db226ba917 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomContentsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomContentsControllerTest.php @@ -117,6 +117,31 @@ public function test_add() $this->assertEquals('関連するコンテンツがありません', $result->errors->content->_required); } + /** + * test view + */ + public function test_view() + { + //データを生成 + $this->loadFixtureScenario(CustomContentsScenario::class); + //APIを呼ぶ + $this->get('/baser/api/admin/bc-custom-content/custom_contents/view/1.json?token=' . $this->accessToken); + //ステータスを確認 + $this->assertResponseOk(); + //戻る値を確認 + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals($result->customContent->description, 'サービステスト'); + $this->assertEquals($result->customContent->content->url, '/'); + + //エラーを発生した時の確認 + $this->get('/baser/api/admin/bc-custom-content/custom_contents/view/10.json?token=' . $this->accessToken); + //ステータスを確認 + $this->assertResponseCode(404); + //戻る値を確認 + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals('データが見つかりません。', $result->message); + } + /** * test edit */