Skip to content

Commit

Permalink
Merge pull request #4076 from HungDV2022/unittest_MailMessagesControl…
Browse files Browse the repository at this point in the history
…ler_delete

MailMessagesController::delete() ユニットテスト
  • Loading branch information
HungDV2022 authored Dec 11, 2024
2 parents aa8316b + 37b113e commit a60afb4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function view(
* @return void|Response
* @checked
* @noTodo
* @unitTest
*/
public function delete(
MailMessagesServiceInterface $service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,38 @@ public function testView()
*/
public function testDelete()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->enableSecurityToken();
$this->enableCsrfToken();
// メールメッセージのデータを作成する
ContentFactory::make([
'plugin' => 'BcMail',
'type' => 'MailContent',
'url' => '/contact/',
'site_id' => 1,
'title' => 'お問い合わせ',
'entity_id' => 1,
])->persist();
MailContentFactory::make(['id' => 1])->persist();
$MailMessagesService = $this->getService(MailMessagesServiceInterface::class);
//テストデータベースを生成
$MailMessagesService->createTable(1);
$mailMessageTable = TableRegistry::getTableLocator()->get('BcMail.MailMessages');
$mailContentId = 1;
$mailMessageTable->setup($mailContentId);
$mailMessageTable->setup($mailContentId);
$mailMessageTable->save(new Entity(['id' => 1]));

//正常テスト
$this->post('/baser/admin/bc-mail/mail_messages/delete/1/1');
$this->assertResponseCode(302);
$this->assertRedirect(['action' => 'index', 1]);
$this->assertFlashMessage('お問い合わせ への受信データ NO「1」 を削除しました。');

//異常テスト
$this->get('/baser/admin/bc-mail/mail_messages/delete/1/1');
$this->assertResponseCode(405);

$MailMessagesService->dropTable(1);
}

/**
Expand Down

0 comments on commit a60afb4

Please sign in to comment.