Skip to content

Commit

Permalink
MailMessagesController::delete() ユニットテスト
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Dec 10, 2024
1 parent 8522806 commit 37b113e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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 @@ -18,6 +18,8 @@
use BcMail\Service\MailMessagesServiceInterface;
use BcMail\Test\Factory\MailContentFactory;
use Cake\Event\Event;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

Expand Down Expand Up @@ -140,7 +142,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 37b113e

Please sign in to comment.