Skip to content

Commit

Permalink
add Admin_EditorTemplatesController_add (#3338)
Browse files Browse the repository at this point in the history
Co-authored-by: thangnn <[email protected]>
  • Loading branch information
thangnnmd and thangnn authored May 24, 2024
1 parent dbef28b commit b81ee6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit b81ee6f

Please sign in to comment.