mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°8210 - Remove iApplicationObjectExtension (#737)
This commit is contained in:
@@ -1,103 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
class ApplicationObjectExtensionTest extends \Combodo\iTop\Test\UnitTest\ItopDataTestCase
|
||||
{
|
||||
const CREATE_TEST_ORG = true;
|
||||
|
||||
// Count the calls by name
|
||||
private static array $aCalls = [];
|
||||
private static int $iCalls = 0;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->RequireOnceUnitTestFile('iApplicationObjectExtension/MockApplicationObjectExtensionForTest1.php');
|
||||
$this->ResetApplicationObjectExtensions();
|
||||
// Count all the calls to this object
|
||||
MockApplicationObjectExtensionForTest1::SetCallBack([ApplicationObjectExtensionTest::class, 'IncrementCallCount']);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
MockApplicationObjectExtensionForTest1::SetModifications('Person', 'name', 0);
|
||||
MockApplicationObjectExtensionForTest1::SetCallBack(null);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public static function IncrementCallCount(string $sOrigin)
|
||||
{
|
||||
self::$aCalls[$sOrigin] = (self::$aCalls[$sOrigin] ?? 0) + 1;
|
||||
self::$iCalls++;
|
||||
}
|
||||
|
||||
public static function ResetCallCount()
|
||||
{
|
||||
self::$aCalls = [];
|
||||
self::$iCalls = 0;
|
||||
}
|
||||
|
||||
public function testExtensionCalled()
|
||||
{
|
||||
// Check that extension is called
|
||||
$oPerson = $this->CreatePerson(1);
|
||||
$oPerson->Set('first_name', 'testUpdateReentranceProtection');
|
||||
MockApplicationObjectExtensionForTest1::SetModifications('Person', 'name', 1);
|
||||
self::ResetCallCount();
|
||||
$oPerson->DBUpdate();
|
||||
// Called twice, the first call will provoke the DBUpdate and call again the object extension
|
||||
$this->assertEquals(2, self::$iCalls);
|
||||
}
|
||||
|
||||
public function testUpdateReentranceProtection()
|
||||
{
|
||||
$oPerson = $this->CreatePerson(1);
|
||||
|
||||
// Check that loop limit is 10
|
||||
$i = 15;
|
||||
self::ResetCallCount();
|
||||
MockApplicationObjectExtensionForTest1::SetModifications('Person', 'name', $i);
|
||||
$oPerson->Set('first_name', 'testUpdateReentranceProtection');
|
||||
$oPerson->DBUpdate();
|
||||
$this->assertEquals(10, self::$iCalls);
|
||||
}
|
||||
|
||||
public function testModificationsOnUpdate()
|
||||
{
|
||||
$oPerson = $this->CreatePerson(1);
|
||||
$oPerson->Set('first_name', 'testUpdateReentranceProtection');
|
||||
|
||||
self::ResetCallCount();
|
||||
MockApplicationObjectExtensionForTest1::SetModifications('Person', 'name', 1);
|
||||
$oPerson->DBUpdate();
|
||||
$this->assertEquals(2, self::$iCalls);
|
||||
}
|
||||
|
||||
public function testModificationsOnInsert()
|
||||
{
|
||||
self::ResetCallCount();
|
||||
MockApplicationObjectExtensionForTest1::SetModifications('Person', 'name', 1);
|
||||
$oPerson = $this->CreatePerson(1);
|
||||
$this->assertEquals(2, self::$iCalls);
|
||||
}
|
||||
|
||||
|
||||
public function testModificationsOnInsertWith2Extensions()
|
||||
{
|
||||
self::ResetCallCount();
|
||||
$this->RequireOnceUnitTestFile('iApplicationObjectExtension/MockApplicationObjectExtensionForTest2.php');
|
||||
$this->ResetApplicationObjectExtensions();
|
||||
// Count all the calls to this object
|
||||
MockApplicationObjectExtensionForTest2::SetCallBack([ApplicationObjectExtensionTest::class, 'IncrementCallCount']);
|
||||
|
||||
MockApplicationObjectExtensionForTest1::SetModifications('Person', 'name', 2);
|
||||
MockApplicationObjectExtensionForTest2::SetModifications('Person', 'first_name', 2);
|
||||
$oPerson = $this->CreatePerson(1);
|
||||
$this->assertEquals(6, self::$iCalls);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -78,10 +78,6 @@ class ApplicationExtensionTest extends ItopCustomDatamodelTestCase
|
||||
\iApplicationUIExtension::class,
|
||||
static::ENUM_API_CALL_METHOD_ENUMPLUGINS,
|
||||
],
|
||||
\iApplicationObjectExtension::class => [
|
||||
\iApplicationObjectExtension::class,
|
||||
static::ENUM_API_CALL_METHOD_ENUMPLUGINS,
|
||||
],
|
||||
\iPopupMenuExtension::class => [
|
||||
\iPopupMenuExtension::class,
|
||||
static::ENUM_API_CALL_METHOD_ENUMPLUGINS,
|
||||
|
||||
@@ -66,16 +66,6 @@ class ExampleFor_iPreferencesExtension extends \AbstractPreferencesExtension
|
||||
<rank>0</rank>
|
||||
<content><![CDATA[
|
||||
class ExampleFor_iApplicationUIExtension extends \AbstractApplicationUIExtension
|
||||
{
|
||||
// Do nothing, we just need the class to exists for the unit test
|
||||
}
|
||||
]]></content>
|
||||
</snippet>
|
||||
<snippet id="ExampleFor_iApplicationObjectExtension" _delta="define">
|
||||
<placement>core</placement>
|
||||
<rank>0</rank>
|
||||
<content><![CDATA[
|
||||
class ExampleFor_iApplicationObjectExtension extends \AbstractApplicationObjectExtension
|
||||
{
|
||||
// Do nothing, we just need the class to exists for the unit test
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test object for AbstractApplicationObjectExtension API
|
||||
*/
|
||||
class MockApplicationObjectExtensionForTest1 extends AbstractApplicationObjectExtension
|
||||
{
|
||||
protected static $iCountModify;
|
||||
protected static $sClass;
|
||||
protected static $sAttCodeToModify;
|
||||
protected static $callBack;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function SetCallBack($callBack)
|
||||
{
|
||||
static::$callBack = $callBack;
|
||||
}
|
||||
|
||||
public static function SetModifications($sClass, $sAttCodeToModify, $iCountModify)
|
||||
{
|
||||
static::$sClass = $sClass;
|
||||
static::$sAttCodeToModify = $sAttCodeToModify;
|
||||
if (!MetaModel::IsValidClass($sClass) || !MetaModel::IsValidAttCode($sClass, $sAttCodeToModify)) {
|
||||
throw new Exception("Invalid class $sClass or attcode $sAttCodeToModify");
|
||||
}
|
||||
static::$iCountModify = $iCountModify;
|
||||
}
|
||||
|
||||
public function OnDBUpdate($oObject, $oChange = null)
|
||||
{
|
||||
if (get_class($oObject) !== static::$sClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_null(static::$callBack)) {
|
||||
call_user_func(static::$callBack, 'OnDBUpdate');
|
||||
}
|
||||
|
||||
$aPreviousValues = $oObject->ListPreviousValuesForUpdatedAttributes();
|
||||
$sPreviousValues = print_r($aPreviousValues, true);
|
||||
|
||||
IssueLog::Info(__METHOD__." received previous values:\n$sPreviousValues");
|
||||
|
||||
if (static::$iCountModify > 0) {
|
||||
static::$iCountModify--;
|
||||
$oObject->Set(static::$sAttCodeToModify, 'Value_'.rand());
|
||||
$oObject->DBUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public function OnDBInsert($oObject, $oChange = null)
|
||||
{
|
||||
if (get_class($oObject) !== static::$sClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_null(static::$callBack)) {
|
||||
call_user_func(static::$callBack, 'OnDBInsert');
|
||||
}
|
||||
|
||||
if (static::$iCountModify > 0) {
|
||||
static::$iCountModify--;
|
||||
$oObject->Set(static::$sAttCodeToModify, 'Value_'.rand());
|
||||
$oObject->DBUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test object for AbstractApplicationObjectExtension API
|
||||
*/
|
||||
class MockApplicationObjectExtensionForTest2 extends AbstractApplicationObjectExtension
|
||||
{
|
||||
protected static $iCountModify;
|
||||
protected static $sClass;
|
||||
protected static $sAttCodeToModify;
|
||||
protected static $callBack;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function SetCallBack($callBack)
|
||||
{
|
||||
static::$callBack = $callBack;
|
||||
}
|
||||
|
||||
public static function SetModifications($sClass, $sAttCodeToModify, $iCountModify)
|
||||
{
|
||||
static::$sClass = $sClass;
|
||||
static::$sAttCodeToModify = $sAttCodeToModify;
|
||||
if (!MetaModel::IsValidClass($sClass) || !MetaModel::IsValidAttCode($sClass, $sAttCodeToModify)) {
|
||||
throw new Exception("Invalid class $sClass or attcode $sAttCodeToModify");
|
||||
}
|
||||
static::$iCountModify = $iCountModify;
|
||||
}
|
||||
|
||||
public function OnDBUpdate($oObject, $oChange = null)
|
||||
{
|
||||
if (get_class($oObject) !== static::$sClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_null(static::$callBack)) {
|
||||
call_user_func(static::$callBack, 'OnDBUpdate');
|
||||
}
|
||||
|
||||
$aPreviousValues = $oObject->ListPreviousValuesForUpdatedAttributes();
|
||||
$sPreviousValues = print_r($aPreviousValues, true);
|
||||
|
||||
IssueLog::Info(__METHOD__." received previous values:\n$sPreviousValues");
|
||||
|
||||
if (static::$iCountModify > 0) {
|
||||
static::$iCountModify--;
|
||||
$oObject->Set(static::$sAttCodeToModify, 'Value_'.rand());
|
||||
$oObject->DBUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public function OnDBInsert($oObject, $oChange = null)
|
||||
{
|
||||
if (get_class($oObject) !== static::$sClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_null(static::$callBack)) {
|
||||
call_user_func(static::$callBack, 'OnDBInsert');
|
||||
}
|
||||
|
||||
if (static::$iCountModify > 0) {
|
||||
static::$iCountModify--;
|
||||
$oObject->Set(static::$sAttCodeToModify, 'Value_'.rand());
|
||||
$oObject->DBUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user