diff --git a/plugins/bc-mail/src/Model/Entity/MailContent.php b/plugins/bc-mail/src/Model/Entity/MailContent.php index e40f6c1740..5babb22437 100755 --- a/plugins/bc-mail/src/Model/Entity/MailContent.php +++ b/plugins/bc-mail/src/Model/Entity/MailContent.php @@ -60,6 +60,7 @@ class MailContent extends Entity * @return int * @checked * @noTodo + * @unitTest */ public function getNumberOfMessages() { diff --git a/plugins/bc-mail/tests/TestCase/Model/Entity/MailContentTest.php b/plugins/bc-mail/tests/TestCase/Model/Entity/MailContentTest.php new file mode 100644 index 0000000000..e35781ed72 --- /dev/null +++ b/plugins/bc-mail/tests/TestCase/Model/Entity/MailContentTest.php @@ -0,0 +1,67 @@ +MailContent = new MailContent(); + } + + public function tearDown(): void + { + parent::tearDown(); + } + + + /** + * Test getNumberOfMessages + */ + public function testGetNumberOfMessages() + { + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + + $rs = $this->MailContent->getNumberOfMessages(); + $this->assertEquals(0, $rs); + + //テストデータベースを生成 + $MailMessagesService->createTable(1); + $mailMessageTable = TableRegistry::getTableLocator()->get('BcMail.MailMessages'); + $mailContentId = 1; + $mailMessageTable->setup($mailContentId); + $mailMessageTable->save(new Entity(['id' => 1])); + $mailMessageTable->save(new Entity(['id' => 2])); + // テストデータを作成する + ContentFactory::make([ + 'id' => 9, + 'name' => 'contact', + 'plugin' => 'BcMail', + 'type' => 'MailContent', + 'entity_id' => 1, + 'url' => '/contact/', + 'site_id' => 1, + 'title' => 'お問い合わせ(※関連Fixture未完了)', + 'status' => true, + ])->persist(); + MailContentFactory::make(['id' => 1, 'save_info' => 1])->persist(); + + $this->MailContent->id = $mailContentId; + + $rs = $this->MailContent->getNumberOfMessages(); + $this->assertEquals(2, $rs); + + //不要なテーブルを削除 + $MailMessagesService->dropTable(1); + } + +}