Skip to content

Commit

Permalink
fix #1939 テーマ設定 API 保存 (#1941)
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 b892a1d commit 38c35f4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,29 @@ public function view(ThemeConfigsServiceInterface $service)
* @param ThemeConfigsServiceInterface $service
* @checked
* @noTodo
* @unitTest
*/
public function edit(ThemeConfigsServiceInterface $service)
{
//todo [API] 保存
$this->request->allowMethod(['post', 'put', 'patch']);
$themeConfig = $errors = null;
try {
$themeConfig = $service->update($this->request->getData());
$message = __d('baser_core', 'テーマ設定を保存しました。');
} catch (PersistenceFailedException $e) {
$errors = $e->getEntity()->getErrors();
$message = __d('baser_core', "入力エラーです。内容を修正してください。");
$this->setResponse($this->response->withStatus(400));
} catch (\Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。' . $e->getMessage());
$this->setResponse($this->response->withStatus(500));
}
$this->set([
'themeConfig' => $themeConfig,
'message' => $message,
'errors' => $errors,
]);
$this->viewBuilder()->setOption('serialize', ['themeConfig', 'message', 'errors']);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,46 @@ public function test_view()
*/
public function test_edit()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//アップローダープラグインを追加
$data = [
'name_add' => 'value_add'
];
//APIを呼ぶ
$this->post("/baser/api/bc-theme-config/theme_configs/edit.json?token=" . $this->accessToken, $data);
//ステータスを確認
$this->assertResponseSuccess();
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals('テーマ設定を保存しました。', $result->message);
$this->assertEquals('value_add', $result->themeConfig->name_add);

//アップローダープラグインを更新
$data = [
'name_add' => 'value_edit'
];
//APIを呼ぶ
$this->post("/baser/api/bc-theme-config/theme_configs/edit.json?token=" . $this->accessToken, $data);
//ステータスを確認
$this->assertResponseSuccess();
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals('テーマ設定を保存しました。', $result->message);
$this->assertEquals('value_edit', $result->themeConfig->name_add);

//アップローダープラグインを保存する時エラーを発生
$data = [
'test'
];
//APIを呼ぶ
$this->post("/baser/api/bc-theme-config/theme_configs/edit.json?token=" . $this->accessToken, $data);
//ステータスを確認
$this->assertResponseCode(500);
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals(
'データベース処理中にエラーが発生しました。Cake\ORM\Entity::get(): Argument #1 ($field) must be of type string, int given, called in /var/www/html/vendor/cakephp/cakephp/src/Datasource/EntityTrait.php on line 557',
$result->message
);
}

}

0 comments on commit 38c35f4

Please sign in to comment.