Образован фильтр ActiveUserRule для проверки активности пользовательского аккаунта

This commit is contained in:
ErickSkrauch
2016-08-07 03:08:48 +03:00
parent 1565370bf3
commit 426fa7dc6e
4 changed files with 95 additions and 10 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace tests\codeception\api\unit\filters;
use api\filters\ActiveUserRule;
use api\models\AccountIdentity;
use Codeception\Specify;
use common\models\Account;
use tests\codeception\api\unit\TestCase;
use tests\codeception\common\_support\ProtectedCaller;
use const common\LATEST_RULES_VERSION;
use yii\base\Action;
class ActiveUserRuleTest extends TestCase {
use Specify;
use ProtectedCaller;
public function testMatchCustom() {
$account = new AccountIdentity();
$this->specify('get false if user not finished registration', function() use (&$account) {
$account->status = 0;
$filter = $this->getFilterMock($account);
expect($this->callProtected($filter, 'matchCustom', new Action(null, null)))->false();
});
$this->specify('get false if user have old EULA agreement', function() use (&$account) {
$account->status = Account::STATUS_ACTIVE;
$account->rules_agreement_version = null;
$filter = $this->getFilterMock($account);
expect($this->callProtected($filter, 'matchCustom', new Action(null, null)))->false();
});
$this->specify('get true if user fully active', function() use (&$account) {
$account->status = Account::STATUS_ACTIVE;
$account->rules_agreement_version = LATEST_RULES_VERSION;
$filter = $this->getFilterMock($account);
expect($this->callProtected($filter, 'matchCustom', new Action(null, null)))->true();
});
}
/**
* @param AccountIdentity $returnIdentity
* @return ActiveUserRule|\PHPUnit_Framework_MockObject_MockObject
*/
private function getFilterMock(AccountIdentity $returnIdentity) {
/** @var ActiveUserRule|\PHPUnit_Framework_MockObject_MockObject $filter */
$filter = $this
->getMockBuilder(ActiveUserRule::class)
->setMethods(['getIdentity'])
->getMock();
$filter
->expects($this->any())
->method('getIdentity')
->will($this->returnValue($returnIdentity));
return $filter;
}
}