mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Наведён порядок в моделях проекта
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace tests\codeception\api\models;
 | 
			
		||||
namespace tests\codeception\api\models\authentication;
 | 
			
		||||
 | 
			
		||||
use api\models\ConfirmEmailForm;
 | 
			
		||||
use api\models\authentication\ConfirmEmailForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\Account;
 | 
			
		||||
use common\models\EmailActivation;
 | 
			
		||||
@@ -10,7 +10,7 @@ use tests\codeception\common\fixtures\EmailActivationFixture;
 | 
			
		||||
use Yii;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @property array $emailActivations
 | 
			
		||||
 * @property EmailActivationFixture $emailActivations
 | 
			
		||||
 */
 | 
			
		||||
class ConfirmEmailFormTest extends DbTestCase {
 | 
			
		||||
    use Specify;
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace codeception\api\unit\models;
 | 
			
		||||
namespace codeception\api\unit\models\authentication;
 | 
			
		||||
 | 
			
		||||
use api\models\ForgotPasswordForm;
 | 
			
		||||
use api\models\authentication\ForgotPasswordForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\EmailActivation;
 | 
			
		||||
use tests\codeception\api\unit\DbTestCase;
 | 
			
		||||
@@ -10,8 +10,8 @@ use tests\codeception\common\fixtures\EmailActivationFixture;
 | 
			
		||||
use Yii;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @property array $accounts
 | 
			
		||||
 * @property array $emailActivations
 | 
			
		||||
 * @property AccountFixture $accounts
 | 
			
		||||
 * @property EmailActivationFixture $emailActivations
 | 
			
		||||
 */
 | 
			
		||||
class ForgotPasswordFormTest extends DbTestCase {
 | 
			
		||||
    use Specify;
 | 
			
