Skip to content

Commit

Permalink
add Admin_MailFieldsController_delete (#3352)
Browse files Browse the repository at this point in the history
Co-authored-by: thangnn <[email protected]>
  • Loading branch information
thangnnmd and thangnn authored Apr 20, 2024
1 parent c740b33 commit 9538ef9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,13 @@ public function edit(MailFieldsAdminServiceInterface $service, int $mailContentI
* @throws \Throwable
* @checked
* @noTodo
* @unitTest
*/
public function delete(MailFieldsServiceInterface $service, int $mailContentId, int $id)
{
$this->request->allowMethod(['post', 'delete']);
$entity = $service->get($id);
try {
$entity = $service->get($id);
if($service->delete($id)) {
$this->BcMessage->setSuccess(__d('baser_core', 'メールフィールド「{0}」を削除しました。', $entity->name));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,32 @@ public function testAdmin_ajax_delete()
*/
public function testAdmin_delete()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->enableSecurityToken();
$this->enableCsrfToken();

//メールメッセージサービスをコル
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
$MailMessagesService->createTable(1);
$MailMessagesService->addMessageField(1, 'name_1');

//データを生成
$this->loadFixtureScenario(MailContentsScenario::class);
$this->loadFixtureScenario(MailFieldsScenario::class);

//対象URLをコル
$this->post('/baser/admin/bc-mail/mail_fields/delete/1/1');
$this->assertResponseCode(302);
$this->assertFlashMessage('メールフィールド「性」を削除しました。');
$this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1');

//check case error
$this->post('/baser/admin/bc-mail/mail_fields/delete/1/999');
$this->assertResponseCode(302);
$this->assertFlashMessage('データベース処理中にエラーが発生しました。Record not found in table `mail_fields`.');
$this->assertRedirect('/baser/admin/bc-mail/mail_fields/index/1');

//テストデータベースを削除
$MailMessagesService->dropTable(1);
}

/**
Expand Down

0 comments on commit 9538ef9

Please sign in to comment.