Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MailHelper::getPublishedMailContents() ユニットテスト #4063

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/bc-mail/src/View/Helper/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public function link($title, $contentsName, $datas = [], $options = [])
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getToken()
{
Expand All @@ -256,6 +257,7 @@ public function getToken()
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function token()
{
Expand Down Expand Up @@ -338,6 +340,7 @@ public function isMail(): bool
* @return mixed
* @checked
* @noTodo
* @unitTest
*/
public function getPublishedMailContents(int $siteId)
{
Expand Down
37 changes: 24 additions & 13 deletions plugins/bc-mail/tests/TestCase/View/Helper/MailHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,40 @@
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\BcFrontAppView;
use BcMail\Model\Entity\MailContent;
use BcMail\Test\Scenario\MailContentsScenario;
use BcMail\View\Helper\MailHelper;
use Cake\ORM\Entity;
use Cake\View\View;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class MailHelperTest
*
* @property MailHelper $Mail
* @property MailHelper $MailHelper
*/
class MailHelperTest extends BcTestCase
{
/**
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;

/**
* set up
*/
public function setUp(): void
{
parent::setUp();
$this->MailHelper = new MailHelper(new View());
SiteFactory::make(['id' => '1'])->persist();
$view = new BcFrontAppView($this->getRequest('/'));
$this->MailHelper = new MailHelper($view);
}

/**
* tear down
*/
public function tearDown(): void
{
// unset($this->Mail);
unset($this->MailHelper);
parent::tearDown();
}

Expand Down Expand Up @@ -114,9 +122,6 @@ public function testGetForm()
*/
public function testGetFormTemplates()
{
SiteFactory::make(['id' => '1'])->persist();
$view = new BcFrontAppView($this->getRequest('/'));
$this->MailHelper = new MailHelper($view);
$result = $this->MailHelper->getFormTemplates(1);
$this->assertEquals(['default' => 'default'], $result);
}
Expand All @@ -126,9 +131,6 @@ public function testGetFormTemplates()
*/
public function testGetMailTemplates()
{
SiteFactory::make(['id' => '1'])->persist();
$view = new BcFrontAppView($this->getRequest('/'));
$this->MailHelper = new MailHelper($view);
$result = $this->MailHelper->getMailTemplates(1);
$this->assertEquals(['mail_default' => 'mail_default'], $result);
}
Expand All @@ -138,10 +140,9 @@ public function testGetMailTemplates()
*/
public function testGetToken()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$result = $this->Mail->getToken();
$result = $this->MailHelper->getToken();
$expected = '/<script.*<\/script>.*/s';
$this->assertMatchesRegularExpression($expected, $result, 'スクリプトが取得できません。');
$this->assertMatchesRegularExpression($expected, $result);
}

/**
Expand Down Expand Up @@ -255,4 +256,14 @@ public function test_isMail()
$result = $this->MailHelper->isMail();
$this->assertTrue($result);
}

/**
* test getPublishedMailContents
*/
public function testGetPublishedMailContents()
{
$this->loadFixtureScenario(MailContentsScenario::class);
$rs = $this->MailHelper->getPublishedMailContents(1);
$this->assertEquals(1, $rs->count());
}
}