2016-05-11 01:10:06 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\_support\traits;
|
2016-05-11 01:10:06 +05:30
|
|
|
|
2019-02-23 04:41:57 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-05-11 01:10:06 +05:30
|
|
|
use api\traits\AccountFinder;
|
|
|
|
use common\models\Account;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\fixtures\AccountFixture;
|
2016-05-11 01:10:06 +05:30
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class AccountFinderTest extends TestCase {
|
2016-05-11 01:10:06 +05:30
|
|
|
|
2019-05-14 04:28:29 +05:30
|
|
|
public function _fixtures(): array {
|
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() {
|
2017-09-19 22:36:16 +05:30
|
|
|
$model = new AccountFinderTestTestClass();
|
|
|
|
/** @var Account $account */
|
|
|
|
$accountFixture = $this->tester->grabFixture('accounts', 'admin');
|
|
|
|
$model->login = $accountFixture->email;
|
|
|
|
$account = $model->getAccount();
|
|
|
|
$this->assertInstanceOf(Account::class, $account);
|
|
|
|
$this->assertSame($accountFixture->id, $account->id, 'founded account for passed login data');
|
|
|
|
|
|
|
|
$model = new AccountFinderTestTestClass();
|
|
|
|
$model->login = 'unexpected';
|
|
|
|
$this->assertNull($account = $model->getAccount(), 'null, if account can\'t be found');
|
2016-05-11 01:10:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLoginAttribute() {
|
2017-09-19 22:36:16 +05:30
|
|
|
$model = new AccountFinderTestTestClass();
|
|
|
|
$model->login = 'erickskrauch@ely.by';
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame('email', $model->getLoginAttribute(), 'if login look like email value, then \'email\'');
|
2016-05-11 01:10:06 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
$model = new AccountFinderTestTestClass();
|
|
|
|
$model->login = 'erickskrauch';
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame('username', $model->getLoginAttribute(), 'username in any other case');
|
2016-05-11 01:10:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class AccountFinderTestTestClass {
|
|
|
|
use AccountFinder;
|
|
|
|
|
|
|
|
public $login;
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
public function getLogin(): string {
|
2016-05-11 01:10:06 +05:30
|
|
|
return $this->login;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|