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( [ 'Zutenis | Uzņēmuma izvēle', 'Izvēlieties uzņēmumu / darbības veidu', 'Mareks Keišs pašn.' ], $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() ); } } }