mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Merge branch 'master' into profile
This commit is contained in:
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\FunctionalTester $actor
|
||||
*/
|
||||
class EmailConfirmRoute extends BasePage {
|
||||
|
||||
public $route = ['signup/confirm'];
|
||||
|
||||
public function confirm($key = '') {
|
||||
$this->actor->sendPOST($this->getUrl(), [
|
||||
'key' => $key,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\FunctionalTester $actor
|
||||
*/
|
||||
class RegisterRoute extends BasePage {
|
||||
|
||||
public $route = ['signup/index'];
|
||||
|
||||
public function send(array $registrationData) {
|
||||
$this->actor->sendPOST($this->getUrl(), $registrationData);
|
||||
}
|
||||
|
||||
}
|
28
tests/codeception/api/_pages/SignupRoute.php
Normal file
28
tests/codeception/api/_pages/SignupRoute.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\_pages;
|
||||
|
||||
use yii\codeception\BasePage;
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\FunctionalTester $actor
|
||||
*/
|
||||
class SignupRoute extends BasePage {
|
||||
|
||||
public function register(array $registrationData) {
|
||||
$this->route = ['signup/index'];
|
||||
$this->actor->sendPOST($this->getUrl(), $registrationData);
|
||||
}
|
||||
|
||||
public function sendRepeatMessage($email = '') {
|
||||
$this->route = ['signup/repeat-message'];
|
||||
$this->actor->sendPOST($this->getUrl(), ['email' => $email]);
|
||||
}
|
||||
|
||||
public function confirm($key = '') {
|
||||
$this->route = ['signup/confirm'];
|
||||
$this->actor->sendPOST($this->getUrl(), [
|
||||
'key' => $key,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
namespace tests\codeception\api;
|
||||
|
||||
use tests\codeception\api\_pages\EmailConfirmRoute;
|
||||
use tests\codeception\api\_pages\SignupRoute;
|
||||
|
||||
class EmailConfirmationCest {
|
||||
|
||||
public function testLoginEmailOrUsername(FunctionalTester $I) {
|
||||
$route = new EmailConfirmRoute($I);
|
||||
$route = new SignupRoute($I);
|
||||
|
||||
$I->wantTo('see error.key_is_required expected if key is not set');
|
||||
$route->confirm();
|
||||
@ -28,7 +28,7 @@ class EmailConfirmationCest {
|
||||
}
|
||||
|
||||
public function testLoginByEmailCorrect(FunctionalTester $I) {
|
||||
$route = new EmailConfirmRoute($I);
|
||||
$route = new SignupRoute($I);
|
||||
|
||||
$I->wantTo('confirm my email using correct activation key');
|
||||
$route->confirm('HABGCABHJ1234HBHVD');
|
||||
|
@ -43,6 +43,7 @@ class LoginCest {
|
||||
'login' => 'error.account_not_activated',
|
||||
],
|
||||
]);
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.email');
|
||||
|
||||
$I->wantTo('don\'t see errors on login field if username is correct and exists in database');
|
||||
$route->login('Admin');
|
||||
|
@ -3,7 +3,7 @@ namespace tests\codeception\api\functional;
|
||||
|
||||
use Codeception\Specify;
|
||||
use common\models\Account;
|
||||
use tests\codeception\api\_pages\RegisterRoute;
|
||||
use tests\codeception\api\_pages\SignupRoute;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class RegisterCest {
|
||||
@ -16,10 +16,10 @@ class RegisterCest {
|
||||
}
|
||||
|
||||
public function testIncorrectRegistration(FunctionalTester $I) {
|
||||
$route = new RegisterRoute($I);
|
||||
$route = new SignupRoute($I);
|
||||
|
||||
$I->wantTo('get error.you_must_accept_rules if we don\'t accept rules');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'ErickSkrauch',
|
||||
'email' => 'erickskrauch@ely.by',
|
||||
'password' => 'some_password',
|
||||
@ -33,7 +33,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('don\'t see error.you_must_accept_rules if we accept rules');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'rulesAgreement' => true,
|
||||
]);
|
||||
$I->cantSeeResponseContainsJson([
|
||||
@ -43,7 +43,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('see error.username_required if username is not set');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => '',
|
||||
'email' => '',
|
||||
'password' => '',
|
||||
@ -58,7 +58,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('don\'t see error.username_required if username is not set');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => '',
|
||||
'password' => '',
|
||||
@ -72,7 +72,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('see error.email_required if email is not set');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => '',
|
||||
'password' => '',
|
||||
@ -87,7 +87,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('see error.email_invalid if email is set, but invalid');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'invalid@email',
|
||||
'password' => '',
|
||||
@ -102,7 +102,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('see error.email_invalid if email is set, valid, but domain doesn\'t exist or don\'t have mx record');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'invalid@govnomail.com',
|
||||
'password' => '',
|
||||
@ -117,7 +117,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('see error.email_not_available if email is set, fully valid, but not available for registration');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'admin@ely.by',
|
||||
'password' => '',
|
||||
@ -132,7 +132,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('don\'t see errors on email if all valid');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'erickskrauch@ely.by',
|
||||
'password' => '',
|
||||
@ -142,7 +142,7 @@ class RegisterCest {
|
||||
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.email');
|
||||
|
||||
$I->wantTo('see error.password_required if password is not set');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'erickskrauch@ely.by',
|
||||
'password' => '',
|
||||
@ -157,7 +157,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('see error.password_too_short before it will be compared with rePassword');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'correct-email@ely.by',
|
||||
'password' => 'short',
|
||||
@ -173,7 +173,7 @@ class RegisterCest {
|
||||
$I->cantSeeResponseJsonMatchesJsonPath('$.errors.rePassword');
|
||||
|
||||
$I->wantTo('see error.rePassword_required if password valid and rePassword not set');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'correct-email@ely.by',
|
||||
'password' => 'valid-password',
|
||||
@ -188,7 +188,7 @@ class RegisterCest {
|
||||
]);
|
||||
|
||||
$I->wantTo('see error.rePassword_does_not_match if password valid and rePassword donen\'t match it');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'valid_nickname',
|
||||
'email' => 'correct-email@ely.by',
|
||||
'password' => 'valid-password',
|
||||
@ -205,10 +205,10 @@ class RegisterCest {
|
||||
}
|
||||
|
||||
public function testUserCorrectRegistration(FunctionalTester $I) {
|
||||
$route = new RegisterRoute($I);
|
||||
$route = new SignupRoute($I);
|
||||
|
||||
$I->wantTo('ensure that signup works');
|
||||
$route->send([
|
||||
$route->register([
|
||||
'username' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'password' => 'some_password',
|
||||
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\functional;
|
||||
|
||||
use Codeception\Specify;
|
||||
use tests\codeception\api\_pages\SignupRoute;
|
||||
use tests\codeception\api\FunctionalTester;
|
||||
|
||||
class RepeatAccountActivationCest {
|
||||
|
||||
public function testInvalidEmailOrAccountState(FunctionalTester $I) {
|
||||
$route = new SignupRoute($I);
|
||||
|
||||
$I->wantTo('error.email_required on empty for submitting');
|
||||
$route->sendRepeatMessage();
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'email' => 'error.email_required',
|
||||
],
|
||||
]);
|
||||
|
||||
$I->wantTo('error.email_not_found if email is not presented in db');
|
||||
$route->sendRepeatMessage('im-not@exists.net');
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'email' => 'error.email_not_found',
|
||||
],
|
||||
]);
|
||||
|
||||
$I->wantTo('error.account_already_activated if passed email matches with already activated account');
|
||||
$route->sendRepeatMessage('admin@ely.by');
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'email' => 'error.account_already_activated',
|
||||
],
|
||||
]);
|
||||
|
||||
$I->wantTo('error.recently_sent_message if last message was send too recently');
|
||||
$route->sendRepeatMessage('achristiansen@gmail.com');
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson([
|
||||
'success' => false,
|
||||
'errors' => [
|
||||
'email' => 'error.recently_sent_message',
|
||||
],
|
||||
]);
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
||||
$I->canSeeResponseJsonMatchesJsonPath('$.data.repeatFrequency');
|
||||
}
|
||||
|
||||
public function testSuccess(FunctionalTester $I) {
|
||||
$route = new SignupRoute($I);
|
||||
|
||||
$I->wantTo('successfully resend account activation message');
|
||||
$route->sendRepeatMessage('jon@ely.by');
|
||||
$I->canSeeResponseCodeIs(200);
|
||||
$I->canSeeResponseIsJson();
|
||||
$I->canSeeResponseContainsJson(['success' => true]);
|
||||
$I->cantSeeResponseJsonMatchesJsonPath('$.errors');
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\models;
|
||||
|
||||
use api\models\RepeatAccountActivationForm;
|
||||
use Codeception\Specify;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
use tests\codeception\common\fixtures\EmailActivationFixture;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* @property array $accounts
|
||||
* @property array $activations
|
||||
*/
|
||||
class RepeatAccountActivationFormTest extends DbTestCase {
|
||||
use Specify;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
/** @var \yii\swiftmailer\Mailer $mailer */
|
||||
$mailer = Yii::$app->mailer;
|
||||
$mailer->fileTransportCallback = function () {
|
||||
return 'testing_message.eml';
|
||||
};
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
if (file_exists($this->getMessageFile())) {
|
||||
unlink($this->getMessageFile());
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function fixtures() {
|
||||
return [
|
||||
'accounts' => [
|
||||
'class' => AccountFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
|
||||
],
|
||||
'activations' => [
|
||||
'class' => EmailActivationFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/email-activations.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testValidateEmailForAccount() {
|
||||
$this->specify('error.email_not_found if passed valid email, but it don\'t exists in database', function() {
|
||||
$model = new RepeatAccountActivationForm(['email' => 'me-is-not@exists.net']);
|
||||
$model->validateEmailForAccount('email');
|
||||
expect($model->getErrors('email'))->equals(['error.email_not_found']);
|
||||
});
|
||||
|
||||
$this->specify('error.account_already_activated if passed valid email, but account already activated', function() {
|
||||
$model = new RepeatAccountActivationForm(['email' => $this->accounts['admin']['email']]);
|
||||
$model->validateEmailForAccount('email');
|
||||
expect($model->getErrors('email'))->equals(['error.account_already_activated']);
|
||||
});
|
||||
|
||||
$this->specify('no errors if passed valid email for not activated account', function() {
|
||||
$model = new RepeatAccountActivationForm(['email' => $this->accounts['not-activated-account']['email']]);
|
||||
$model->validateEmailForAccount('email');
|
||||
expect($model->getErrors('email'))->isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
public function testValidateExistsActivation() {
|
||||
$this->specify('error.recently_sent_message if passed email has recently sent message', function() {
|
||||
$model = new RepeatAccountActivationForm(['email' => $this->accounts['not-activated-account']['email']]);
|
||||
$model->validateExistsActivation('email');
|
||||
expect($model->getErrors('email'))->equals(['error.recently_sent_message']);
|
||||
});
|
||||
|
||||
$this->specify('no errors if passed email has expired activation message', function() {
|
||||
$email = $this->accounts['not-activated-account-with-expired-message']['email'];
|
||||
$model = new RepeatAccountActivationForm(['email' => $email]);
|
||||
$model->validateExistsActivation('email');
|
||||
expect($model->getErrors('email'))->isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
public function testSendRepeatMessage() {
|
||||
$this->specify('no magic if we don\'t pass validation', function() {
|
||||
$model = new RepeatAccountActivationForm();
|
||||
expect($model->sendRepeatMessage())->false();
|
||||
expect_file($this->getMessageFile())->notExists();
|
||||
});
|
||||
|
||||
$this->specify('successfully send new message if previous message has expired', function() {
|
||||
$email = $this->accounts['not-activated-account-with-expired-message']['email'];
|
||||
$model = new RepeatAccountActivationForm(['email' => $email]);
|
||||
expect($model->sendRepeatMessage())->true();
|
||||
expect($model->getActiveActivation())->notNull();
|
||||
expect_file($this->getMessageFile())->exists();
|
||||
});
|
||||
}
|
||||
|
||||
private function getMessageFile() {
|
||||
/** @var \yii\swiftmailer\Mailer $mailer */
|
||||
$mailer = Yii::$app->mailer;
|
||||
|
||||
return Yii::getAlias($mailer->fileTransportPath) . '/testing_message.eml';
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user