diff --git a/plugins/bc-editor-template/src/Controller/Admin/EditorTemplatesController.php b/plugins/bc-editor-template/src/Controller/Admin/EditorTemplatesController.php index 607fcd810b..69ccd20caf 100644 --- a/plugins/bc-editor-template/src/Controller/Admin/EditorTemplatesController.php +++ b/plugins/bc-editor-template/src/Controller/Admin/EditorTemplatesController.php @@ -52,6 +52,7 @@ public function index(EditorTemplatesServiceInterface $service) * @param EditorTemplatesService $service * @checked * @noTodo + * @UnitTest */ public function add(EditorTemplatesServiceInterface $service) { @@ -73,7 +74,7 @@ public function add(EditorTemplatesServiceInterface $service) ]); $this->BcMessage->setSuccess(__d('baser_core', 'テンプレート「{0}」を追加しました', $entity->name)); - $this->redirect(['action' => 'index']); + return $this->redirect(['action' => 'index']); } catch (PersistenceFailedException $e) { $entity = $e->getEntity(); $this->BcMessage->setError(__d('baser_core', '入力エラーです。内容を修正してください。')); @@ -84,7 +85,6 @@ public function add(EditorTemplatesServiceInterface $service) $this->set([ 'editorTemplate' => $entity?? $service->getNew() ]); - $this->viewBuilder()->addHelper(BcSiteConfig::get('editor')); } /** @@ -117,7 +117,7 @@ public function edit(EditorTemplatesServiceInterface $service, int $id) ]); $this->BcMessage->setSuccess(__d('baser_core', 'テンプレート「{0}」を更新しました', $entity->name)); - $this->redirect(['action' => 'index']); + return $this->redirect(['action' => 'index']); } catch (PersistenceFailedException $e) { $entity = $e->getEntity(); $this->BcMessage->setError(__d('baser_core', '入力エラーです。内容を修正してください。')); @@ -128,7 +128,6 @@ public function edit(EditorTemplatesServiceInterface $service, int $id) $this->set([ 'editorTemplate' => $entity ]); - $this->viewBuilder()->addHelper(BcSiteConfig::get('editor')); } /** diff --git a/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php b/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php index f1a3e640d0..4470d93f6c 100644 --- a/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php +++ b/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php @@ -114,6 +114,27 @@ public function testAfterAddEvent() $this->assertEquals(1, $query->count()); } + /** + * Test add + */ + public function testAdmin_add() + { + $this->enableSecurityToken(); + $this->enableCsrfToken(); + + //正常系実行 + $this->post('/baser/admin/bc-editor-template/editor_templates/add', ['name' => 'test', 'description' => 'test description']); + $this->assertResponseCode(302); + $this->assertFlashMessage('テンプレート「test」を追加しました'); + $this->assertRedirect(['action' => 'index']); + + //異常系実行 + $this->post('/baser/admin/bc-editor-template/editor_templates/add', ['name' => '']); + $this->assertResponseCode(200); + $vars = $this->_controller->viewBuilder()->getVars(); + $this->assertEquals(['name' => ['_empty' => "テンプレート名を入力してください。"]], $vars['editorTemplate']->getErrors()); + } + /** * Test beforeAddEvent */