mirror of
https://github.com/elyby/accounts.git
synced 2024-12-02 11:41:05 +05:30
Обновлены тесты для всех форм, что отправляли письма
This commit is contained in:
parent
88175fea48
commit
b8049e8899
@ -78,6 +78,8 @@ class RepeatAccountActivationForm extends ApiForm {
|
|||||||
throw new ThisShouldNotHappenException('Unable save email-activation model.');
|
throw new ThisShouldNotHappenException('Unable save email-activation model.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->emailActivation = $activation;
|
||||||
|
|
||||||
Yii::$app->queue->push(SendRegistrationEmail::createFromConfirmation($activation));
|
Yii::$app->queue->push(SendRegistrationEmail::createFromConfirmation($activation));
|
||||||
|
|
||||||
$transaction->commit();
|
$transaction->commit();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
namespace common\tasks;
|
namespace common\tasks;
|
||||||
|
|
||||||
use common\emails\EmailHelper;
|
use common\emails\EmailHelper;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
namespace common\tasks;
|
namespace common\tasks;
|
||||||
|
|
||||||
use common\emails\EmailHelper;
|
use common\emails\EmailHelper;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
namespace common\tasks;
|
namespace common\tasks;
|
||||||
|
|
||||||
use common\emails\EmailHelper;
|
use common\emails\EmailHelper;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
namespace common\tasks;
|
namespace common\tasks;
|
||||||
|
|
||||||
use common\emails\EmailHelper;
|
use common\emails\EmailHelper;
|
||||||
|
@ -4,6 +4,7 @@ modules:
|
|||||||
- Yii2:
|
- Yii2:
|
||||||
part: [orm, email, fixtures]
|
part: [orm, email, fixtures]
|
||||||
- tests\codeception\common\_support\amqp\Helper
|
- tests\codeception\common\_support\amqp\Helper
|
||||||
|
- tests\codeception\common\_support\queue\CodeceptionQueueHelper
|
||||||
- tests\codeception\common\_support\Mockery
|
- tests\codeception\common\_support\Mockery
|
||||||
config:
|
config:
|
||||||
Yii2:
|
Yii2:
|
||||||
|
@ -4,7 +4,9 @@ namespace codeception\api\unit\models\authentication;
|
|||||||
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
||||||
use api\models\authentication\ForgotPasswordForm;
|
use api\models\authentication\ForgotPasswordForm;
|
||||||
use Codeception\Specify;
|
use Codeception\Specify;
|
||||||
|
use common\models\Account;
|
||||||
use common\models\EmailActivation;
|
use common\models\EmailActivation;
|
||||||
|
use common\tasks\SendPasswordRecoveryEmail;
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use tests\codeception\api\unit\TestCase;
|
use tests\codeception\api\unit\TestCase;
|
||||||
use tests\codeception\common\fixtures\AccountFixture;
|
use tests\codeception\common\fixtures\AccountFixture;
|
||||||
@ -78,29 +80,41 @@ class ForgotPasswordFormTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testForgotPassword() {
|
public function testForgotPassword() {
|
||||||
$model = new ForgotPasswordForm(['login' => $this->tester->grabFixture('accounts', 'admin')['username']]);
|
/** @var Account $account */
|
||||||
|
$account = $this->tester->grabFixture('accounts', 'admin');
|
||||||
|
$model = new ForgotPasswordForm(['login' => $account->username]);
|
||||||
$this->assertTrue($model->forgotPassword(), 'form should be successfully processed');
|
$this->assertTrue($model->forgotPassword(), 'form should be successfully processed');
|
||||||
$activation = $model->getEmailActivation();
|
$activation = $model->getEmailActivation();
|
||||||
$this->assertInstanceOf(EmailActivation::class, $activation, 'getEmailActivation should return valid object instance');
|
$this->assertInstanceOf(EmailActivation::class, $activation, 'getEmailActivation should return valid object instance');
|
||||||
$this->tester->canSeeEmailIsSent(1);
|
|
||||||
/** @var \yii\swiftmailer\Message $email */
|
$this->assertTaskCreated($this->tester->grabLastQueuedJob(), $account, $activation);
|
||||||
$email = $this->tester->grabSentEmails()[0];
|
|
||||||
$body = $email->getSwiftMessage()->getBody();
|
|
||||||
$this->assertContains($activation->key, $body);
|
|
||||||
$this->assertContains('/recover-password/' . $activation->key, $body);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForgotPasswordResend() {
|
public function testForgotPasswordResend() {
|
||||||
$fixture = $this->tester->grabFixture('accounts', 'account-with-expired-forgot-password-message');
|
/** @var Account $account */
|
||||||
$model = new ForgotPasswordForm([
|
$account = $this->tester->grabFixture('accounts', 'account-with-expired-forgot-password-message');
|
||||||
'login' => $fixture['username'],
|
$model = new ForgotPasswordForm(['login' => $account->username]);
|
||||||
]);
|
|
||||||
$callTime = time();
|
$callTime = time();
|
||||||
$this->assertTrue($model->forgotPassword(), 'form should be successfully processed');
|
$this->assertTrue($model->forgotPassword(), 'form should be successfully processed');
|
||||||
$emailActivation = $model->getEmailActivation();
|
$emailActivation = $model->getEmailActivation();
|
||||||
$this->assertInstanceOf(EmailActivation::class, $emailActivation);
|
$this->assertInstanceOf(EmailActivation::class, $emailActivation);
|
||||||
$this->assertGreaterThanOrEqual($callTime, $emailActivation->created_at);
|
$this->assertGreaterThanOrEqual($callTime, $emailActivation->created_at);
|
||||||
$this->tester->canSeeEmailIsSent(1);
|
|
||||||
|
$this->assertTaskCreated($this->tester->grabLastQueuedJob(), $account, $emailActivation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SendPasswordRecoveryEmail $job
|
||||||
|
* @param Account $account
|
||||||
|
* @param EmailActivation $activation
|
||||||
|
*/
|
||||||
|
private function assertTaskCreated($job, Account $account, EmailActivation $activation) {
|
||||||
|
$this->assertInstanceOf(SendPasswordRecoveryEmail::class, $job);
|
||||||
|
$this->assertSame($account->username, $job->username);
|
||||||
|
$this->assertSame($account->email, $job->email);
|
||||||
|
$this->assertSame($account->lang, $job->locale);
|
||||||
|
$this->assertSame($activation->key, $job->code);
|
||||||
|
$this->assertSame('http://localhost/recover-password/' . $activation->key, $job->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,7 @@ use Codeception\Specify;
|
|||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
use common\models\EmailActivation;
|
use common\models\EmailActivation;
|
||||||
use common\models\UsernameHistory;
|
use common\models\UsernameHistory;
|
||||||
|
use common\tasks\SendRegistrationEmail;
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use tests\codeception\api\unit\TestCase;
|
use tests\codeception\api\unit\TestCase;
|
||||||
use tests\codeception\common\fixtures\AccountFixture;
|
use tests\codeception\common\fixtures\AccountFixture;
|
||||||
@ -40,23 +41,19 @@ class RegistrationFormTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testValidatePasswordAndRePasswordMatch() {
|
public function testValidatePasswordAndRePasswordMatch() {
|
||||||
$this->specify('error.rePassword_does_not_match if password and rePassword not match', function() {
|
$model = new RegistrationForm([
|
||||||
$model = new RegistrationForm([
|
'password' => 'enough-length',
|
||||||
'password' => 'enough-length',
|
'rePassword' => 'but-mismatch',
|
||||||
'rePassword' => 'password',
|
]);
|
||||||
]);
|
$this->assertFalse($model->validate(['rePassword']));
|
||||||
expect($model->validate(['rePassword']))->false();
|
$this->assertSame(['error.rePassword_does_not_match'], $model->getErrors('rePassword'));
|
||||||
expect($model->getErrors('rePassword'))->equals(['error.rePassword_does_not_match']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->specify('no errors if password and rePassword match', function() {
|
$model = new RegistrationForm([
|
||||||
$model = new RegistrationForm([
|
'password' => 'enough-length',
|
||||||
'password' => 'enough-length',
|
'rePassword' => 'enough-length',
|
||||||
'rePassword' => 'enough-length',
|
]);
|
||||||
]);
|
$this->assertTrue($model->validate(['rePassword']));
|
||||||
expect($model->validate(['rePassword']))->true();
|
$this->assertEmpty($model->getErrors('rePassword'));
|
||||||
expect($model->getErrors('rePassword'))->isEmpty();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSignup() {
|
public function testSignup() {
|
||||||
@ -118,12 +115,15 @@ class RegistrationFormTest extends TestCase {
|
|||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'applied_in' => $account->created_at,
|
'applied_in' => $account->created_at,
|
||||||
])->exists(), 'username history record exists in database');
|
])->exists(), 'username history record exists in database');
|
||||||
$this->tester->canSeeEmailIsSent(1);
|
|
||||||
/** @var \yii\swiftmailer\Message $email */
|
/** @var SendRegistrationEmail $job */
|
||||||
$email = $this->tester->grabSentEmails()[0];
|
$job = $this->tester->grabLastQueuedJob();
|
||||||
$body = $email->getSwiftMessage()->getBody();
|
$this->assertInstanceOf(SendRegistrationEmail::class, $job);
|
||||||
$this->assertContains($activation->key, $body);
|
$this->assertSame($account->username, $job->username);
|
||||||
$this->assertContains('/activation/' . $activation->key, $body);
|
$this->assertSame($account->email, $job->email);
|
||||||
|
$this->assertSame($account->lang, $job->locale);
|
||||||
|
$this->assertSame($activation->key, $job->code);
|
||||||
|
$this->assertSame('http://localhost/activation/' . $activation->key, $job->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mockRequest($ip = '88.225.20.236') {
|
private function mockRequest($ip = '88.225.20.236') {
|
||||||
|
@ -5,6 +5,7 @@ use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
|||||||
use api\models\authentication\RepeatAccountActivationForm;
|
use api\models\authentication\RepeatAccountActivationForm;
|
||||||
use Codeception\Specify;
|
use Codeception\Specify;
|
||||||
use common\models\EmailActivation;
|
use common\models\EmailActivation;
|
||||||
|
use common\tasks\SendRegistrationEmail;
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use tests\codeception\api\unit\TestCase;
|
use tests\codeception\api\unit\TestCase;
|
||||||
use tests\codeception\common\fixtures\AccountFixture;
|
use tests\codeception\common\fixtures\AccountFixture;
|
||||||
@ -69,19 +70,24 @@ class RepeatAccountActivationFormTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSendRepeatMessage() {
|
public function testSendRepeatMessage() {
|
||||||
$this->specify('no magic if we don\'t pass validation', function() {
|
$model = new RepeatAccountActivationForm();
|
||||||
$model = new RepeatAccountActivationForm();
|
$this->assertFalse($model->sendRepeatMessage(), 'no magic if we don\'t pass validation');
|
||||||
expect($model->sendRepeatMessage())->false();
|
$this->assertEmpty($this->tester->grabQueueJobs());
|
||||||
$this->tester->cantSeeEmailIsSent();
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->specify('successfully send new message if previous message has expired', function() {
|
/** @var \common\models\Account $account */
|
||||||
$email = $this->tester->grabFixture('accounts', 'not-activated-account-with-expired-message')['email'];
|
$account = $this->tester->grabFixture('accounts', 'not-activated-account-with-expired-message');
|
||||||
$model = new RepeatAccountActivationForm(['email' => $email]);
|
$model = new RepeatAccountActivationForm(['email' => $account->email]);
|
||||||
expect($model->sendRepeatMessage())->true();
|
$this->assertTrue($model->sendRepeatMessage());
|
||||||
expect($model->getActivation())->notNull();
|
$activation = $model->getActivation();
|
||||||
$this->tester->canSeeEmailIsSent(1);
|
$this->assertNotNull($activation);
|
||||||
});
|
/** @var SendRegistrationEmail $job */
|
||||||
|
$job = $this->tester->grabLastQueuedJob();
|
||||||
|
$this->assertInstanceOf(SendRegistrationEmail::class, $job);
|
||||||
|
$this->assertSame($account->username, $job->username);
|
||||||
|
$this->assertSame($account->email, $job->email);
|
||||||
|
$this->assertSame($account->lang, $job->locale);
|
||||||
|
$this->assertSame($activation->key, $job->code);
|
||||||
|
$this->assertSame('http://localhost/activation/' . $activation->key, $job->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,6 +5,7 @@ use api\modules\accounts\models\SendEmailVerificationForm;
|
|||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
use common\models\confirmations\CurrentEmailConfirmation;
|
use common\models\confirmations\CurrentEmailConfirmation;
|
||||||
use common\models\EmailActivation;
|
use common\models\EmailActivation;
|
||||||
|
use common\tasks\SendCurrentEmailConfirmation;
|
||||||
use tests\codeception\api\unit\TestCase;
|
use tests\codeception\api\unit\TestCase;
|
||||||
use tests\codeception\common\fixtures\AccountFixture;
|
use tests\codeception\common\fixtures\AccountFixture;
|
||||||
use tests\codeception\common\fixtures\EmailActivationFixture;
|
use tests\codeception\common\fixtures\EmailActivationFixture;
|
||||||
@ -35,11 +36,19 @@ class SendEmailVerificationFormTest extends TestCase {
|
|||||||
'password' => 'password_0',
|
'password' => 'password_0',
|
||||||
]);
|
]);
|
||||||
$this->assertTrue($model->performAction());
|
$this->assertTrue($model->performAction());
|
||||||
$this->assertTrue(EmailActivation::find()->andWhere([
|
/** @var EmailActivation $activation */
|
||||||
|
$activation = EmailActivation::findOne([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'type' => EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION,
|
'type' => EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION,
|
||||||
])->exists());
|
]);
|
||||||
$this->tester->canSeeEmailIsSent();
|
$this->assertInstanceOf(EmailActivation::class, $activation);
|
||||||
|
|
||||||
|
/** @var SendCurrentEmailConfirmation $job */
|
||||||
|
$job = $this->tester->grabLastQueuedJob();
|
||||||
|
$this->assertInstanceOf(SendCurrentEmailConfirmation::class, $job);
|
||||||
|
$this->assertSame($account->username, $job->username);
|
||||||
|
$this->assertSame($account->email, $job->email);
|
||||||
|
$this->assertSame($activation->key, $job->code);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ use api\modules\accounts\models\SendNewEmailVerificationForm;
|
|||||||
use common\models\Account;
|
use common\models\Account;
|
||||||
use common\models\confirmations\NewEmailConfirmation;
|
use common\models\confirmations\NewEmailConfirmation;
|
||||||
use common\models\EmailActivation;
|
use common\models\EmailActivation;
|
||||||
|
use common\tasks\SendNewEmailConfirmation;
|
||||||
use tests\codeception\api\unit\TestCase;
|
use tests\codeception\api\unit\TestCase;
|
||||||
use tests\codeception\common\fixtures\AccountFixture;
|
use tests\codeception\common\fixtures\AccountFixture;
|
||||||
use tests\codeception\common\fixtures\EmailActivationFixture;
|
use tests\codeception\common\fixtures\EmailActivationFixture;
|
||||||
@ -44,11 +45,19 @@ class SendNewEmailVerificationFormTest extends TestCase {
|
|||||||
Mock::func(EmailValidator::class, 'checkdnsrr')->andReturn(true);
|
Mock::func(EmailValidator::class, 'checkdnsrr')->andReturn(true);
|
||||||
$this->assertTrue($model->performAction());
|
$this->assertTrue($model->performAction());
|
||||||
$this->assertNull(EmailActivation::findOne($key));
|
$this->assertNull(EmailActivation::findOne($key));
|
||||||
$this->assertNotNull(EmailActivation::findOne([
|
/** @var EmailActivation $activation */
|
||||||
|
$activation = EmailActivation::findOne([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'type' => EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION,
|
'type' => EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION,
|
||||||
]));
|
]);
|
||||||
$this->tester->canSeeEmailIsSent();
|
$this->assertNotNull(EmailActivation::class, $activation);
|
||||||
|
|
||||||
|
/** @var SendNewEmailConfirmation $job */
|
||||||
|
$job = $this->tester->grabLastQueuedJob();
|
||||||
|
$this->assertInstanceOf(SendNewEmailConfirmation::class, $job);
|
||||||
|
$this->assertSame($account->username, $job->username);
|
||||||
|
$this->assertSame('my-new-email@ely.by', $job->email);
|
||||||
|
$this->assertSame($activation->key, $job->code);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\codeception\common\_support\queue;
|
||||||
|
|
||||||
|
use Codeception\Exception\ModuleException;
|
||||||
|
use Codeception\Module;
|
||||||
|
use Codeception\Module\Yii2;
|
||||||
|
|
||||||
|
class CodeceptionQueueHelper extends Module {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last sent message
|
||||||
|
*
|
||||||
|
* @return \yii\queue\JobInterface|null
|
||||||
|
*/
|
||||||
|
public function grabLastQueuedJob() {
|
||||||
|
$messages = $this->grabQueueJobs();
|
||||||
|
return end($messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns array of all sent amqp messages.
|
||||||
|
* Each message is `\PhpAmqpLib\Message\AMQPMessage` instance.
|
||||||
|
* Useful to perform additional checks using `Asserts` module.
|
||||||
|
*
|
||||||
|
* @param string|null $exchange
|
||||||
|
* @return \yii\queue\JobInterface[]
|
||||||
|
* @throws ModuleException
|
||||||
|
*/
|
||||||
|
public function grabQueueJobs() {
|
||||||
|
$amqp = $this->grabComponent('queue');
|
||||||
|
if (!$amqp instanceof Queue) {
|
||||||
|
throw new ModuleException($this, 'AMQP module is not mocked, can\'t test messages');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $amqp->getMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function grabComponent(string $component) {
|
||||||
|
return $this->getYii2()->grabComponent($component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getYii2(): Yii2 {
|
||||||
|
$yii2 = $this->getModule('Yii2');
|
||||||
|
if (!$yii2 instanceof Yii2) {
|
||||||
|
throw new ModuleException($this, 'Yii2 module must be configured');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $yii2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
tests/codeception/common/_support/queue/Queue.php
Normal file
32
tests/codeception/common/_support/queue/Queue.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\codeception\common\_support\queue;
|
||||||
|
|
||||||
|
use yii\base\NotSupportedException;
|
||||||
|
use yii\queue\Queue as BaseQueue;
|
||||||
|
|
||||||
|
class Queue extends BaseQueue {
|
||||||
|
|
||||||
|
private $messages = [];
|
||||||
|
|
||||||
|
public function push($job) {
|
||||||
|
$this->messages[] = $job;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function status($id) {
|
||||||
|
throw new NotSupportedException('Status is not supported in the driver.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMessages() {
|
||||||
|
return $this->messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function pushMessage($message, $ttr, $delay, $priority) {
|
||||||
|
// This function is abstract, but will be not called
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __set($name, $value) {
|
||||||
|
// Yii2 components may contains some configuration
|
||||||
|
// But we just ignore it for this mock component
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,17 +2,12 @@
|
|||||||
namespace tests\codeception\common\unit\emails;
|
namespace tests\codeception\common\unit\emails;
|
||||||
|
|
||||||
use common\emails\EmailHelper;
|
use common\emails\EmailHelper;
|
||||||
use common\models\Account;
|
|
||||||
use tests\codeception\common\unit\TestCase;
|
use tests\codeception\common\unit\TestCase;
|
||||||
|
|
||||||
class EmailHelperTest extends TestCase {
|
class EmailHelperTest extends TestCase {
|
||||||
|
|
||||||
public function testBuildTo() {
|
public function testBuildTo() {
|
||||||
/** @var Account|\Mockery\MockInterface $account */
|
$this->assertSame(['mock@ely.by' => 'username'], EmailHelper::buildTo('username', 'mock@ely.by'));
|
||||||
$account = mock(Account::class)->makePartial();
|
|
||||||
$account->username = 'mock-username';
|
|
||||||
$account->email = 'mock@ely.by';
|
|
||||||
$this->assertEquals(['mock@ely.by' => 'mock-username'], EmailHelper::buildTo($account));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\codeception\common\unit\tasks;
|
||||||
|
|
||||||
|
use common\models\Account;
|
||||||
|
use common\models\confirmations\CurrentEmailConfirmation;
|
||||||
|
use common\tasks\SendCurrentEmailConfirmation;
|
||||||
|
use tests\codeception\common\unit\TestCase;
|
||||||
|
use yii\queue\Queue;
|
||||||
|
|
||||||
|
class SendCurrentEmailConfirmationTest extends TestCase {
|
||||||
|
|
||||||
|
public function testCreateFromConfirmation() {
|
||||||
|
$account = new Account();
|
||||||
|
$account->username = 'mock-username';
|
||||||
|
$account->email = 'mock@ely.by';
|
||||||
|
$account->lang = 'id';
|
||||||
|
|
||||||
|
/** @var \Mockery\Mock|CurrentEmailConfirmation $confirmation */
|
||||||
|
$confirmation = mock(CurrentEmailConfirmation::class)->makePartial();
|
||||||
|
$confirmation->key = 'ABCDEFG';
|
||||||
|
$confirmation->shouldReceive('getAccount')->andReturn($account);
|
||||||
|
|
||||||
|
$result = SendCurrentEmailConfirmation::createFromConfirmation($confirmation);
|
||||||
|
$this->assertInstanceOf(SendCurrentEmailConfirmation::class, $result);
|
||||||
|
$this->assertSame('mock-username', $result->username);
|
||||||
|
$this->assertSame('mock@ely.by', $result->email);
|
||||||
|
$this->assertSame('ABCDEFG', $result->code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExecute() {
|
||||||
|
$task = new SendCurrentEmailConfirmation();
|
||||||
|
$task->username = 'mock-username';
|
||||||
|
$task->email = 'mock@ely.by';
|
||||||
|
$task->code = 'GFEDCBA';
|
||||||
|
|
||||||
|
$task->execute(mock(Queue::class));
|
||||||
|
|
||||||
|
$this->tester->canSeeEmailIsSent(1);
|
||||||
|
/** @var \yii\swiftmailer\Message $email */
|
||||||
|
$email = $this->tester->grabSentEmails()[0];
|
||||||
|
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||||
|
$this->assertSame('Ely.by Account change E-mail confirmation', $email->getSubject());
|
||||||
|
$children = $email->getSwiftMessage()->getChildren()[0];
|
||||||
|
$this->assertContains('GFEDCBA', $children->getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\codeception\common\unit\tasks;
|
||||||
|
|
||||||
|
use common\models\Account;
|
||||||
|
use common\models\confirmations\NewEmailConfirmation;
|
||||||
|
use common\tasks\SendNewEmailConfirmation;
|
||||||
|
use tests\codeception\common\unit\TestCase;
|
||||||
|
use yii\queue\Queue;
|
||||||
|
|
||||||
|
class SendNewEmailConfirmationTest extends TestCase {
|
||||||
|
|
||||||
|
public function testCreateFromConfirmation() {
|
||||||
|
$account = new Account();
|
||||||
|
$account->username = 'mock-username';
|
||||||
|
$account->lang = 'id';
|
||||||
|
|
||||||
|
/** @var \Mockery\Mock|NewEmailConfirmation $confirmation */
|
||||||
|
$confirmation = mock(NewEmailConfirmation::class)->makePartial();
|
||||||
|
$confirmation->key = 'ABCDEFG';
|
||||||
|
$confirmation->shouldReceive('getAccount')->andReturn($account);
|
||||||
|
$confirmation->shouldReceive('getNewEmail')->andReturn('new-email@ely.by');
|
||||||
|
|
||||||
|
$result = SendNewEmailConfirmation::createFromConfirmation($confirmation);
|
||||||
|
$this->assertInstanceOf(SendNewEmailConfirmation::class, $result);
|
||||||
|
$this->assertSame('mock-username', $result->username);
|
||||||
|
$this->assertSame('new-email@ely.by', $result->email);
|
||||||
|
$this->assertSame('ABCDEFG', $result->code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExecute() {
|
||||||
|
$task = new SendNewEmailConfirmation();
|
||||||
|
$task->username = 'mock-username';
|
||||||
|
$task->email = 'mock@ely.by';
|
||||||
|
$task->code = 'GFEDCBA';
|
||||||
|
|
||||||
|
$task->execute(mock(Queue::class));
|
||||||
|
|
||||||
|
$this->tester->canSeeEmailIsSent(1);
|
||||||
|
/** @var \yii\swiftmailer\Message $email */
|
||||||
|
$email = $this->tester->grabSentEmails()[0];
|
||||||
|
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||||
|
$this->assertSame('Ely.by Account new E-mail confirmation', $email->getSubject());
|
||||||
|
$children = $email->getSwiftMessage()->getChildren()[0];
|
||||||
|
$this->assertContains('GFEDCBA', $children->getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\codeception\common\unit\tasks;
|
||||||
|
|
||||||
|
use common\models\Account;
|
||||||
|
use common\models\confirmations\ForgotPassword;
|
||||||
|
use common\tasks\SendPasswordRecoveryEmail;
|
||||||
|
use tests\codeception\common\unit\TestCase;
|
||||||
|
use yii\queue\Queue;
|
||||||
|
|
||||||
|
class SendPasswordRecoveryEmailTest extends TestCase {
|
||||||
|
|
||||||
|
public function testCreateFromConfirmation() {
|
||||||
|
$account = new Account();
|
||||||
|
$account->username = 'mock-username';
|
||||||
|
$account->email = 'mock@ely.by';
|
||||||
|
$account->lang = 'id';
|
||||||
|
|
||||||
|
/** @var \Mockery\Mock|ForgotPassword $confirmation */
|
||||||
|
$confirmation = mock(ForgotPassword::class)->makePartial();
|
||||||
|
$confirmation->key = 'ABCDEFG';
|
||||||
|
$confirmation->shouldReceive('getAccount')->andReturn($account);
|
||||||
|
|
||||||
|
$result = SendPasswordRecoveryEmail::createFromConfirmation($confirmation);
|
||||||
|
$this->assertInstanceOf(SendPasswordRecoveryEmail::class, $result);
|
||||||
|
$this->assertSame('mock-username', $result->username);
|
||||||
|
$this->assertSame('mock@ely.by', $result->email);
|
||||||
|
$this->assertSame('ABCDEFG', $result->code);
|
||||||
|
$this->assertSame('http://localhost/recover-password/ABCDEFG', $result->link);
|
||||||
|
$this->assertSame('id', $result->locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExecute() {
|
||||||
|
$task = new SendPasswordRecoveryEmail();
|
||||||
|
$task->username = 'mock-username';
|
||||||
|
$task->email = 'mock@ely.by';
|
||||||
|
$task->code = 'GFEDCBA';
|
||||||
|
$task->link = 'https://account.ely.by/recover-password/ABCDEFG';
|
||||||
|
$task->locale = 'ru';
|
||||||
|
|
||||||
|
$task->execute(mock(Queue::class));
|
||||||
|
|
||||||
|
$this->tester->canSeeEmailIsSent(1);
|
||||||
|
/** @var \yii\swiftmailer\Message $email */
|
||||||
|
$email = $this->tester->grabSentEmails()[0];
|
||||||
|
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||||
|
$this->assertSame('Ely.by Account forgot password', $email->getSubject());
|
||||||
|
$body = $email->getSwiftMessage()->getBody();
|
||||||
|
$this->assertContains('Привет, mock-username', $body);
|
||||||
|
$this->assertContains('GFEDCBA', $body);
|
||||||
|
$this->assertContains('https://account.ely.by/recover-password/ABCDEFG', $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
namespace tests\codeception\common\unit\tasks;
|
||||||
|
|
||||||
|
use common\models\Account;
|
||||||
|
use common\models\confirmations\RegistrationConfirmation;
|
||||||
|
use common\tasks\SendRegistrationEmail;
|
||||||
|
use tests\codeception\common\unit\TestCase;
|
||||||
|
use yii\queue\Queue;
|
||||||
|
|
||||||
|
class SendRegistrationEmailTest extends TestCase {
|
||||||
|
|
||||||
|
public function testCreateFromConfirmation() {
|
||||||
|
$account = new Account();
|
||||||
|
$account->username = 'mock-username';
|
||||||
|
$account->email = 'mock@ely.by';
|
||||||
|
$account->lang = 'ru';
|
||||||
|
|
||||||
|
/** @var \Mockery\Mock|RegistrationConfirmation $confirmation */
|
||||||
|
$confirmation = mock(RegistrationConfirmation::class)->makePartial();
|
||||||
|
$confirmation->key = 'ABCDEFG';
|
||||||
|
$confirmation->shouldReceive('getAccount')->andReturn($account);
|
||||||
|
|
||||||
|
$result = SendRegistrationEmail::createFromConfirmation($confirmation);
|
||||||
|
$this->assertInstanceOf(SendRegistrationEmail::class, $result);
|
||||||
|
$this->assertSame('mock-username', $result->username);
|
||||||
|
$this->assertSame('mock@ely.by', $result->email);
|
||||||
|
$this->assertSame('ABCDEFG', $result->code);
|
||||||
|
$this->assertSame('http://localhost/activation/ABCDEFG', $result->link);
|
||||||
|
$this->assertSame('ru', $result->locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExecute() {
|
||||||
|
$task = new SendRegistrationEmail();
|
||||||
|
$task->username = 'mock-username';
|
||||||
|
$task->email = 'mock@ely.by';
|
||||||
|
$task->code = 'GFEDCBA';
|
||||||
|
$task->link = 'https://account.ely.by/activation/ABCDEFG';
|
||||||
|
$task->locale = 'ru';
|
||||||
|
|
||||||
|
$task->execute(mock(Queue::class));
|
||||||
|
|
||||||
|
$this->tester->canSeeEmailIsSent(1);
|
||||||
|
/** @var \yii\swiftmailer\Message $email */
|
||||||
|
$email = $this->tester->grabSentEmails()[0];
|
||||||
|
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||||
|
$this->assertSame('Ely.by Account registration', $email->getSubject());
|
||||||
|
$body = $email->getSwiftMessage()->getBody();
|
||||||
|
$this->assertContains('Привет, mock-username', $body);
|
||||||
|
$this->assertContains('GFEDCBA', $body);
|
||||||
|
$this->assertContains('https://account.ely.by/activation/ABCDEFG', $body);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,9 @@ return [
|
|||||||
'namespace' => 'tests\codeception\common\fixtures',
|
'namespace' => 'tests\codeception\common\fixtures',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'params' => [
|
||||||
|
'fromEmail' => 'ely@ely.by',
|
||||||
|
],
|
||||||
'components' => [
|
'components' => [
|
||||||
'urlManager' => [
|
'urlManager' => [
|
||||||
'showScriptName' => true,
|
'showScriptName' => true,
|
||||||
@ -20,6 +23,9 @@ return [
|
|||||||
'amqp' => [
|
'amqp' => [
|
||||||
'class' => tests\codeception\common\_support\amqp\TestComponent::class,
|
'class' => tests\codeception\common\_support\amqp\TestComponent::class,
|
||||||
],
|
],
|
||||||
|
'queue' => [
|
||||||
|
'class' => tests\codeception\common\_support\queue\Queue::class,
|
||||||
|
],
|
||||||
'sentry' => [
|
'sentry' => [
|
||||||
'enabled' => false,
|
'enabled' => false,
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user