127 lines
3.7 KiB
PHP
127 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace LoretaAudit\Tests\UnitTests\App\PubUsers;;
|
|
|
|
use Exception;
|
|
use BRSystems\Core\App\pubUsers\pubUsers;
|
|
use LoretaAudit\Tests\BasePhpUnitCase;
|
|
use LoretaAudit\Tests\DataSetup\Constants\SiteMap;
|
|
|
|
class companySelectionActionRequestTest 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_SEL_COMPANY);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$this->logOutUnitTestUser();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testCompanySelectionDefaultActionLoginRequirement(): void
|
|
{
|
|
$this->testModuleLoginRequirement(SiteMap::PUB_SEL_COMPANY);
|
|
}
|
|
|
|
public function testCompanySelectionDefaultAction(): void
|
|
{
|
|
// Default form generation
|
|
ob_start();
|
|
$this->users->companySelectionAction();
|
|
$pageHTML = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
$this->assertExpected(
|
|
[
|
|
'<title>Zutenis | Uzņēmuma izvēle</title>',
|
|
'Izvēlieties uzņēmumu / darbības veidu',
|
|
'<i>Mareks Keišs pašn.</i>'
|
|
],
|
|
$pageHTML
|
|
);
|
|
}
|
|
|
|
public function testCompanySelectionSetActiveCompanyAction(): void
|
|
{
|
|
// Error case - Default with none existing action
|
|
$this->setGet(['action' => 'setCp', 'id' => 't3Aj']);
|
|
$this->users->controller->suser->URLS2COMPANY = ['t3Aj' => 1];
|
|
|
|
try {
|
|
$this->users->companySelectionAction();
|
|
$this->fail('Exception Expected!');
|
|
} catch (Exception $error) {
|
|
$this->assertExpected(
|
|
['Redirected to Location:'],
|
|
$error->getMessage()
|
|
);
|
|
}
|
|
|
|
// Default with none existing action
|
|
$this->setGet(['action' => 'setCp', 'id' => 't3Aj']);
|
|
$this->users->controller->suser->URLS2COMPANY = ['t3Aj' => 23];
|
|
|
|
try {
|
|
$this->users->companySelectionAction();
|
|
$this->fail('Exception Expected!');
|
|
} catch (Exception $error) {
|
|
$this->assertExpected(
|
|
['Redirected to Location: /gramatvedibas-sistema/sistemas-informacijas-panelis'],
|
|
$error->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
public function testCompanySelectionUpdateFavoriteAction(): void
|
|
{
|
|
// Default with none existing action
|
|
$this->setPost(['action' => 'updateFavorite', 'id' => 't3Aj', 'status' => 1]);
|
|
|
|
// Error case - Default with none existing action
|
|
try {
|
|
$this->users->companySelectionAction();
|
|
$this->fail('Exception Expected!');
|
|
} catch (Exception $error) {
|
|
$this->assertExpected(
|
|
['{"error":true}'],
|
|
$error->getMessage()
|
|
);
|
|
}
|
|
|
|
// Correct case
|
|
$this->users->controller->suser->URLS2COMPANY = ['t3Aj' => 23];
|
|
|
|
try {
|
|
$this->users->companySelectionAction();
|
|
$this->fail('Exception Expected!');
|
|
} catch (Exception $error) {
|
|
$this->assertExpected(
|
|
['{"jsonok":true}'],
|
|
$error->getMessage()
|
|
);
|
|
}
|
|
|
|
$this->setPost(['action' => 'updateFavorite', 'id' => 't3Aj', 'status' => 0]);
|
|
|
|
try {
|
|
$this->users->companySelectionAction();
|
|
$this->fail('Exception Expected!');
|
|
} catch (Exception $error) {
|
|
$this->assertExpected(
|
|
['{"jsonok":true}'],
|
|
$error->getMessage()
|
|
);
|
|
}
|
|
}
|
|
}
|