2016-07-25 16:37:14 +05:30
|
|
|
<?php
|
2019-12-14 02:46:05 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-25 16:37:14 +05:30
|
|
|
namespace codeception\api\unit\validators;
|
|
|
|
|
2019-08-02 05:59:20 +05:30
|
|
|
use api\rbac\Permissions as P;
|
2019-02-23 04:41:57 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-07-25 16:37:14 +05:30
|
|
|
use api\validators\PasswordRequiredValidator;
|
2018-04-18 02:17:25 +05:30
|
|
|
use common\helpers\Error as E;
|
2016-07-25 16:37:14 +05:30
|
|
|
use common\models\Account;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\_support\ProtectedCaller;
|
2017-09-30 03:14:05 +05:30
|
|
|
use yii\web\User;
|
2016-07-25 16:37:14 +05:30
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class PasswordRequiredValidatorTest extends TestCase {
|
2016-07-25 16:37:14 +05:30
|
|
|
use ProtectedCaller;
|
|
|
|
|
|
|
|
public function testValidateValue() {
|
|
|
|
$account = new Account(['password' => '12345678']);
|
2017-09-30 03:14:05 +05:30
|
|
|
$model = new PasswordRequiredValidator(['account' => $account]);
|
|
|
|
|
|
|
|
// Get error.password_required if password is empty
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame([E::PASSWORD_REQUIRED, []], $this->callProtected($model, 'validateValue', ''));
|
2017-09-30 03:14:05 +05:30
|
|
|
|
|
|
|
// Get error.password_incorrect if password is incorrect
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame([E::PASSWORD_INCORRECT, []], $this->callProtected($model, 'validateValue', '87654321'));
|
2017-09-30 03:14:05 +05:30
|
|
|
|
|
|
|
// No errors, if password is correct for provided account
|
|
|
|
$this->assertNull($this->callProtected($model, 'validateValue', '12345678'));
|
|
|
|
|
|
|
|
// Skip validation if user can skip identity verification
|
2019-12-14 02:46:05 +05:30
|
|
|
$component = $this->createPartialMock(User::class, ['can']);
|
|
|
|
$component->method('can')->with(P::ESCAPE_IDENTITY_VERIFICATION)->willReturn(true);
|
2017-09-30 03:14:05 +05:30
|
|
|
$model->user = $component;
|
|
|
|
$this->assertNull($this->callProtected($model, 'validateValue', ''));
|
2016-07-25 16:37:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|