102 lines
3.3 KiB
PHP
102 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace LoretaAudit\Tests\UnitTests\App\PubUsers;
|
|
|
|
use BRSystems\Core\App\pubSysDashboard\pubSysDashboard;
|
|
use Exception;
|
|
use BRSystems\Core\App\pubUsers\pubUsers;
|
|
use LoretaAudit\Tests\BasePhpUnitCase;
|
|
use LoretaAudit\Tests\DataSetup\Constants\SiteMap;
|
|
use LoretaAudit\Tests\DataSetup\Constants\siteUsers;
|
|
|
|
class userAdditionalCompanyRegistrationTest extends BasePhpUnitCase
|
|
{
|
|
private ?pubSysDashboard $pubSysDashboard;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
// Init base structure
|
|
$this->unitTestsAreRunning = true;
|
|
$this->resetGetAndPost();
|
|
parent::setUp();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$this->reloadDbTables(['mod_users']);
|
|
$this->logOutUnitTestUser();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testUserAdditionalCompanyRegistrationDataRequest(): void
|
|
{
|
|
// Create new class
|
|
$this->pubSysDashboard = $this->initBaseClassObjectBySiteMapId(SiteMap::SYSTEM_DASHBOARD);
|
|
|
|
// Get partners settings
|
|
$data = $this->pubSysDashboard->controller->oUser->sendActiveUserDataForAdditionalCompanyRegistration(
|
|
$this->pubSysDashboard->controller
|
|
);
|
|
|
|
unset($data['uid']);
|
|
$this->assertEquals(
|
|
[
|
|
'login' => 'testmareks',
|
|
'name' => 'Mareks',
|
|
'surname' => 'Keišs',
|
|
'email' => 'keiss.mareks@gmail.com',
|
|
'phone' => '28639957'
|
|
],
|
|
$data
|
|
);
|
|
}
|
|
|
|
public function testUserAdditionalCompanyRegistrationDataRequestErrors(): void
|
|
{
|
|
// Delete user 2FA access
|
|
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
|
|
$this->cDb->_queryUpdate('mod_users', ['user_2fa_secret_enabled' => ''], ['id' => $loginData['id']]);
|
|
|
|
// Create new class / empty class - since it's dying on 2FA entrapment
|
|
$this->pubSysDashboard = $this->initBaseClassObjectBySiteMapId(
|
|
SiteMap::SYSTEM_DASHBOARD,
|
|
siteUsers::loginAppSelfEmployed,
|
|
false
|
|
);
|
|
|
|
// Create user class
|
|
$pubUser = new pubUsers(getFirstMatchByMapId(SiteMap::PUB_LOGIN));
|
|
|
|
// Get partners settings
|
|
$data = $pubUser->controller->sendActiveUserDataForAdditionalRegistration(
|
|
$this->pubSysDashboard->controller
|
|
);
|
|
|
|
$this->assertEquals(
|
|
[
|
|
'error' => 1,
|
|
'msg' => 'Lai turpinātu, lietotāja kontam ir jāaktivizē 2FA. <br/>Lūdzu ienāciet sistēmā ar lietotāju un aktivizējiet 2FA.',
|
|
],
|
|
$data
|
|
);
|
|
|
|
// Get partners settings
|
|
$pubUser->controller->is_post = true;
|
|
try {
|
|
$data = $pubUser->controller->sendActiveUserDataForAdditionalRegistration(
|
|
$this->pubSysDashboard->controller
|
|
);
|
|
$this->fail('Exception Expected!');
|
|
} catch (Exception $error) {
|
|
$this->assertExpected(
|
|
[
|
|
'"error":true',
|
|
'Lai turpin\u0101tu, lietot\u0101ja kontam ir j\u0101aktiviz\u0113 2FA.',
|
|
'L\u016bdzu ien\u0101ciet sist\u0113m\u0101 ar lietot\u0101ju un aktiviz\u0113jiet 2FA.',
|
|
],
|
|
$error->getMessage()
|
|
);
|
|
}
|
|
}
|
|
}
|