		||||
@@ -76,7 +76,7 @@ class ForgotPasswordFormTest extends DbTestCase {
 | 
			
		||||
 | 
			
		||||
    public function testValidateFrequency() {
 | 
			
		||||
        $this->specify('error.account_not_activated if recently was message', function() {
 | 
			
		||||
            $model = new DummyForgotPasswordForm([
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'login' => $this->accounts['admin']['username'],
 | 
			
		||||
                'key' => $this->emailActivations['freshPasswordRecovery']['key'],
 | 
			
		||||
            ]);
 | 
			
		||||
@@ -86,7 +86,7 @@ class ForgotPasswordFormTest extends DbTestCase {
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->specify('empty errors if email was sent a long time ago', function() {
 | 
			
		||||
            $model = new DummyForgotPasswordForm([
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'login' => $this->accounts['admin']['username'],
 | 
			
		||||
                'key' => $this->emailActivations['oldPasswordRecovery']['key'],
 | 
			
		||||
            ]);
 | 
			
		||||
@@ -96,7 +96,7 @@ class ForgotPasswordFormTest extends DbTestCase {
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->specify('empty errors if previous confirmation model not founded', function() {
 | 
			
		||||
            $model = new DummyForgotPasswordForm([
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'login' => $this->accounts['admin']['username'],
 | 
			
		||||
                'key' => 'invalid-key',
 | 
			
		||||
            ]);
 | 
			
		||||
@@ -136,14 +136,18 @@ class ForgotPasswordFormTest extends DbTestCase {
 | 
			
		||||
        return Yii::getAlias($mailer->fileTransportPath) . '/testing_message.eml';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $params
 | 
			
		||||
     * @return ForgotPasswordForm
 | 
			
		||||
     */
 | 
			
		||||
    private function createModel(array $params = []) {
 | 
			
		||||
        return new class($params) extends ForgotPasswordForm {
 | 
			
		||||
            public $key;
 | 
			
		||||
 | 
			
		||||
class DummyForgotPasswordForm extends ForgotPasswordForm {
 | 
			
		||||
 | 
			
		||||
    public $key;
 | 
			
		||||
 | 
			
		||||
    public function getEmailActivation() {
 | 
			
		||||
        return EmailActivation::findOne($this->key);
 | 
			
		||||
            public function getEmailActivation() {
 | 
			
		||||
                return EmailActivation::findOne($this->key);
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,18 +1,18 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace tests\codeception\api\models;
 | 
			
		||||
namespace tests\codeception\api\models\authentication;
 | 
			
		||||
 | 
			
		||||
use api\models\LoginForm;
 | 
			
		||||
use api\models\authentication\LoginForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\Account;
 | 
			
		||||
use tests\codeception\api\unit\DbTestCase;
 | 
			
		||||
use tests\codeception\api\unit\TestCase;
 | 
			
		||||
use Yii;
 | 
			
		||||
 | 
			
		||||
class LoginFormTest extends DbTestCase {
 | 
			
		||||
class LoginFormTest extends TestCase {
 | 
			
		||||
    use Specify;
 | 
			
		||||
 | 
			
		||||
    public function testValidateLogin() {
 | 
			
		||||
        $this->specify('error.login_not_exist if login not exists', function() {
 | 
			
		||||
            $model = new DummyLoginForm([
 | 
			
		||||
        $this->specify('error.login_not_exist if login not exists', function () {
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'login' => 'mr-test',
 | 
			
		||||
                'account' => null,
 | 
			
		||||
            ]);
 | 
			
		||||
@@ -20,8 +20,8 @@ class LoginFormTest extends DbTestCase {
 | 
			
		||||
            expect($model->getErrors('login'))->equals(['error.login_not_exist']);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->specify('no errors if login exists', function() {
 | 
			
		||||
            $model = new DummyLoginForm([
 | 
			
		||||
        $this->specify('no errors if login exists', function () {
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'login' => 'mr-test',
 | 
			
		||||
                'account' => new Account(),
 | 
			
		||||
            ]);
 | 
			
		||||
@@ -31,8 +31,8 @@ class LoginFormTest extends DbTestCase {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testValidatePassword() {
 | 
			
		||||
        $this->specify('error.password_incorrect if password invalid', function() {
 | 
			
		||||
            $model = new DummyLoginForm([
 | 
			
		||||
        $this->specify('error.password_incorrect if password invalid', function () {
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'password' => '87654321',
 | 
			
		||||
                'account' => new Account(['password' => '12345678']),
 | 
			
		||||
            ]);
 | 
			
		||||
@@ -40,8 +40,8 @@ class LoginFormTest extends DbTestCase {
 | 
			
		||||
            expect($model->getErrors('password'))->equals(['error.password_incorrect']);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->specify('no errors if password valid', function() {
 | 
			
		||||
            $model = new DummyLoginForm([
 | 
			
		||||
        $this->specify('no errors if password valid', function () {
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'password' => '12345678',
 | 
			
		||||
                'account' => new Account(['password' => '12345678']),
 | 
			
		||||
            ]);
 | 
			
		||||
@@ -51,16 +51,16 @@ class LoginFormTest extends DbTestCase {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testValidateActivity() {
 | 
			
		||||
        $this->specify('error.account_not_activated if account in not activated state', function() {
 | 
			
		||||
            $model = new DummyLoginForm([
 | 
			
		||||
        $this->specify('error.account_not_activated if account in not activated state', function () {
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'account' => new Account(['status' => Account::STATUS_REGISTERED]),
 | 
			
		||||
            ]);
 | 
			
		||||
            $model->validateActivity('login');
 | 
			
		||||
            expect($model->getErrors('login'))->equals(['error.account_not_activated']);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->specify('no errors if account active', function() {
 | 
			
		||||
            $model = new DummyLoginForm([
 | 
			
		||||
        $this->specify('no errors if account active', function () {
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'account' => new Account(['status' => Account::STATUS_ACTIVE]),
 | 
			
		||||
            ]);
 | 
			
		||||
            $model->validateActivity('login');
 | 
			
		||||
@@ -70,7 +70,7 @@ class LoginFormTest extends DbTestCase {
 | 
			
		||||
 | 
			
		||||
    public function testLogin() {
 | 
			
		||||
        $this->specify('user should be able to login with correct username and password', function () {
 | 
			
		||||
            $model = new DummyLoginForm([
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'login' => 'erickskrauch',
 | 
			
		||||
                'password' => '12345678',
 | 
			
		||||
                'account' => new Account([
 | 
			
		||||
@@ -84,18 +84,22 @@ class LoginFormTest extends DbTestCase {
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $params
 | 
			
		||||
     * @return LoginForm
 | 
			
		||||
     */
 | 
			
		||||
    private function createModel(array $params = []) {
 | 
			
		||||
        return new class($params) extends LoginForm {
 | 
			
		||||
            private $_account;
 | 
			
		||||
 | 
			
		||||
class DummyLoginForm extends LoginForm {
 | 
			
		||||
            public function setAccount($value) {
 | 
			
		||||
                $this->_account = $value;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
    private $_account;
 | 
			
		||||
 | 
			
		||||
    public function setAccount($value) {
 | 
			
		||||
        $this->_account = $value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getAccount() {
 | 
			
		||||
        return $this->_account;
 | 
			
		||||
            public function getAccount() {
 | 
			
		||||
                return $this->_account;
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace tests\codeception\api\models;
 | 
			
		||||
namespace tests\codeception\api\models\authentication;
 | 
			
		||||
 | 
			
		||||
use api\models\RecoverPasswordForm;
 | 
			
		||||
use api\models\authentication\RecoverPasswordForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\Account;
 | 
			
		||||
use common\models\EmailActivation;
 | 
			
		||||
@@ -10,7 +10,7 @@ use tests\codeception\common\fixtures\EmailActivationFixture;
 | 
			
		||||
use Yii;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @property array $emailActivations
 | 
			
		||||
 * @property EmailActivationFixture $emailActivations
 | 
			
		||||
 */
 | 
			
		||||
class RecoverPasswordFormTest extends DbTestCase {
 | 
			
		||||
    use Specify;
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace tests\codeception\api\models;
 | 
			
		||||
namespace tests\codeception\api\models\authentication;
 | 
			
		||||
 | 
			
		||||
use api\models\RegistrationForm;
 | 
			
		||||
use api\models\authentication\RegistrationForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\Account;
 | 
			
		||||
use common\models\EmailActivation;
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace tests\codeception\api\models;
 | 
			
		||||
namespace tests\codeception\api\models\authentication;
 | 
			
		||||
 | 
			
		||||
use api\models\RepeatAccountActivationForm;
 | 
			
		||||
use api\models\authentication\RepeatAccountActivationForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\EmailActivation;
 | 
			
		||||
use tests\codeception\api\unit\DbTestCase;
 | 
			
		||||
@@ -68,7 +68,7 @@ class RepeatAccountActivationFormTest extends DbTestCase {
 | 
			
		||||
 | 
			
		||||
    public function testValidateExistsActivation() {
 | 
			
		||||
        $this->specify('error.recently_sent_message if passed email has recently sent message', function() {
 | 
			
		||||
            $model = new DummyRepeatAccountActivationForm([
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'emailKey' => $this->activations['freshRegistrationConfirmation']['key'],
 | 
			
		||||
            ]);
 | 
			
		||||
            $model->validateExistsActivation('email');
 | 
			
		||||
@@ -76,7 +76,7 @@ class RepeatAccountActivationFormTest extends DbTestCase {
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $this->specify('no errors if passed email has expired activation message', function() {
 | 
			
		||||
            $model = new DummyRepeatAccountActivationForm([
 | 
			
		||||
            $model = $this->createModel([
 | 
			
		||||
                'emailKey' => $this->activations['oldRegistrationConfirmation']['key'],
 | 
			
		||||
            ]);
 | 
			
		||||
            $model->validateExistsActivation('email');
 | 
			
		||||
@@ -107,14 +107,18 @@ class RepeatAccountActivationFormTest extends DbTestCase {
 | 
			
		||||
        return Yii::getAlias($mailer->fileTransportPath) . '/testing_message.eml';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array $params
 | 
			
		||||
     * @return RepeatAccountActivationForm
 | 
			
		||||
     */
 | 
			
		||||
    private function createModel(array $params = []) {
 | 
			
		||||
        return new class($params) extends RepeatAccountActivationForm {
 | 
			
		||||
            public $emailKey;
 | 
			
		||||
 | 
			
		||||
class DummyRepeatAccountActivationForm extends RepeatAccountActivationForm {
 | 
			
		||||
 | 
			
		||||
    public $emailKey;
 | 
			
		||||
 | 
			
		||||
    public function getActivation() {
 | 
			
		||||
        return EmailActivation::findOne($this->emailKey);
 | 
			
		||||
            public function getActivation() {
 | 
			
		||||
                return EmailActivation::findOne($this->emailKey);
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace tests\codeception\api\models;
 | 
			
		||||
namespace tests\codeception\api\models\profile;
 | 
			
		||||
 | 
			
		||||
use api\models\ChangePasswordForm;
 | 
			
		||||
use api\models\profile\ChangePasswordForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\Account;
 | 
			
		||||
use tests\codeception\api\unit\DbTestCase;
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
namespace tests\codeception\api\models;
 | 
			
		||||
namespace tests\codeception\api\models\profile;
 | 
			
		||||
 | 
			
		||||
use api\models\ChangeUsernameForm;
 | 
			
		||||
use api\models\profile\ChangeUsernameForm;
 | 
			
		||||
use Codeception\Specify;
 | 
			
		||||
use common\models\Account;
 | 
			
		||||
use common\models\UsernameHistory;
 | 
			
		||||
		Reference in New Issue
	
	Block a user