Skip to content

Commit 4370dd7

Browse files
authored
fix #1775 テーマファイルAPI ファイルを表示 (#1786)
1 parent 8e48b9e commit 4370dd7

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

plugins/bc-theme-file/src/Controller/Api/ThemeFilesController.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,33 @@ public function copy_to_theme(ThemeFilesServiceInterface $service)
179179
* [API] テーマファイル ファイルを表示
180180
*
181181
* @param ThemeFilesServiceInterface $service
182+
*
183+
* @checked
184+
* @noTodo
185+
* @unitTest
182186
*/
183187
public function view(ThemeFilesServiceInterface $service)
184188
{
185-
//todo テーマファイルAPI ファイルを表示 #1775
189+
$this->request->allowMethod(['get']);
190+
try {
191+
$data = $this->getRequest()->getQueryParams();
192+
$data['fullpath'] = $service->getFullpath($data['theme'], $data['type'], $data['path']);
193+
$entity = $service->get($data['fullpath']);
194+
} catch (BcFormFailedException $e) {
195+
$this->setResponse($this->response->withStatus(400));
196+
$errors = $e->getForm()->getErrors();
197+
$message = __d('baser', '入力エラーです。内容を修正してください。' . $e->getMessage());
198+
} catch (\Throwable $e) {
199+
$this->setResponse($this->response->withStatus(400));
200+
$message = __d('baser', '処理中にエラーが発生しました。');
201+
}
202+
203+
$this->set([
204+
'entity' => $entity ?? null,
205+
'message' => $message ?? null,
206+
'errors' => $errors ?? null
207+
]);
208+
$this->viewBuilder()->setOption('serialize', ['entity', 'message', 'errors']);
186209
}
187210

188211
/**

plugins/bc-theme-file/tests/TestCase/Controller/Api/ThemeFilesControllerTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,22 @@ public function test_copy_to_theme()
224224
*/
225225
public function test_view()
226226
{
227-
$this->markTestIncomplete('このテストは未実装です。');
227+
//POSTデータを生成
228+
$data = [
229+
'theme' => 'BcThemeSample',
230+
'type' => 'layout',
231+
'path' => 'default.php',
232+
'plugin' => '',
233+
'token' => $this->accessToken
234+
];
235+
$query = http_build_query($data);
236+
//APIをコール
237+
$this->get('/baser/api/bc-theme-file/theme_files/view.json?' . $query);
238+
//レスポンスコードを確認
239+
$this->assertResponseSuccess();
240+
//戻る値を確認
241+
$result = json_decode((string)$this->_response->getBody());
242+
$this->assertNotNull($result->entity->contents);
228243
}
229244

230245
/**

0 commit comments

Comments
 (0)