mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Реализованы формы для шагов смены E-mail адреса, покрыты unit-тестами
У EmailActivation добавлено поле $_data и дописано поведение для работы с ним Упрощено подключение фикстур для EmailActivations
This commit is contained in:
@@ -50,10 +50,7 @@ class FixtureHelper extends Module {
|
||||
'class' => AccountFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
|
||||
],
|
||||
'emailActivations' => [
|
||||
'class' => EmailActivationFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/email-activations.php',
|
||||
],
|
||||
'emailActivations' => EmailActivationFixture::class,
|
||||
'oauthClients' => [
|
||||
'class' => OauthClientFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/oauth-clients.php',
|
||||
|
@@ -75,4 +75,16 @@ return [
|
||||
'created_at' => 1462891612,
|
||||
'updated_at' => 1462891612,
|
||||
],
|
||||
'account-with-change-email-finish-state' => [
|
||||
'id' => 7,
|
||||
'uuid' => '4c34f2cc-4bd9-454b-9583-bb52f020ec16',
|
||||
'username' => 'CrafterGameplays',
|
||||
'email' => 'crafter@gmail.com',
|
||||
'password_hash' => '$2y$13$2rYkap5T6jG8z/mMK8a3Ou6aZxJcmAaTha6FEuujvHEmybSHRzW5e', # password_0
|
||||
'password_hash_strategy' => \common\models\Account::PASS_HASH_STRATEGY_YII2,
|
||||
'lang' => 'en',
|
||||
'status' => \common\models\Account::STATUS_ACTIVE,
|
||||
'created_at' => 1463349615,
|
||||
'updated_at' => 1463349615,
|
||||
],
|
||||
];
|
||||
|
@@ -24,4 +24,17 @@ return [
|
||||
'type' => \common\models\EmailActivation::TYPE_FORGOT_PASSWORD_KEY,
|
||||
'created_at' => time() - (new \common\models\confirmations\ForgotPassword())->repeatTimeout - 10,
|
||||
],
|
||||
'currentEmailConfirmation' => [
|
||||
'key' => 'H26HBDCHHAG2HGHGHS',
|
||||
'account_id' => 1,
|
||||
'type' => \common\models\EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION,
|
||||
'created_at' => time() - 10,
|
||||
],
|
||||
'newEmailConfirmation' => [
|
||||
'key' => 'H27HBDCHHAG2HGHGHS',
|
||||
'account_id' => 7,
|
||||
'type' => \common\models\EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION,
|
||||
'_data' => serialize(['newEmail' => 'my-new-email@ely.by']),
|
||||
'created_at' => time() - 10,
|
||||
],
|
||||
];
|
||||
|
79
tests/codeception/common/unit/behaviors/DataBehaviorTest.php
Normal file
79
tests/codeception/common/unit/behaviors/DataBehaviorTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace codeception\common\unit\behaviors;
|
||||
|
||||
use Codeception\Specify;
|
||||
use common\behaviors\DataBehavior;
|
||||
use tests\codeception\common\_support\ProtectedCaller;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
use yii\base\ErrorException;
|
||||
use yii\base\Model;
|
||||
|
||||
class DataBehaviorTest extends TestCase {
|
||||
use Specify;
|
||||
use ProtectedCaller;
|
||||
|
||||
public function testSetKey() {
|
||||
$this->specify('setting value should change model data field', function() {
|
||||
$model = $this->createModel();
|
||||
/** @var DataBehavior $behavior */
|
||||
$behavior = $model->behaviors['dataBehavior'];
|
||||
$this->callProtected($behavior, 'setKey', 'my-key', 'my-value');
|
||||
expect($model->_data)->equals(serialize(['my-key' => 'my-value']));
|
||||
});
|
||||
}
|
||||
|
||||
public function testGetKey() {
|
||||
$this->specify('getting value from exists data should work', function() {
|
||||
$model = $this->createModel();
|
||||
$model->_data = serialize(['some-key' => 'some-value']);
|
||||
/** @var DataBehavior $behavior */
|
||||
$behavior = $model->behaviors['dataBehavior'];
|
||||
expect($this->callProtected($behavior, 'getKey', 'some-key'))->equals('some-value');
|
||||
});
|
||||
}
|
||||
|
||||
public function testGetData() {
|
||||
$this->specify('getting value from null field should return empty array', function() {
|
||||
$model = $this->createModel();
|
||||
/** @var DataBehavior $behavior */
|
||||
$behavior = $model->behaviors['dataBehavior'];
|
||||
expect($this->callProtected($behavior, 'getData'))->equals([]);
|
||||
});
|
||||
|
||||
$this->specify('getting value from serialized data field should return encoded value', function() {
|
||||
$model = $this->createModel();
|
||||
$data = ['foo' => 'bar'];
|
||||
$model->_data = serialize($data);
|
||||
/** @var DataBehavior $behavior */
|
||||
$behavior = $model->behaviors['dataBehavior'];
|
||||
expect($this->callProtected($behavior, 'getData'))->equals($data);
|
||||
});
|
||||
|
||||
$this->specify('getting value from invalid serialization string', function() {
|
||||
$model = $this->createModel();
|
||||
$model->_data = 'this is invalid serialization of string';
|
||||
/** @var DataBehavior $behavior */
|
||||
$behavior = $model->behaviors['dataBehavior'];
|
||||
$this->expectException(ErrorException::class);
|
||||
$this->callProtected($behavior, 'getData');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Model
|
||||
*/
|
||||
private function createModel() {
|
||||
return new class extends Model {
|
||||
public $_data;
|
||||
|
||||
public function behaviors() {
|
||||
return [
|
||||
'dataBehavior' => [
|
||||
'class' => DataBehavior::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@@ -13,10 +13,7 @@ class EmailActivationTest extends DbTestCase {
|
||||
|
||||
public function fixtures() {
|
||||
return [
|
||||
'emailActivations' => [
|
||||
'class' => EmailActivationFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/email-activations.php',
|
||||
],
|
||||
'emailActivations' => EmailActivationFixture::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -3,11 +3,12 @@ namespace codeception\common\unit\validators;
|
||||
|
||||
use Codeception\Specify;
|
||||
use common\validators\LanguageValidator;
|
||||
use ReflectionClass;
|
||||
use tests\codeception\common\_support\ProtectedCaller;
|
||||
use tests\codeception\common\unit\TestCase;
|
||||
|
||||
class LanguageValidatorTest extends TestCase {
|
||||
use Specify;
|
||||
use ProtectedCaller;
|
||||
|
||||
public function testGetFilesNames() {
|
||||
$this->specify('get list of 2 languages: ru and en', function() {
|
||||
@@ -42,12 +43,4 @@ class LanguageValidatorTest extends TestCase {
|
||||
};
|
||||
}
|
||||
|
||||
private function callProtected($object, string $function, ...$args) {
|
||||
$class = new ReflectionClass($object);
|
||||
$method = $class->getMethod($function);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invokeArgs($object, $args);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user