mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°5341-test ormBrokenCaselogExtensionT + renaming
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
class LogBrokenOrmCaseLog implements iOrmCaseLogExtension {
|
||||
public function Rebuild($sCaseLogId, &$sLog, &$aIndex): bool {
|
||||
try {
|
||||
$oUser->CheckProfiles();
|
||||
} catch (Exception $oException) {
|
||||
\IssueLog::Error('Broken caselog', LogChannels::ORM_CASELOG, [
|
||||
'caselog_id' => $sCaseLogId,
|
||||
'exception_message' => $oException->getMessage(),
|
||||
'exception_stacktrace' => $oException->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class LogBrokenOrmCaseLogExtension implements iOrmCaseLogExtension {
|
||||
class ormBrokenCaselogExtension implements iOrmCaseLogExtension {
|
||||
const CASE_LOG_SEPARATOR_REGEX_FIND = "\n?========== \w+-\d+-\d+ \d+:\d+:\d+ : .*\s\(\d+\) ============\n\n";
|
||||
const CASE_LOG_SEPARATOR_REGEX_EXTRACT = "\n?========== (?<date>\w+-\d+-\d+ \d+:\d+:\d+) : (?<user_name>.*)\s\((?<user_id>\d+)\) ============\n\n";
|
||||
|
||||
@@ -11,10 +11,12 @@ class LogBrokenOrmCaseLogExtension implements iOrmCaseLogExtension {
|
||||
}
|
||||
} catch (Exception $oException) {
|
||||
\IssueLog::Error('Broken caselog', LogChannels::ORM_CASELOG, [
|
||||
'exception_message' => $oException->getMessage(),
|
||||
'sLog' => $sLog,
|
||||
'$aIndex' => $aIndex,
|
||||
'exception_stacktrace' => $oException->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2970,6 +2970,7 @@ return array(
|
||||
'lnkAuditCategoryToAuditDomain' => $baseDir . '/application/audit.domain.class.inc.php',
|
||||
'lnkTriggerAction' => $baseDir . '/core/trigger.class.inc.php',
|
||||
'ormCaseLog' => $baseDir . '/core/ormcaselog.class.inc.php',
|
||||
'ormBrokenCaselogExtension' => $baseDir . '/core/ormBrokenCaselogExtension.inc.php',
|
||||
'ormCaseLogService' => $baseDir . '/core/ormcaselogservice.inc.php',
|
||||
'ormCustomFieldsValue' => $baseDir . '/core/ormcustomfieldsvalue.class.inc.php',
|
||||
'ormDocument' => $baseDir . '/core/ormdocument.class.inc.php',
|
||||
|
||||
@@ -3334,6 +3334,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
'iWorkingTimeComputer' => __DIR__ . '/../..' . '/core/computing.inc.php',
|
||||
'lnkAuditCategoryToAuditDomain' => __DIR__ . '/../..' . '/application/audit.domain.class.inc.php',
|
||||
'lnkTriggerAction' => __DIR__ . '/../..' . '/core/trigger.class.inc.php',
|
||||
'ormBrokenCaselogExtension' => __DIR__ . '/../..' . '/core/ormBrokenCaselogExtension.inc.php',
|
||||
'ormCaseLog' => __DIR__ . '/../..' . '/core/ormcaselog.class.inc.php',
|
||||
'ormCaseLogService' => __DIR__ . '/../..' . '/core/ormcaselogservice.inc.php',
|
||||
'ormCustomFieldsValue' => __DIR__ . '/../..' . '/core/ormcustomfieldsvalue.class.inc.php',
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2023 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use ormCaseLog;
|
||||
|
||||
/**
|
||||
* Tests of the ormCaseLog class
|
||||
*
|
||||
* @covers \ormCaseLog
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormBrokenCaselogExtensionTest extends ItopDataTestCase
|
||||
{
|
||||
const USE_TRANSACTION = false;
|
||||
private $sLogin;
|
||||
private $sPassword = "Iuytrez9876543ç_è-(";
|
||||
|
||||
public function setUp() :void{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
require_once __DIR__ . "/OrmCaseLogExtensionForTest.php";
|
||||
require_once APPROOT . "core/ormcaselogservice.inc.php";
|
||||
|
||||
$oAdminProfile = \MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'Administrator'), true);
|
||||
|
||||
if (is_object($oAdminProfile)) {
|
||||
$this->sLogin = sprintf("admin-%s-%s", date('dmYHis'), uniqid());
|
||||
|
||||
$this->CreateTestOrganization();
|
||||
|
||||
/** @var \Person $oPerson */
|
||||
$oPerson = $this->createObject('Person', array(
|
||||
'name' => $this->sLogin,
|
||||
'first_name' => 'Test',
|
||||
'org_id' => $this->getTestOrgId(),
|
||||
));
|
||||
|
||||
$this->CreateUser($this->sLogin, $oAdminProfile->GetKey(), $this->sPassword, $oPerson->GetKey());
|
||||
}
|
||||
}
|
||||
|
||||
public function LogBrokenCaseLogProvider(){
|
||||
return [
|
||||
'extension configured / should log broken caselog info' => [ true ],
|
||||
'extension NOT configured/ should do nothing' => [ false ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider LogBrokenCaseLogProvider
|
||||
*/
|
||||
public function testLogBrokenCaseLog_constructor($bExtensionConfigured){
|
||||
if ($bExtensionConfigured){
|
||||
\MetaModel::GetConfig()->Set('ormcaselog_extension_classes', [ \ormBrokenCaselogExtension::class]);
|
||||
}
|
||||
|
||||
$sLog = "aaaaa";
|
||||
$aInitialIndex = ['a' => 'b'];
|
||||
|
||||
$sLogPath = APPROOT . 'log/error.log';
|
||||
$iLogIndexBefore = strrpos(file_get_contents($sLogPath), 'Broken caselog | ORCMCASELOG');
|
||||
$oLog = new ormCaseLog($sLog, $aInitialIndex);
|
||||
$iLogIndexAfter = strrpos(file_get_contents($sLogPath), 'Broken caselog | ORCMCASELOG');
|
||||
|
||||
if ($bExtensionConfigured){
|
||||
$this->assertNotEquals($iLogIndexBefore, $iLogIndexAfter, 'Log line found and it must be in aother position in the log file');
|
||||
} else {
|
||||
$this->assertEquals($iLogIndexBefore, $iLogIndexAfter, 'No log line found OR it is found at same position (logged before)');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,21 +237,6 @@ class ormCaseLogTest extends ItopDataTestCase
|
||||
$aInitialIndex = ['a' => 'b'];
|
||||
$aRebuiltIndex = ['c' => 'd'];
|
||||
|
||||
/*$aOrmCaseLogExtensionForTest = $this->createMock(\iOrmCaseLogExtension::class);
|
||||
$aOrmCaseLogExtensionForTest->expects($this->exactly(1))
|
||||
->method('Rebuild')
|
||||
->with(
|
||||
$this->callback(
|
||||
function ($sLogParam, &$aIndexParam) use ($aInitialIndex, $sLog, $aRebuiltIndex, $sRebuiltLog, $bTouched) {
|
||||
$sLogParam = $sRebuiltLog;
|
||||
$aIndexParam = $aRebuiltIndex;
|
||||
return ($sLog === $sLogParam)
|
||||
&& ($aInitialIndex === $sLogParam);
|
||||
}
|
||||
)
|
||||
)
|
||||
->willReturn($bTouched);*/
|
||||
|
||||
$aOrmCaseLogExtensionForTest = new OrmCaseLogExtensionForTest();
|
||||
$aOrmCaseLogExtensionForTest->Init($bTouched, $sRebuiltLog, $aRebuiltIndex);
|
||||
$aOrmCaseLogExtension=[$aOrmCaseLogExtensionForTest];
|
||||
|
||||
Reference in New Issue
Block a user