2016-05-11 01:10:06 +05:30
|
|
|
<?php
|
|
|
|
namespace tests\codeception\api\traits;
|
|
|
|
|
2016-05-30 05:14:17 +05:30
|
|
|
use api\models\AccountIdentity;
|
2016-05-11 01:10:06 +05:30
|
|
|
use api\traits\AccountFinder;
|
|
|
|
use Codeception\Specify;
|
|
|
|
use common\models\Account;
|
2016-10-29 03:17:31 +05:30
|
|
|
use tests\codeception\api\unit\TestCase;
|
2016-05-11 01:10:06 +05:30
|
|
|
use tests\codeception\common\fixtures\AccountFixture;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class AccountFinderTest extends TestCase {
|
2016-05-11 01:10:06 +05:30
|
|
|
use Specify;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
public function _fixtures() {
|
2016-05-11 01:10:06 +05:30
|
|
|
return [
|
2016-10-29 03:17:31 +05:30
|
|
|
'accounts' => AccountFixture::class,
|
2016-05-11 01:10:06 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAccount() {
|
|
|
|
$this->specify('founded account for passed login data', function() {
|
|
|
|
$model = new AccountFinderTestTestClass();
|
2016-10-29 03:17:31 +05:30
|
|
|
/** @var Account $account */
|
|
|
|
$account = $this->tester->grabFixture('accounts', 'admin');
|
|
|
|
$model->login = $account->email;
|
2016-05-11 01:10:06 +05:30
|
|
|
$account = $model->getAccount();
|
|
|
|
expect($account)->isInstanceOf(Account::class);
|
2016-10-29 03:17:31 +05:30
|
|
|
expect($account->id)->equals($account->id);
|
2016-05-30 05:14:17 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
$this->specify('founded account for passed login data with changed account model class name', function() {
|
|
|
|
/** @var AccountFinderTestTestClass $model */
|
|
|
|
$model = new class extends AccountFinderTestTestClass {
|
|
|
|
protected function getAccountClassName() {
|
|
|
|
return AccountIdentity::class;
|
|
|
|
}
|
|
|
|
};
|
2016-10-29 03:17:31 +05:30
|
|
|
/** @var Account $account */
|
|
|
|
$account = $this->tester->grabFixture('accounts', 'admin');
|
|
|
|
$model->login = $account->email;
|
2016-05-30 05:14:17 +05:30
|
|
|
$account = $model->getAccount();
|
|
|
|
expect($account)->isInstanceOf(AccountIdentity::class);
|
2016-10-29 03:17:31 +05:30
|
|
|
expect($account->id)->equals($account->id);
|
2016-05-11 01:10:06 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|