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 {
|
|
|
|
|
|
|
|
public function testValidateAccountBanned() {
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
public function testPardon() {
|
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)
|
|
|
|
->setMethods(['save'])
|
|
|
|
->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
|
|
|
}
|
|
|
|
|
|
|
|
}
|