Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Admin_EditorTemplatesController_add #3338

Merged
merged 11 commits into from
May 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function index(EditorTemplatesServiceInterface $service)
* @param EditorTemplatesService $service
* @checked
* @noTodo
* @UnitTest
*/
public function add(EditorTemplatesServiceInterface $service)
{
Expand All @@ -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', '入力エラーです。内容を修正してください。'));
Expand All @@ -84,7 +85,6 @@ public function add(EditorTemplatesServiceInterface $service)
$this->set([
'editorTemplate' => $entity?? $service->getNew()
]);
$this->viewBuilder()->addHelper(BcSiteConfig::get('editor'));
}

/**
Expand Down Expand Up @@ -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', '入力エラーです。内容を修正してください。'));
Expand All @@ -128,7 +128,6 @@ public function edit(EditorTemplatesServiceInterface $service, int $id)
$this->set([
'editorTemplate' => $entity
]);
$this->viewBuilder()->addHelper(BcSiteConfig::get('editor'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading