Skip to content

Commit 68227bc

Browse files
authored
fix #1807 テーマフォルダAPI フォルダを表示 (#1819)
1 parent 3fcb4ee commit 68227bc

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ public function view(ThemeFilesServiceInterface $service)
194194
$data = $this->getRequest()->getQueryParams();
195195
$data['fullpath'] = $service->getFullpath($data['theme'], $data['type'], $data['path']);
196196
$entity = $service->get($data['fullpath']);
197-
} catch (BcFormFailedException $e) {
198-
$this->setResponse($this->response->withStatus(400));
199-
$errors = $e->getForm()->getErrors();
200-
$message = __d('baser', '入力エラーです。内容を修正してください。' . $e->getMessage());
201197
} catch (\Throwable $e) {
202198
$this->setResponse($this->response->withStatus(400));
203199
$message = __d('baser', '処理中にエラーが発生しました。');

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,29 @@ public function copy_to_theme(ThemeFoldersServiceInterface $service)
258258
*
259259
* @param ThemeFoldersServiceInterface $service
260260
* @return void
261+
*
262+
* @checked
263+
* @noTodo
264+
* @unitTest
261265
*/
262266
public function view(ThemeFoldersServiceInterface $service)
263267
{
264-
//todo テーマフォルダAPI フォルダを表示
268+
$this->request->allowMethod(['get']);
269+
try {
270+
$data = $this->getRequest()->getQueryParams();
271+
$data['fullpath'] = $service->getFullpath($data['theme'], $data['type'], $data['path']);
272+
$entity = $service->get($data['fullpath']);
273+
} catch (\Throwable $e) {
274+
$this->setResponse($this->response->withStatus(400));
275+
$message = __d('baser', '処理中にエラーが発生しました。');
276+
}
277+
278+
$this->set([
279+
'entity' => $entity ?? null,
280+
'message' => $message ?? null,
281+
'errors' => $errors ?? null
282+
]);
283+
$this->viewBuilder()->setOption('serialize', ['entity', 'message', 'errors']);
265284
}
266285

267286
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ public function test_copy_to_theme()
208208
*/
209209
public function test_view()
210210
{
211-
$this->markTestIncomplete('このテストは未実装です。');
211+
//POSTデータを生成
212+
$data = [
213+
'theme' => 'BcThemeSample',
214+
'type' => 'layout',
215+
'path' => '',
216+
'plugin' => '',
217+
'token' => $this->accessToken
218+
];
219+
$query = http_build_query($data);
220+
//APIをコール
221+
$this->get('/baser/api/bc-theme-file/theme_folders/view.json?' . $query);
222+
//レスポンスコードを確認
223+
$this->assertResponseSuccess();
224+
//戻る値を確認
225+
$result = json_decode((string)$this->_response->getBody());
226+
$this->assertNotNull($result->entity);
212227
}
213228
}

0 commit comments

Comments
 (0)