Skip to content

Commit

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

MailMessagesController::view() ユニットテスト
  • Loading branch information
HungDV2022 authored Dec 11, 2024
2 parents 3164455 + aa79d06 commit aa8316b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function index(MailMessagesAdminServiceInterface $service, int $mailConte
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function view(
MailMessagesAdminServiceInterface $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 @@ -132,7 +134,33 @@ public function testIndex()
*/
public function testView()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
// メールメッセージのデータを作成する
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->save(new Entity(['id' => 1]));

//正常テスト
$this->get('/baser/admin/bc-mail/mail_messages/view/1/1');
$this->assertResponseCode(200);

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

$MailMessagesService->dropTable(1);
}

/**
Expand Down

0 comments on commit aa8316b

Please sign in to comment.