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

MailMessagesController::delete() ユニットテスト #4076

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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