Добавлена поддержка запоминания языка для аккаунта

Обновлена минимальная версия Yii2
Удалено немного хлама от Yii2 Advanced
Исправлены некоторые тесты
This commit is contained in:
ErickSkrauch
2016-05-13 12:03:00 +03:00
parent 65382fa1ce
commit ecd92b8fda
22 changed files with 175 additions and 124 deletions

View File

@@ -26,8 +26,12 @@ class AccountsCurrentCest {
'id' => 1,
'username' => 'Admin',
'email' => 'admin@ely.by',
'lang' => 'en',
'shouldChangePassword' => false,
'isActive' => true,
'hasMojangUsernameCollision' => false,
]);
$I->canSeeResponseJsonMatchesJsonPath('$.passwordChangedAt');
}
}

View File

@@ -214,6 +214,7 @@ class RegisterCest {
'password' => 'some_password',
'rePassword' => 'some_password',
'rulesAgreement' => true,
'lang' => 'ru',
]);
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();

View File

@@ -85,9 +85,10 @@ class ChangePasswordFormTest extends DbTestCase {
'newRePassword' => 'my-new-password',
]);
$this->specify('successfully change password with legacy hash strategy', function() use ($model, $account) {
$callTime = time();
expect('form should return true', $model->changePassword())->true();
expect('new password should be successfully stored into account', $account->validatePassword('my-new-password'))->true();
expect('password change time updated', $account->password_changed_at)->greaterOrEquals(time() - 2);
expect('password change time updated', $account->password_changed_at)->greaterOrEquals($callTime);
});
}

View File

