Skip to content

Commit

Permalink
Merge pull request #3966 from thangnnmd/unitTest_MailContent_getNumbe…
Browse files Browse the repository at this point in the history
…rOfMessages

MailContent::getNumberOfMessages
  • Loading branch information
HungDV2022 authored Nov 7, 2024
2 parents 2c13165 + 7d5afab commit b2b14a0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Model/Entity/MailContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MailContent extends Entity
* @return int
* @checked
* @noTodo
* @unitTest
*/
public function getNumberOfMessages()
{
Expand Down
67 changes: 67 additions & 0 deletions plugins/bc-mail/tests/TestCase/Model/Entity/MailContentTest.php
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);
}

}

0 comments on commit b2b14a0

Please sign in to comment.