2017-11-27 04:59:15 +05:30
|
|
|
<?php
|
2019-12-14 00:57:13 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace common\tests\unit\tasks;
|
2017-11-27 04:59:15 +05:30
|
|
|
|
|
|
|
use common\models\Account;
|
2019-12-14 00:57:13 +05:30
|
|
|
use common\models\AccountQuery;
|
2017-11-27 04:59:15 +05:30
|
|
|
use common\models\confirmations\NewEmailConfirmation;
|
|
|
|
use common\tasks\SendNewEmailConfirmation;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\unit\TestCase;
|
2017-11-27 04:59:15 +05:30
|
|
|
use yii\queue\Queue;
|
|
|
|
|
|
|
|
class SendNewEmailConfirmationTest extends TestCase {
|
|
|
|
|
|
|
|
public function testCreateFromConfirmation() {
|
|
|
|
$account = new Account();
|
|
|
|
$account->username = 'mock-username';
|
|
|
|
$account->lang = 'id';
|
|
|
|
|
2019-12-14 00:57:13 +05:30
|
|
|
$accountQuery = $this->createMock(AccountQuery::class);
|
|
|
|
$accountQuery->method('findFor')->willReturn($account);
|
|
|
|
|
|
|
|
$confirmation = $this->createPartialMock(NewEmailConfirmation::class, ['getAccount']);
|
|
|
|
$confirmation->method('getAccount')->willReturn($accountQuery);
|
|
|
|
$confirmation->setNewEmail('new-email@ely.by');
|
2017-11-27 04:59:15 +05:30
|
|
|
$confirmation->key = 'ABCDEFG';
|
|
|
|
|
|
|
|
$result = SendNewEmailConfirmation::createFromConfirmation($confirmation);
|
|
|
|
$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';
|
|
|
|
|
2019-12-14 00:57:13 +05:30
|
|
|
$task->execute($this->createMock(Queue::class));
|
2017-11-27 04:59:15 +05:30
|
|
|
|
|
|
|
$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];
|
2019-08-02 18:27:17 +05:30
|
|
|
$this->assertStringContainsString('GFEDCBA', $children->getBody());
|
2017-11-27 04:59:15 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|