2016-12-16 14:02:13 +05:30
|
|
|
<?php
|
2020-06-12 02:57:02 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
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;
|
2020-06-12 02:57:02 +05:30
|
|
|
use ReflectionObject;
|
2016-12-16 14:02:13 +05:30
|
|
|
|
2020-06-12 02:57:02 +05:30
|
|
|
class BanAccountFormTest extends TestCase {
|
2016-12-18 04:50:53 +05:30
|
|
|
|
|
|
|
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 */
|
2020-06-12 02:57:02 +05:30
|
|
|
$account = $this->createPartialMock(Account::class, ['save']);
|
|
|
|
$account->expects($this->once())->method('save')->willReturn(true);
|
|
|
|
$account->id = 123;
|
2016-12-16 14:02:13 +05:30
|
|
|
|
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);
|
2020-06-12 02:57:02 +05:30
|
|
|
$obj = new ReflectionObject($job);
|
|
|
|
$property = $obj->getProperty('accountId');
|
|
|
|
$property->setAccessible(true);
|
|
|
|
$this->assertSame(123, $property->getValue($job));
|
2016-12-16 14:02:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|