2017-01-05 03:27:04 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\unit\modules\internal\models;
|
2017-01-05 03:27:04 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
use api\modules\accounts\models\PardonAccountForm;
|
2018-04-18 02:17:25 +05:30
|
|
|
use api\modules\internal\helpers\Error as E;
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2019-02-23 04:41:57 +05:30
|
|
|
use common\models\Account;
|
2017-01-05 03:27:04 +05:30
|
|
|
|
|
|
|
class PardonFormTest extends TestCase {
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testValidateAccountBanned(): void {
|
2017-01-05 03:27:04 +05:30
|
|
|
$account = new Account();
|
|
|
|
$account->status = Account::STATUS_BANNED;
|
2017-09-19 22:36:16 +05:30
|
|
|
$form = new PardonAccountForm($account);
|
2017-01-05 03:27:04 +05:30
|
|
|
$form->validateAccountBanned();
|
|
|
|
$this->assertEmpty($form->getErrors('account'));
|
|
|
|
|
|
|
|
$account = new Account();
|
|
|
|
$account->status = Account::STATUS_ACTIVE;
|
2017-09-19 22:36:16 +05:30
|
|
|
$form = new PardonAccountForm($account);
|
2017-01-05 03:27:04 +05:30
|
|
|
$form->validateAccountBanned();
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame([E::ACCOUNT_NOT_BANNED], $form->getErrors('account'));
|
2017-01-05 03:27:04 +05:30
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testPardon(): void {
|
2019-05-14 04:28:29 +05:30
|
|
|
/** @var Account|\PHPUnit\Framework\MockObject\MockObject $account */
|
2017-01-05 03:27:04 +05:30
|
|
|
$account = $this->getMockBuilder(Account::class)
|
2024-12-02 15:40:55 +05:30
|
|
|
->onlyMethods(['save'])
|
2017-01-05 03:27:04 +05:30
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$account->expects($this->once())
|
|
|
|
->method('save')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$account->status = Account::STATUS_BANNED;
|
2017-09-19 22:36:16 +05:30
|
|
|
$model = new PardonAccountForm($account);
|
|
|
|
$this->assertTrue($model->performAction());
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame(Account::STATUS_ACTIVE, $account->status);
|
2017-01-05 03:27:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|