Skip to content

Commit

Permalink
Merge pull request #4050 from thangnnmd/unitTest_MailMessageMailer_ge…
Browse files Browse the repository at this point in the history
…tFrom

MailMessageMailer::getFrom
  • Loading branch information
HungDV2022 authored Nov 28, 2024
2 parents b237705 + 15aa733 commit a287750
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/bc-mail/src/Mailer/MailMessageMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function sendFormToUser(
* @return array|mixed
* @checked
* @noTodo
* @unitTest
*/
public function getFrom(EntityInterface $mailContent) {
if($mailContent->sender_name) return $mailContent->sender_name;
Expand Down
16 changes: 15 additions & 1 deletion plugins/bc-mail/tests/TestCase/Mailer/MailMessageMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

namespace BcMail\Test\TestCase\Mailer;

use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\TestSuite\BcTestCase;
use BcMail\Mailer\MailMessageMailer;
use BcMail\Service\MailContentsServiceInterface;
use BcMail\Test\Factory\MailContentFactory;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

Expand Down Expand Up @@ -121,6 +124,17 @@ public function testSendFormToUser()
*/
public function testGetFrom()
{
$this->markTestIncomplete('このテストは未実装');
$mailContentService = $this->getService(MailContentsServiceInterface::class);
MailContentFactory::make(['id' => 1])->persist();
ContentFactory::make(['plugin' => 'BcMail', 'type' => 'MailContent', 'site_id' => 1, 'entity_id' => 1])->persist();
SiteFactory::make(['id' => 1, 'display_name' => 'main site'])->persist();

//sender_name が存在場合
$mailContent = MailContentFactory::make(['sender_name' => 'sender name'])->getEntity();
$this->assertEquals('sender name', $this->MailMessageMailer->getFrom($mailContent));

//sender_name が存在しない場合
$mailContent = $mailContentService->get(1);
$this->assertEquals('main site', $this->MailMessageMailer->getFrom($mailContent));
}
}

0 comments on commit a287750

Please sign in to comment.