-
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 #3989 from HungDV2022/unittest_PasswordRequestMail…
…er_resetPassword PasswordRequestMailer::resetPassword() ユニットテスト
- Loading branch information
Showing
2 changed files
with
78 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
77 changes: 77 additions & 0 deletions
77
plugins/baser-core/tests/TestCase/Mailer/Admin/PasswordRequestMailerTest.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,77 @@ | ||
<?php | ||
/** | ||
* baserCMS : Based Website Development Project <https://basercms.net> | ||
* Copyright (c) NPO baser foundation <https://baserfoundation.org/> | ||
* | ||
* @copyright Copyright (c) NPO baser foundation | ||
* @link https://basercms.net baserCMS Project | ||
* @since 5.0.0 | ||
* @license https://basercms.net/license/index.html MIT License | ||
*/ | ||
|
||
namespace BaserCore\Test\TestCase\Mailer\Admin; | ||
|
||
use BaserCore\Mailer\Admin\PasswordRequestMailer; | ||
use BaserCore\Test\Factory\PasswordRequestFactory; | ||
use BaserCore\Test\Factory\SiteConfigFactory; | ||
use BaserCore\Test\Factory\UserFactory; | ||
use BaserCore\TestSuite\BcTestCase; | ||
use Cake\Routing\Router; | ||
use Cake\Utility\Security; | ||
|
||
/** | ||
* Class PasswordRequestMailerTest | ||
*/ | ||
class PasswordRequestMailerTest extends BcTestCase | ||
{ | ||
|
||
/** | ||
* @var PasswordRequestMailer | ||
*/ | ||
public $PasswordRequestMailer; | ||
|
||
/** | ||
* Set Up | ||
* | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
SiteConfigFactory::make(['name' => 'email', 'value' => '[email protected]'])->persist(); | ||
SiteConfigFactory::make(['name' => 'admin-theme', 'value' => 'test theme'])->persist(); | ||
$this->PasswordRequestMailer = new PasswordRequestMailer(); | ||
} | ||
|
||
/** | ||
* Tear Down | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* test resetPassword | ||
*/ | ||
public function testResetPassword() | ||
{ | ||
UserFactory::make(['id' => 1])->persist(); | ||
PasswordRequestFactory::make(['id' => 1, 'user_id' => 1, 'request_key' => Security::randomString(40), 'used' => 0,])->persist(); | ||
|
||
Router::setRequest( | ||
$this->getRequest()->withParam('prefix', 'Admin') | ||
->withParam('controller', 'MailController') | ||
->withParam('plugin', 'Mail') | ||
); | ||
//正常テスト メールが無事に送信できる | ||
$this->PasswordRequestMailer->resetPassword(UserFactory::get(1), PasswordRequestFactory::get(1)); | ||
|
||
//正常テスト エラーを出る | ||
$this->expectException('Cake\Datasource\Exception\RecordNotFoundException'); | ||
$this->PasswordRequestMailer->resetPassword(UserFactory::get(2), PasswordRequestFactory::get(1)); | ||
} | ||
|
||
} |