-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3966 from thangnnmd/unitTest_MailContent_getNumbe…
…rOfMessages MailContent::getNumberOfMessages
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
plugins/bc-mail/tests/TestCase/Model/Entity/MailContentTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace BcMail\Test\TestCase\Model\Entity; | ||
|
||
use BaserCore\Test\Factory\ContentFactory; | ||
use BaserCore\TestSuite\BcTestCase; | ||
use BcMail\Model\Entity\MailContent; | ||
use BcMail\Service\MailMessagesServiceInterface; | ||
use BcMail\Test\Factory\MailContentFactory; | ||
use Cake\ORM\Entity; | ||
use Cake\ORM\TableRegistry; | ||
|
||
class MailContentTest extends BcTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->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); | ||
} | ||
|
||
} |