@@ -68,19 +68,43 @@ class RegistrationFormTest extends DbTestCase {
'password' => 'some_password',
'rePassword' => 'some_password',
'rulesAgreement' => true,
'lang' => 'ru',
]);
$user = $model->signup();
$account = $model->signup();
expect('user should be valid', $user)->isInstanceOf(Account::class);
expect('password should be correct', $user->validatePassword('some_password'))->true();
expect('uuid is set', $user->uuid)->notEmpty();
$this->expectSuccessRegistration($account);
expect('lang is set', $account->lang)->equals('ru');
}
public function testSignupWithDefaultLanguage() {
$model = new RegistrationForm([
'username' => 'some_username',
'email' => 'some_email@example.com',
'password' => 'some_password',
'rePassword' => 'some_password',
'rulesAgreement' => true,
]);
$account = $model->signup();
$this->expectSuccessRegistration($account);
expect('lang is set', $account->lang)->equals('en');
}
/**
* @param Account|null $account
*/
private function expectSuccessRegistration($account) {
expect('user should be valid', $account)->isInstanceOf(Account::class);
expect('password should be correct', $account->validatePassword('some_password'))->true();
expect('uuid is set', $account->uuid)->notEmpty();
expect('user model exists in database', Account::find()->andWhere([
'username' => 'some_username',
'email' => 'some_email@example.com',
])->exists())->true();
expect('email activation code exists in database', EmailActivation::find()->andWhere([
'account_id' => $user->id,
'account_id' => $account->id,
'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION,
])->exists())->true();
expect_file('message file exists', $this->getMessageFile())->exists();

View File

@@ -7,7 +7,7 @@ return [
'email' => 'admin@ely.by',
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi', # password_0
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
'password_reset_token' => null,
'lang' => 'en',
'status' => \common\models\Account::STATUS_ACTIVE,
'created_at' => 1451775316,
'updated_at' => 1451775316,
@@ -20,7 +20,7 @@ return [
'email' => 'erickskrauch123@yandex.ru',
'password_hash' => '133c00c463cbd3e491c28cb653ce4718', # 12345678
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_OLD_ELY,
'password_reset_token' => null,
'lang' => 'en',
'status' => \common\models\Account::STATUS_ACTIVE,
'created_at' => 1385225069,
'updated_at' => 1385225069,
@@ -33,7 +33,7 @@ return [
'email' => 'achristiansen@gmail.com',
'password_hash' => '$2y$13$2rYkap5T6jG8z/mMK8a3Ou6aZxJcmAaTha6FEuujvHEmybSHRzW5e', # password_0
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
'password_reset_token' => null,
'lang' => 'en',
'status' => \common\models\Account::STATUS_REGISTERED,
'created_at' => 1453146616,
'updated_at' => 1453146616,
@@ -46,7 +46,7 @@ return [
'email' => 'jon@ely.by',
'password_hash' => '$2y$13$2rYkap5T6jG8z/mMK8a3Ou6aZxJcmAaTha6FEuujvHEmybSHRzW5e', # password_0
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
'password_reset_token' => null,
'lang' => 'en',
'status' => \common\models\Account::STATUS_REGISTERED,
'created_at' => 1457890086,
'updated_at' => 1457890086,
@@ -58,7 +58,7 @@ return [
'email' => 'notch@mojang.com',
'password_hash' => '$2y$13$2rYkap5T6jG8z/mMK8a3Ou6aZxJcmAaTha6FEuujvHEmybSHRzW5e', # password_0
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
'password_reset_token' => null,
'lang' => 'en',
'status' => \common\models\Account::STATUS_ACTIVE,
'created_at' => 1462891432,
'updated_at' => 1462891432,
@@ -70,7 +70,7 @@ return [
'email' => '23derevo@gmail.com',
'password_hash' => '$2y$13$2rYkap5T6jG8z/mMK8a3Ou6aZxJcmAaTha6FEuujvHEmybSHRzW5e', # password_0
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
'password_reset_token' => null,
'lang' => 'en',
'status' => \common\models\Account::STATUS_ACTIVE,
'created_at' => 1462891612,
'updated_at' => 1462891612,

View File

@@ -12,7 +12,7 @@ return [
'email' => $faker->email,
'password_hash' => $security->generatePasswordHash('password_' . $index),
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
'password_reset_token' => NULL,
'lang' => 'en',
'auth_key' => $security->generateRandomString(),
'status' => \common\models\Account::STATUS_ACTIVE,
'created_at' => time(),

View File

@@ -1,11 +1,8 @@
<?php
namespace tests\codeception\common\unit;
/**
* @inheritdoc
*/
class TestCase extends \yii\codeception\TestCase
{
class TestCase extends \yii\codeception\TestCase {
public $appConfig = '@tests/codeception/config/common/unit.php';
}

View File

@@ -0,0 +1,3 @@
{
"testString": "testValue"
}

View File

@@ -0,0 +1,3 @@
{
"testString": "тестовоеЗначение"
}

View File

@@ -1,14 +0,0 @@
<?php
return [
[
'username' => 'bayer.hudson',
'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR',
//password_0
'password_hash' => '$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO',
'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317',
'created_at' => '1402312317',
'updated_at' => '1402312317',
'email' => 'nicole.paucek@schultz.info',
],
];

View File

@@ -0,0 +1,53 @@
<?php
namespace codeception\common\unit\validators;
use Codeception\Specify;
use common\validators\LanguageValidator;
use ReflectionClass;
use tests\codeception\common\unit\TestCase;
class LanguageValidatorTest extends TestCase {
use Specify;
public function testGetFilesNames() {
$this->specify('get list of 2 languages: ru and en', function() {
$model = $this->createModelWithFixturePath();
expect($this->callProtected($model, 'getFilesNames'))->equals(['en', 'ru']);
});
}
public function testValidateValue() {
$this->specify('get null, because language is supported', function() {
$model = $this->createModelWithFixturePath();
expect($this->callProtected($model, 'validateValue', 'ru'))->null();
});
$this->specify('get error message, because language is unsupported', function() {
$model = $this->createModelWithFixturePath();
expect($this->callProtected($model, 'validateValue', 'by'))->equals([
$model->message,
[],
]);
});
}
/**
* @return LanguageValidator
*/
private function createModelWithFixturePath() {
return new class extends LanguageValidator {
public function getFolderPath() {
return __DIR__ . '/../fixtures/data/i18n';
}
};
}
private function callProtected($object, string $function, ...$args) {
$class = new ReflectionClass($object);
$method = $class->getMethod($function);
$method->setAccessible(true);
return $method->invokeArgs($object, $args);
}
}