2016-05-11 01:10:06 +05:30
|
|
|
<?php
|
|
|
|
namespace tests\codeception\api\traits;
|
|
|
|
|
|
|
|
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() {
|
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';
|
|
|
|
$this->assertEquals('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';
|
|
|
|
$this->assertEquals('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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|