From a4c243ea6bb1781751d9045a8468a158ee642747 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:29:03 +0700 Subject: [PATCH] =?UTF-8?q?CustomLinksController::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(#2749)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../Api/Admin/CustomLinksController.php | 4 +- .../Admin/Api/CustomLinksControllerTest.php | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/plugins/bc-custom-content/src/Controller/Api/Admin/CustomLinksController.php b/plugins/bc-custom-content/src/Controller/Api/Admin/CustomLinksController.php index 3bc917426d..5c934983d9 100644 --- a/plugins/bc-custom-content/src/Controller/Api/Admin/CustomLinksController.php +++ b/plugins/bc-custom-content/src/Controller/Api/Admin/CustomLinksController.php @@ -64,6 +64,7 @@ public function index(CustomLinksServiceInterface $service) * @param int $id * @checked * @noTodo + * @unitTest */ public function view(CustomLinksServiceInterface $service, int $id) { @@ -74,7 +75,7 @@ public function view(CustomLinksServiceInterface $service, int $id) $customLink = $service->get($id, $this->getRequest()->getQueryParams()); } catch (RecordNotFoundException $e) { $this->setResponse($this->response->withStatus(404)); - $message = __d('baser_core', 'データが見つかりません'); + $message = __d('baser_core', 'データが見つかりません。'); } $this->set([ @@ -125,6 +126,7 @@ public function add(CustomLinksServiceInterface $service) * * @checked * @noTodo + * @unitTest */ public function edit(CustomLinksServiceInterface $service, $id) { diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomLinksControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomLinksControllerTest.php index e1fd7a9103..b72df3d9d4 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomLinksControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/Admin/Api/CustomLinksControllerTest.php @@ -157,6 +157,45 @@ public function test_add() } + /** + * test view + */ + public function test_view() + { + //サービスをコル + $dataBaseService = $this->getService(BcDatabaseServiceInterface::class); + $customTable = $this->getService(CustomTablesServiceInterface::class); + + //データを生成 + $this->loadFixtureScenario(CustomContentsScenario::class); + $this->loadFixtureScenario(CustomFieldsScenario::class); + $customTable->create([ + 'id' => 1, + 'name' => 'recruit_category', + 'title' => '求人情報', + 'type' => '1', + 'display_field' => 'title', + 'has_child' => 0 + ]); + //APIを呼ぶ + $this->get('/baser/api/admin/bc-custom-content/custom_links/view/1.json?token=' . $this->accessToken); + //ステータスを確認 + $this->assertResponseOk(); + //戻る値を確認 + $result = json_decode((string)$this->_response->getBody()); + $this->assertNotNull($result->customLink); + + //存在しないIDを指定した場合、 + $this->get('/baser/api/admin/bc-custom-content/custom_links/view/11111.json?token=' . $this->accessToken); + //ステータスを確認 + $this->assertResponseCode(404); + $result = json_decode((string)$this->_response->getBody()); + $this->assertEquals('データが見つかりません。', $result->message); + + //不要なテーブルを削除 + $dataBaseService->dropTable('custom_entry_1_recruit_category'); + } + /** * test edit */