mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Образован trait AccountFinder для поиска пользователя по его нику\мылу
Модель EmailActivation теперь умеет автоматически создавать своих правильных потомков по соответствующему типу Добавлена форма восстановления пароля и её обработчик (без контроллера)
This commit is contained in:
67
tests/codeception/api/unit/traits/AccountFinderTest.php
Normal file
67
tests/codeception/api/unit/traits/AccountFinderTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace tests\codeception\api\traits;
|
||||
|
||||
use api\traits\AccountFinder;
|
||||
use Codeception\Specify;
|
||||
use common\models\Account;
|
||||
use tests\codeception\api\unit\DbTestCase;
|
||||
use tests\codeception\common\fixtures\AccountFixture;
|
||||
|
||||
/**
|
||||
* @property \tests\codeception\api\UnitTester $actor
|
||||
* @property array $accounts
|
||||
*/
|
||||
class AccountFinderTest extends DbTestCase {
|
||||
use Specify;
|
||||
|
||||
public function fixtures() {
|
||||
return [
|
||||
'accounts' => [
|
||||
'class' => AccountFixture::class,
|
||||
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetAccount() {
|
||||
$this->specify('founded account for passed login data', function() {
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = $this->accounts['admin']['email'];
|
||||
$account = $model->getAccount();
|
||||
expect($account)->isInstanceOf(Account::class);
|
||||
expect($account->id)->equals($this->accounts['admin']['id']);
|
||||
});
|
||||
|
||||
$this->specify('null, if account not founded', function() {
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = 'unexpected';
|
||||
expect($account = $model->getAccount())->null();
|
||||
});
|
||||
}
|
||||
|
||||
public function testGetLoginAttribute() {
|
||||
$this->specify('if login look like email value, then \'email\'', function() {
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = 'erickskrauch@ely.by';
|
||||
expect($model->getLoginAttribute())->equals('email');
|
||||
});
|
||||
|
||||
$this->specify('username in any other case', function() {
|
||||
$model = new AccountFinderTestTestClass();
|
||||
$model->login = 'erickskrauch';
|
||||
expect($model->getLoginAttribute())->equals('username');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AccountFinderTestTestClass {
|
||||
use AccountFinder;
|
||||
|
||||
public $login;
|
||||
|
||||
public function getLogin() {
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user