Skip to content

Commit

Permalink
fix #1930 エディタテンプレートAPI 削除 (#1935)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <HungDV2022>
  • Loading branch information
HungDV2022 committed Mar 12, 2023
1 parent b172348 commit 121aac0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,33 @@ public function edit(EditorTemplatesServiceInterface $service)
* 削除API
*
* @param EditorTemplatesServiceInterface $service
* @param int $id
*
* @checked
* @noTodo
* @unitTest
*/
public function delete(EditorTemplatesServiceInterface $service)
public function delete(EditorTemplatesServiceInterface $service, int $id)
{
//todo 削除API
$this->request->allowMethod(['post', 'delete']);
$editorTemplate = null;
try {
$editorTemplate = $service->get($id);
$service->delete($id);
$message = __d('baser_core', 'エディタテンプレート「{0}」を削除しました。', $editorTemplate->name);
} catch (RecordNotFoundException $e) {
$this->setResponse($this->response->withStatus(404));
$message = __d('baser_core', 'データが見つかりません。');
} catch (\Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。' . $e->getMessage());
$this->setResponse($this->response->withStatus(500));
}

$this->set([
'message' => $message,
'editorTemplate' => $editorTemplate,
]);
$this->viewBuilder()->setOption('serialize', ['editorTemplate', 'message']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,23 @@ public function test_edit()
*/
public function test_delete()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//データを生成
$this->loadFixtureScenario(EditorTemplatesScenario::class);
$this->post('/baser/api/bc-editor-template/editor_templates/delete/1.json?token=' . $this->accessToken);
//ステータスを確認
$this->assertResponseOk();
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals('エディタテンプレート「画像(左)とテキスト」を削除しました。', $result->message);
$this->assertEquals('画像(左)とテキスト', $result->editorTemplate->name);

//無効なIDを指定した場合、
$this->post('/baser/api/bc-editor-template/editor_templates/delete/10.json?token=' . $this->accessToken);
//ステータスを確認
$this->assertResponseCode(404);
//メッセージ内容を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals('データが見つかりません。', $result->message);
}

/**
Expand Down

0 comments on commit 121aac0

Please sign in to comment.