mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Отрефакторены тесты для форм
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
namespace api\models;
|
||||
|
||||
use api\models\base\ApiForm;
|
||||
use api\models\base\PasswordProtectedForm;
|
||||
use common\models\Account;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class ChangePasswordForm extends ApiForm {
|
||||
|
||||
public $password;
|
||||
class ChangePasswordForm extends PasswordProtectedForm {
|
||||
|
||||
public $newPassword;
|
||||
|
||||
@@ -18,33 +18,16 @@ class ChangePasswordForm extends ApiForm {
|
||||
*/
|
||||
private $_account;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(Account $account, array $config = []) {
|
||||
$this->_account = $account;
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules() {
|
||||
return [
|
||||
['password', 'required', 'message' => 'error.password_required'],
|
||||
return ArrayHelper::merge(parent::rules(), [
|
||||
['newPassword', 'required', 'message' => 'error.newPassword_required'],
|
||||
['newRePassword', 'required', 'message' => 'error.newRePassword_required'],
|
||||
['password', 'validatePassword'],
|
||||
['newPassword', 'string', 'min' => 8, 'tooShort' => 'error.password_too_short'],
|
||||
['newRePassword', 'validatePasswordAndRePasswordMatch'],
|
||||
];
|
||||
}
|
||||
|
||||
public function validatePassword($attribute) {
|
||||
if (!$this->hasErrors() && !$this->_account->validatePassword($this->$attribute)) {
|
||||
$this->addError($attribute, 'error.' . $attribute . '_incorrect');
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
public function validatePasswordAndRePasswordMatch($attribute) {
|
||||
@@ -69,4 +52,17 @@ class ChangePasswordForm extends ApiForm {
|
||||
return $account->save();
|
||||
}
|
||||
|
||||
protected function getAccount() {
|
||||
return $this->_account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(Account $account, array $config = []) {
|
||||
$this->_account = $account;
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user