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();
|
|
|
|
$this->assertEquals([E::ACCOUNT_ALREADY_BANNED], $form->getErrors('account'));
|
|
|
|
}
|
2016-12-16 14:02:13 +05:30
|
|
|
|
|
|
|
public function testBan() {
|
|
|
|
/** @var Account|\PHPUnit_Framework_MockObject_MockObject $account */
|
|
|
|
$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());
|
2016-12-16 14:02:13 +05:30
|
|
|
$this->assertEquals(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
|
|
|
}
|
|
|
|
|
|
|
|
}
|