2016-12-16 14:02:13 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\unit\modules\internal\models;
|
2016-12-16 14:02:13 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
use api\modules\accounts\models\BanAccountForm;
|
2018-04-18 02:17:25 +05:30
|
|
|
use api\modules\internal\helpers\Error as E;
|
2019-02-23 04:41:57 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-12-16 14:02:13 +05:30
|
|
|
use common\models\Account;
|
2018-07-08 20:50:19 +05:30
|
|
|
use common\tasks\ClearAccountSessions;
|
2016-12-16 14:02:13 +05:30
|
|
|
|
2016-12-18 04:50:53 +05:30
|
|
|
class BanFormTest extends TestCase {
|
|
|
|
|
|
|
|
public function testValidateAccountActivity() {
|
|
|
|
$account = new Account();
|
|
|
|
$account->status = Account::STATUS_ACTIVE;
|
2017-09-19 22:36:16 +05:30
|
|
|
$form = new BanAccountForm($account);
|
2016-12-18 04:50:53 +05:30
|
|
|
$form->validateAccountActivity();
|
|
|
|
$this->assertEmpty($form->getErrors('account'));
|
|
|
|
|
|
|
|
$account = new Account();
|
|
|
|
$account->status = Account::STATUS_BANNED;
|
2017-09-19 22:36:16 +05:30
|
|
|
$form = new BanAccountForm($account);
|
2016-12-18 04:50:53 +05:30
|
|
|
$form->validateAccountActivity();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame([E::ACCOUNT_ALREADY_BANNED], $form->getErrors('account'));
|
2016-12-18 04:50:53 +05:30
|
|
|
}
|
2016-12-16 14:02:13 +05:30
|
|
|
|
|
|
|
public function testBan() {
|
2019-05-14 04:28:29 +05:30
|
|
|
/** @var Account|\PHPUnit\Framework\MockObject\MockObject $account */
|
2016-12-16 14:02:13 +05:30
|
|
|
$account = $this->getMockBuilder(Account::class)
|
|
|
|
->setMethods(['save'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$account->expects($this->once())
|
|
|
|
->method('save')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
$model = new BanAccountForm($account);
|
|
|
|
$this->assertTrue($model->performAction());
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame(Account::STATUS_BANNED, $account->status);
|
2018-07-08 20:50:19 +05:30
|
|
|
/** @var ClearAccountSessions $job */
|
|
|
|
$job = $this->tester->grabLastQueuedJob();
|
|
|
|
$this->assertInstanceOf(ClearAccountSessions::class, $job);
|
|
|
|
$this->assertSame($job->accountId, $account->id);
|
2016-12-16 14:02:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|