ElixirVault/tests/UnitTests/App/PubUsers/accountActivationTest.php

82 lines
2.5 KiB
PHP

<?php
namespace LoretaAudit\Tests\UnitTests\App\PubUsers;
use BRSystems\Core\Cms\cmsAccountActivation\inc\cmsAccountActivationController;
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 accountActivationTest extends BasePhpUnitCase
{
private pubUsers $users;
protected function setUp(): void
{
// Init base structure
$this->unitTestsAreRunning = true;
$this->resetGetAndPost();
parent::setUp();
// Create new class
$this->users = $this->initBaseClassObjectBySiteMapId(SiteMap::PUB_LOGIN, null);
}
protected function tearDown(): void
{
$this->reloadDbTables(['mod_users']);
parent::tearDown();
}
public function testUserAccountActivationViaLinkOnActivatedUser(): void
{
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
$this->setGet([
'act' => $this->users->controller->oDefuseCrypt->encrypt(
$loginData['id'] . cmsAccountActivationController::ACTIVATION_LINK_SEP .
$this->users->controller->oDefuseCrypt->encrypt($loginData['password'])
)
]);
try {
$this->users->loginAction();
$this->fail('Exception Expected!');
} catch (Exception $error) {
$this->assertExpected(
['Redirected to Location: /ienakt-gramatvedibas-sistema'],
$error->getMessage()
);
}
}
public function testUserAccountActivationViaLinkWhileLoggedIn(): void
{
$this->loginUnitTestUserForCoverage();
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
// Set user not activated
$this->cDb->_queryUpdate('mod_users', ['user_activated' => '0'], ['id' => $loginData['id']]);
$this->setGet([
'act' => $this->users->controller->oDefuseCrypt->encrypt(
$loginData['id'] . cmsAccountActivationController::ACTIVATION_LINK_SEP . $loginData['password']
)
]);
try {
$this->users->loginAction();
$this->fail('Exception Expected!');
} catch (Exception $error) {
$this->assertEquals(
'Redirected to Location: /ienakt-gramatvedibas-sistema/divi-faktori',
$error->getMessage()
);
}
$this->logOutUnitTestUser();
}
}