From f65e14397cb61f32248acfaab48efb56402723a7 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 16 Jan 2023 11:15:54 +0100 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20N=C2=B04660=20Fix=20pe?= =?UTF-8?q?rmissions=20changes=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unitary-tests/core/OQLTest.php | 16 +++++++------- .../core/iTopConfigParserTest.php | 6 +++++- .../unitary-tests/webservices/RestTest.php | 21 ++++++++----------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/core/OQLTest.php b/tests/php-unit-tests/unitary-tests/core/OQLTest.php index c6f71058b..bf25ccf54 100644 --- a/tests/php-unit-tests/unitary-tests/core/OQLTest.php +++ b/tests/php-unit-tests/unitary-tests/core/OQLTest.php @@ -38,14 +38,16 @@ class OQLTest extends ItopDataTestCase */ public function testOQLSetup() { - utils::GetConfig()->Set('use_legacy_dbsearch', false, 'test'); - utils::GetConfig()->Set('apc_cache.enabled', false, 'test'); - utils::GetConfig()->Set('query_cache_enabled', false, 'test'); - utils::GetConfig()->Set('expression_cache_enabled', false, 'test'); - $sConfigFile = utils::GetConfig()->GetLoadedFile(); + $oConfig = utils::GetConfig(); + $oConfig->Set('use_legacy_dbsearch', false, 'test'); + $oConfig->Set('apc_cache.enabled', false, 'test'); + $oConfig->Set('query_cache_enabled', false, 'test'); + $oConfig->Set('expression_cache_enabled', false, 'test'); + + $sConfigFile = $oConfig->GetLoadedFile(); @chmod($sConfigFile, 0770); - utils::GetConfig()->WriteToFile(); - @chmod($sConfigFile, 0444); // Read-only + $oConfig->WriteToFile(); + @chmod($sConfigFile, 0444); } /** diff --git a/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php b/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php index 78addc558..335016c39 100644 --- a/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php +++ b/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php @@ -35,7 +35,11 @@ class iTopConfigParserTest extends ItopTestCase { parent::tearDown(); if ($this->conf_exists) { - rename($this->tmpSavePath, $this->sConfigPath); + // restoring config that was in place before the test + @chmod($this->sConfigPath, 0770); + $bRenameResult = rename($this->tmpSavePath, $this->sConfigPath); + echo "Restored config file, result={$bRenameResult}"; + @chmod($this->sConfigPath, 0440); } } diff --git a/tests/php-unit-tests/unitary-tests/webservices/RestTest.php b/tests/php-unit-tests/unitary-tests/webservices/RestTest.php index 16604009d..3d0170d0a 100644 --- a/tests/php-unit-tests/unitary-tests/webservices/RestTest.php +++ b/tests/php-unit-tests/unitary-tests/webservices/RestTest.php @@ -35,20 +35,16 @@ class RestTest extends ItopDataTestCase unlink($this->sTmpFile); } - $sConfigFile = \utils::GetConfig()->GetLoadedFile(); - @chmod($sConfigFile, 0770); - $this->sUrl = \MetaModel::GetConfig()->Get('app_root_url'); - @chmod($sConfigFile, 0444); // Read-only + $this->sUrl = \MetaModel::GetConfig()->Get('app_root_url'); - $oRestProfile = \MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'REST Services User'), true); - $oAdminProfile = \MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'Administrator'), true); + $oRestProfile = \MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'REST Services User'), true); + $oAdminProfile = \MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'Administrator'), true); - if (is_object($oRestProfile) && is_object($oAdminProfile)) - { - $oUser = $this->CreateUser($this->sLogin, $oRestProfile->GetKey(), $this->sPassword); - $this->AddProfileToUser($oUser, $oAdminProfile->GetKey()); - } - } + if (is_object($oRestProfile) && is_object($oAdminProfile)) { + $oUser = $this->CreateUser($this->sLogin, $oRestProfile->GetKey(), $this->sPassword); + $this->AddProfileToUser($oUser, $oAdminProfile->GetKey()); + } + } /** * @dataProvider BasicProvider @@ -62,6 +58,7 @@ class RestTest extends ItopDataTestCase $description = date('dmY H:i:s'); $sOuputJson = $this->CreateTicketViaApi($description); $aJson = json_decode($sOuputJson, true); + $this->assertNotNull($aJson, "Cannot decode returned JSON : $sOuputJson"); $this->assertContains("0", "".$aJson['code'], $sOuputJson); $sUserRequestKey = $this->array_key_first($aJson['objects']); $this->assertContains('UserRequest::', $sUserRequestKey);