Compare commits

...

5 Commits

Author SHA1 Message Date
denis.flaven@combodo.com
3fb5c05467 N°7001 - Being admin to generate oAuth token is too restrictive 2023-12-13 13:57:44 +01:00
Pierre Goiffon
f36f3aa05b 💡 N°6848 Fix PHPDoc 2023-10-17 11:12:38 +02:00
Pierre Goiffon
d0d90d7c69 N°6848 Fix TransactionsTest::testTransactionOpenedNotClosed failing
Was caused by 239c51bb, which adds 65bb76b9 tests improvements but only partly : we were missing in TransactionsTest::tearDown the mysqli reset from mock to original mysqli cnx

Without this reset the rollback made in ItopTestCase::tearDown is throwing an exception (query() method on the DbConnectionWrapper cnx returns false in \CMDBSource::DBQuery) on PHP 8.1 and 8.2

Co-authored-by: Romain Quetiez <romain.queriez@combodo.com>
2023-10-17 10:53:26 +02:00
odain
239c51bb53 ci enhancement: complete tearDown to cleanup transactions and cmdb changes properly 2023-10-03 10:09:26 +02:00
Pierre Goiffon
bdf0b4daa9 N°6562 Fix DOMNode->textContent write
This attribute is read only
Causes layout issues on PHP 8.1.21 and 8.2.8

(cherry picked from commit 734a788340)
(cherry picked from commit 7aa478d6ff)
2023-09-14 15:31:02 +02:00
6 changed files with 28 additions and 6 deletions

View File

@@ -59,9 +59,17 @@ class DbConnectionWrapper
* Use this to register a mock that will handle {@see mysqli::query()} * Use this to register a mock that will handle {@see mysqli::query()}
* *
* @param \mysqli|null $oMysqli * @param \mysqli|null $oMysqli
* @since 3.0.4 3.1.1 3.2.0 Param $oMysqli becomes nullable
* @since 3.1.0-4 N°6848 backport of restoring cnx on null parameter value
*/ */
public static function SetDbConnectionMockForQuery(?mysqli $oMysqli): void public static function SetDbConnectionMockForQuery(?mysqli $oMysqli = null): void
{ {
static::$oDbCnxMockableForQuery = $oMysqli; if (is_null($oMysqli)) {
// Reset to standard connection
static::$oDbCnxMockableForQuery = static::$oDbCnxStandard;
}
else {
static::$oDbCnxMockableForQuery = $oMysqli;
}
} }
} }

View File

@@ -10,6 +10,5 @@ IssueLog::Trace('----- Request: '.utils::GetRequestUri(), LogChannels::WEB_REQUE
$sTemplates = APPROOT.'templates/pages/backoffice/oauth'; $sTemplates = APPROOT.'templates/pages/backoffice/oauth';
$oUpdateController = new OAuthLandingController($sTemplates, 'core'); $oUpdateController = new OAuthLandingController($sTemplates, 'core');
$oUpdateController->AllowOnlyAdmin();
$oUpdateController->SetDefaultOperation('Landing'); $oUpdateController->SetDefaultOperation('Landing');
$oUpdateController->HandleOperation(); $oUpdateController->HandleOperation();

View File

@@ -892,7 +892,10 @@ class iTopDesignFormat
$oNodeList = $oXPath->query("/itop_design/classes//class/fields/field/values/value"); $oNodeList = $oXPath->query("/itop_design/classes//class/fields/field/values/value");
foreach ($oNodeList as $oNode) { foreach ($oNodeList as $oNode) {
$sCode = $oNode->textContent; $sCode = $oNode->textContent;
$oNode->textContent = ''; // N°6562 textContent is readonly, see https://www.php.net/manual/en/class.domnode.php#95545
// $oNode->textContent = '';
// N°6562 to update text node content we must use the node methods !
$oNode->removeChild($oNode->firstChild);
$oCodeNode = $oNode->ownerDocument->createElement("code", $sCode); $oCodeNode = $oNode->ownerDocument->createElement("code", $sCode);
$oNode->appendChild($oCodeNode); $oNode->appendChild($oCodeNode);
} }
@@ -982,7 +985,12 @@ class iTopDesignFormat
if ($oStyleNode) { if ($oStyleNode) {
$this->DeleteNode($oStyleNode); $this->DeleteNode($oStyleNode);
} }
$oNode->textContent = $sCode;
// N°6562 textContent is readonly, see https://www.php.net/manual/en/class.domnode.php#95545
// $oNode->textContent = $sCode;
// N°6562 to update text node content we must use the node methods !
$oTextContentNode = new DOMText($sCode);
$oNode->appendChild($oTextContentNode);
} }
} }
// - Style // - Style

View File

@@ -136,6 +136,8 @@ class ItopDataTestCase extends ItopTestCase
} }
} }
CMDBObject::SetCurrentChange(null);
parent::tearDown(); parent::tearDown();
} }

View File

@@ -68,6 +68,10 @@ class ItopTestCase extends TestCase
if (CMDBSource::IsInsideTransaction()) { if (CMDBSource::IsInsideTransaction()) {
// Nested transactions were opened but not finished ! // Nested transactions were opened but not finished !
// Rollback to avoid side effects on next tests
while (CMDBSource::IsInsideTransaction()) {
CMDBSource::Query('ROLLBACK');
}
throw new MySQLTransactionNotClosedException('Some DB transactions were opened but not closed ! Fix the code by adding ROLLBACK or COMMIT statements !', []); throw new MySQLTransactionNotClosedException('Some DB transactions were opened but not closed ! Fix the code by adding ROLLBACK or COMMIT statements !', []);
} }
} }
@@ -312,4 +316,4 @@ class ItopTestCase extends TestCase
} }
closedir($dir); closedir($dir);
} }
} }

View File

@@ -276,6 +276,7 @@ class TransactionsTest extends ItopTestCase
protected function tearDown(): void protected function tearDown(): void
{ {
try { try {
DbConnectionWrapper::SetDbConnectionMockForQuery(); // Else will throw error on PHP 8.1+ (see N°6848)
parent::tearDown(); parent::tearDown();
} }
catch (MySQLTransactionNotClosedException $e) { catch (MySQLTransactionNotClosedException $e) {