',
],
$response['html']
);
}
}
public function testBaseCaseActionSelfSave(): void
{
$newUserCfg = $this->newUserCfg;
$newUserCfg['fields'] = base64_encode($newUserCfg['fields']);
$this->setPost($newUserCfg);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['"jsonok":true'], $error->getMessage());
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['newid']));
$this->assertIsInt($response['newid']);
}
// Check error user already exists with this email
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(
['{"error":true,"data":{"u_email":"User login already exists!"}}'],
$error->getMessage()
);
}
// Self save existing user
$newUserCfg['id'] = $response['newid'];
$this->setPost($newUserCfg);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['"jsonok":true'], $error->getMessage());
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertFalse(isset($response['newid']));
}
}
public function testBaseCaseActionChangeRecordsStatus(): void
{
$newId = $this->addExtraRecordInTableAndResetPost();
$this->setPost(
[
'action' => 'changeRecordsStatus',
'baseField' => 'h_status',
'fields' => '{"1":"' . $newId . '"}'
]
);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"jsonok":true,"data":true}'], $error->getMessage());
}
// Error case
// Try to disable self - user admin
$this->setPost(
[
'action' => 'changeRecordsStatus',
'baseField' => 'h_status',
'fields' => '{"1":"12"}'
]
);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"error":true,"data":"Something went wrong while updating user(s)!"}'], $error->getMessage());
}
// Prevent self Disable
$this->setPost(
[
'action' => 'changeRecordsStatus',
'baseField' => 'h_status',
'fields' => '{"1":"' . $newId . '","2":"12"}'
]
);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"jsonok":true,"data":true}'], $error->getMessage());
}
}
public function testBaseCaseActionDeleteRecords(): void
{
$newId = $this->addExtraRecordInTableAndResetPost();
$this->setPost(
[
'action' => 'deleteRecords',
'fields' => '{"1":"' . $newId . '"}'
]
);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"jsonok":true,"data":true}'], $error->getMessage());
}
// Error case
// Try to delete self - user admin
$this->setPost(
[
'action' => 'deleteRecords',
'fields' => '{"1":"12"}'
]
);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"error":true,"msg":"Something went wrong while deleting user(s)!"}'], $error->getMessage());
}
// Prevent self delete 2
$this->reloadDbTables(['mod_users']);
$newId = $this->addExtraRecordInTableAndResetPost();
$this->setPost(
[
'action' => 'deleteRecords',
'fields' => '{"1":"' . $newId . '","2":"12"}'
]
);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"jsonok":true,"data":true}'], $error->getMessage());
}
}
public function testBaseCaseActionISendRecoveryMail(): void
{
$this->setPost(['action' => 'iSendRecoveryMail']);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"jsonok":true,"data":false}'], $error->getMessage());
}
}
public function testBaseCaseActionTablesCfg(): void
{
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
$this->setPost(['action' => 'tablescfg', 'id' => $loginData['id']]);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['html']));
$this->assertExpected(
['
'],
$response['html']
);
}
}
public function testBaseCaseActionPropSave(): void
{
$this->setPost(
[
'action' => 'propsave',
'prop' => '{"c0":["partner-status","earnings-status"],"b1":["chart-income-base","chart-expanses-categories"' .
',"chart-3","chart-4"],"b2":["subscription-status","system-new-update-log","quick-view-calendar","recent-activity-log"]}'
]
);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['{"jsonok":true,"data":true}'], $error->getMessage());
}
}
public function testBaseCaseActionCompanies(): void
{
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
$this->setPost(['action' => 'companies', 'id' => $loginData['id']]);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['html']));
$this->assertExpected(
[
'',
'',
'',
'',
'',
'',
],
$response['html']
);
}
}
public function testBaseCaseActionActivate2FA(): void
{
$oGoogle2FA = new cGoogle2FA();
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
$this->setPost([
'action' => 'activate-2FA',
'secret' => $secret = $oGoogle2FA->getNewGoogleAuthSecret(),
'code' => $oGoogle2FA->getGoogleAuthCode($secret)
]);
try {
$this->pubUserManager->controller->selUserId = $loginData['id'];
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['url']));
$this->assertEquals('/gramatvedibas-sistema/sistemas-informacijas-panelis', $response['url']);
}
// Error case
$this->setPost([
'action' => 'activate-2FA',
'secret' => 'KDSALKDSDNNV',
'code' => 123123
]);
try {
$this->pubUserManager->controller->selUserId = $loginData['id'];
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertEquals(
'{"error":true,"data":{"code":"Ievad\u012bts k\u013c\u016bdains 2FA iestat\u012b\u0161anas dro\u0161\u012bbas kods!"}}',
$error->getMessage()
);
}
}
public function testBaseCaseActionDeactivate2FA(): void
{
$oGoogle2FA = new cGoogle2FA();
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
$this->setPost([
'action' => 'deactivate-2FA',
'code' => $oGoogle2FA->getGoogleAuthCode($loginData['2fa'])
]);
try {
$this->pubUserManager->controller->selUserId = $loginData['id'];
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
}
// Error case
$this->setPost([
'action' => 'deactivate-2FA',
'secret' => 'KDSALKDSDNNV',
'code' => 123123
]);
try {
$this->pubUserManager->controller->selUserId = $loginData['id'];
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertEquals(
'{"error":true,"data":{"code":"Login 2FA Security removal code input error!"}}',
$error->getMessage()
);
}
}
public function testBaseCaseActionGet2FAQRCode(): void
{
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
$this->setPost(['action' => 'get2FA-QRCode']);
try {
$this->pubUserManager->controller->selUserId = $loginData['id'];
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['html']));
$this->assertTrue(isset($response['msgEnableAuth']));
$this->assertTrue(isset($response['buttonYes']));
$this->assertTrue(isset($response['buttonCancel']));
$this->assertTrue(isset($response['buttonActivate']));
$this->assertExpected(
[
'Pierakstiet savu slepeno atslēgu un glabājiet to droši.
',
'Tā būs nepieciešama, lai atgūtu 2FA, nozaudēšanas gadījumā.
',
'',
],
$response['html']
);
}
// With reload
$this->setPost([
'action' => 'get2FA-QRCode',
'reload' => true
]);
try {
$this->pubUserManager->controller->selUserId = $loginData['id'];
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['sUrl']));
$this->assertTrue(isset($response['sSecret']));
$this->assertTrue(strlen($response['sSecret']) > 0);
}
}
public function testBaseCaseActionGet2FA4Deactivate(): void
{
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
$this->setPost(['action' => 'get2FA-4Deactivate']);
try {
$this->pubUserManager->controller->selUserId = $loginData['id'];
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['html']));
$this->assertTrue(isset($response['msgDisableAuth']));
$this->assertTrue(isset($response['buttonDeactivate']));
$this->assertExpected(
[
'Ievadiet kodu, lai deaktivizētu 2FA
',
'Ja atslēgsiet 2FA autentifikāciju, daži moduļi var nebūt pieejami!
',
],
$response['html']
);
}
}
public function testBaseCaseActionGenRandomPwd(): void
{
$this->setPost(['action' => 'genRandomPwd']);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['"jsonok":true,"key":"'], $error->getMessage());
}
}
public function testBaseCaseActionGetTableSettings(): void
{
$this->setPost(['action' => 'getTableSettings', 'mod' => 'pubUserManager']);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertTrue(isset($response['jsonok']));
$this->assertTrue(isset($response['vCfg']));
$this->assertTrue(isset($response['mod_title']));
$this->assertTrue(isset($response['save_data']));
$this->assertTrue(isset($response['body']));
$this->assertExpected(
[
'',
'Pielāgojiet tabulas kolonnas
',
'Tablulas rindas
',
'Atiestatīt izkārtojumu
',
],
$response['body']
);
}
}
public function testBaseCaseActionSaveTableSettings(): void
{
$this->setPost([
'action' => 'saveTableSettings',
'mod' => 'pubUserManager',
'tbl' => '{"pubUserManager":["h_created_by","h_user_name","h_id","h_user_login","h_user_email","h_user_phone' .
'","h_user_last_ip","h_user_last_login","h_user_modified","h_user_created","h_status"],"base_only":true}',
'data' => '{"a_rec_per_page":"25"}'
]);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(
['{"jsonok":true,"data":true}'],
$error->getMessage()
);
}
}
public function testBaseCaseActionResetTableSettings(): void
{
$this->setPost([
'action' => 'resetTableSettings',
'mod' => 'pubUserManager'
]);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(
['{"jsonok":true,"data":true}'],
$error->getMessage()
);
}
}
private function addExtraRecordInTableAndResetPost(): int
{
// Create user for load
$newUserCfg = $this->newUserCfg;
$newUserCfg['fields'] = str_replace(
'"u_login":"test@test.lv"',
'"u_login":"extra.record@test.lv"',
$newUserCfg['fields']
);
$newUserCfg['fields'] = base64_encode($newUserCfg['fields']);
$this->setPost($newUserCfg);
try {
$this->pubUserManager->run();
$this->fail("Exception expected!");
} catch (Exception $error) {
$this->assertExpected(['"jsonok":true'], $error->getMessage());
// get JSON response
$response = json_decode($error->getMessage(), true);
$this->assertIsInt($response['newid']);
}
$this->resetGetAndPost();
return $response['newid'];
}
public function testGetUploadConfig(): void
{
$this->pubUserManager = new pubUserManager(getFirstMatchByMapId(SiteMap::PUB_USER_MANAGER));
$data = $this->pubUserManager->controller->getUploadConfig();
$this->assertIsArray($data);
}
public function testGetFileUploadConfig(): void
{
$this->pubUserManager = new pubUserManager(getFirstMatchByMapId(SiteMap::PUB_USER_MANAGER));
$data = $this->pubUserManager->controller->getFileUploadConfig();
$this->assertIsArray($data);
}
}