Skip to content

Commit

Permalink
CustomLinksController::view のユニットテスト (#2749)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Sep 22, 2023
1 parent e92f72f commit a4c243e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function index(CustomLinksServiceInterface $service)
* @param int $id
* @checked
* @noTodo
* @unitTest
*/
public function view(CustomLinksServiceInterface $service, int $id)
{
Expand All @@ -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([
Expand Down Expand Up @@ -125,6 +126,7 @@ public function add(CustomLinksServiceInterface $service)
*
* @checked
* @noTodo
* @unitTest
*/
public function edit(CustomLinksServiceInterface $service, $id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit a4c243e

Please sign in to comment.